mirror of
https://github.com/MuRuLOSE/limoka.git
synced 2026-06-16 22:34:19 +02:00
Added and updated repositories 2026-05-03 02:10:53
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ import random
|
|||||||
import string
|
import string
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from PIL import Image, UnidentifiedImageError
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
|
||||||
from telethon.tl.functions.stickers import CreateStickerSetRequest
|
from telethon.tl.functions.stickers import CreateStickerSetRequest
|
||||||
@@ -38,11 +39,12 @@ except AttributeError:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
STATIC_STICKER_LIMIT = 120
|
||||||
|
EMOJI_LIMIT = 200
|
||||||
|
|
||||||
async def process_to_webp(input_path: str, output_path: str, size: int = 512) -> bool:
|
async def process_to_webp(input_path: str, output_path: str, size: int = 512) -> bool:
|
||||||
try:
|
try:
|
||||||
is_video = input_path.lower().endswith(('.mp4', '.webm', '.mov')) or b'ftyp' in open(input_path, 'rb').read(32)
|
is_video = input_path.lower().endswith((".mp4", ".webm", ".mov")) or b"ftyp" in open(input_path, "rb").read(32)
|
||||||
if is_video:
|
if is_video:
|
||||||
cap = cv2.VideoCapture(input_path)
|
cap = cv2.VideoCapture(input_path)
|
||||||
success, frame = cap.read()
|
success, frame = cap.read()
|
||||||
@@ -87,7 +89,7 @@ async def process_to_webp(input_path: str, output_path: str, size: int = 512) ->
|
|||||||
|
|
||||||
async def process_to_png(input_path: str, output_path: str, size: int = 100) -> bool:
|
async def process_to_png(input_path: str, output_path: str, size: int = 100) -> bool:
|
||||||
try:
|
try:
|
||||||
is_video = input_path.lower().endswith(('.mp4', '.webm', '.mov')) or b'ftyp' in open(input_path, 'rb').read(32)
|
is_video = input_path.lower().endswith((".mp4", ".webm", ".mov")) or b"ftyp" in open(input_path, "rb").read(32)
|
||||||
if is_video:
|
if is_video:
|
||||||
cap = cv2.VideoCapture(input_path)
|
cap = cv2.VideoCapture(input_path)
|
||||||
success, frame = cap.read()
|
success, frame = cap.read()
|
||||||
@@ -137,8 +139,10 @@ class CreatePacks(loader.Module):
|
|||||||
"processing": "<b>[CreatePacks]</b> Collecting avatars of participants...",
|
"processing": "<b>[CreatePacks]</b> Collecting avatars of participants...",
|
||||||
"no_avatars": "<b>[CreatePacks]</b> No members with avatars",
|
"no_avatars": "<b>[CreatePacks]</b> No members with avatars",
|
||||||
"no_valid": "<b>[CreatePacks]</b> Could not process any avatars",
|
"no_valid": "<b>[CreatePacks]</b> Could not process any avatars",
|
||||||
"done_pack": "<b>[CreatePacks]</b> Sticker pack is ready:\n<b>[CreatePacks]</b> Open: <a href='https://t.me/addstickers/{}'>here</a>",
|
"done_pack": "<b>[CreatePacks]</b> Sticker pack is ready:\n<b>[CreatePacks]</b> Open: <a href=\'https://t.me/addstickers/{}\\'>here</a>",
|
||||||
"done_emoji_pack": "<b>[CreatePacks]</b> Emoji pack is ready:\n<b>[CreatePacks]</b> Open: <a href='https://t.me/addstickers/{}'>here</a>",
|
"done_packs": "<b>[CreatePacks]</b> Sticker packs are ready:\n{}",
|
||||||
|
"done_emoji_pack": "<b>[CreatePacks]</b> Emoji pack is ready:\n<b>[CreatePacks]</b> Open: <a href=\'https://t.me/addstickers/{}\\''>here</a>",
|
||||||
|
"done_emoji_packs": "<b>[CreatePacks]</b> Emoji packs are ready:\n{}",
|
||||||
"already": "<b>[CreatePacks]</b> A sticker pack with this name already exists.",
|
"already": "<b>[CreatePacks]</b> A sticker pack with this name already exists.",
|
||||||
"emoji_processing": "<b>[CreatePacks]</b> Creating emoji pack from avatars...",
|
"emoji_processing": "<b>[CreatePacks]</b> Creating emoji pack from avatars...",
|
||||||
"emoji_no_emoji": "<b>[CreatePacks]</b> No emoji specified — using",
|
"emoji_no_emoji": "<b>[CreatePacks]</b> No emoji specified — using",
|
||||||
@@ -149,8 +153,10 @@ class CreatePacks(loader.Module):
|
|||||||
"processing": "<b>[CreatePacks]</b> Собираю аватарки участников...",
|
"processing": "<b>[CreatePacks]</b> Собираю аватарки участников...",
|
||||||
"no_avatars": "<b>[CreatePacks]</b> Нет участников с аватарками",
|
"no_avatars": "<b>[CreatePacks]</b> Нет участников с аватарками",
|
||||||
"no_valid": "<b>[CreatePacks]</b> Не удалось обработать ни одну аватарку",
|
"no_valid": "<b>[CreatePacks]</b> Не удалось обработать ни одну аватарку",
|
||||||
"done_pack": "<b>[CreatePacks]</b> Стикерпак готов:\n<b>[CreatePacks]</b> Открыть: <a href='https://t.me/addstickers/{}'>здесь</a>",
|
"done_pack": "<b>[CreatePacks]</b> Стикерпак готов:\n<b>[CreatePacks]</b> Открыть: <a href=\'https://t.me/addstickers/{}\\''>здесь</a>",
|
||||||
"done_emoji_pack": "<b>[CreatePacks]</b> Эмодзи-пак готов:\n<b>[CreatePacks]</b> Открыть: <a href='https://t.me/addstickers/{}'>здесь</a>",
|
"done_packs": "<b>[CreatePacks]</b> Стикерпаки готовы:\n{}",
|
||||||
|
"done_emoji_pack": "<b>[CreatePacks]</b> Эмодзи-пак готов:\n<b>[CreatePacks]</b> Открыть: <a href=\'https://t.me/addstickers/{}\\''>здесь</a>",
|
||||||
|
"done_emoji_packs": "<b>[CreatePacks]</b> Эмодзи-паки готовы:\n{}",
|
||||||
"already": "<b>[CreatePacks]</b> Стикерпак с таким именем уже существует",
|
"already": "<b>[CreatePacks]</b> Стикерпак с таким именем уже существует",
|
||||||
"emoji_processing": "<b>[CreatePacks]</b> Создаю эмодзи-пак из аватаров...",
|
"emoji_processing": "<b>[CreatePacks]</b> Создаю эмодзи-пак из аватаров...",
|
||||||
"emoji_no_emoji": "<b>[CreatePacks]</b> Эмодзи не указан — используется",
|
"emoji_no_emoji": "<b>[CreatePacks]</b> Эмодзи не указан — используется",
|
||||||
@@ -169,10 +175,6 @@ class CreatePacks(loader.Module):
|
|||||||
if len(users) >= 100:
|
if len(users) >= 100:
|
||||||
break
|
break
|
||||||
|
|
||||||
if not users:
|
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
||||||
return [], tmp_dir
|
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
process_func = process_to_webp if format == "webp" else process_to_png
|
process_func = process_to_webp if format == "webp" else process_to_png
|
||||||
|
|
||||||
@@ -224,6 +226,43 @@ class CreatePacks(loader.Module):
|
|||||||
|
|
||||||
return processed, tmp_dir
|
return processed, tmp_dir
|
||||||
|
|
||||||
|
async def _create_sticker_pack(self, message, stickers_to_add, is_emoji_pack: bool, pack_number: int = 1, emoji: str = "🖼️"):
|
||||||
|
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10))
|
||||||
|
short_name = f"pack_{random_str}_by_fcreate"
|
||||||
|
|
||||||
|
chat = await message.get_chat()
|
||||||
|
chat_title = getattr(chat, 'title', 'Chat')
|
||||||
|
|
||||||
|
title_prefix = "Ava" if not is_emoji_pack else "Emoji"
|
||||||
|
full_title = f"{chat_title} {title_prefix} #{pack_number}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self._client(CreateStickerSetRequest(
|
||||||
|
user_id="me",
|
||||||
|
title=full_title,
|
||||||
|
short_name=short_name,
|
||||||
|
stickers=stickers_to_add,
|
||||||
|
emojis=is_emoji_pack
|
||||||
|
))
|
||||||
|
return short_name, full_title
|
||||||
|
except PackShortNameOccupiedError:
|
||||||
|
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=12))
|
||||||
|
short_name = f"pack_{random_str}_by_fcreate"
|
||||||
|
try:
|
||||||
|
await self._client(CreateStickerSetRequest(
|
||||||
|
user_id="me",
|
||||||
|
title=full_title,
|
||||||
|
short_name=short_name,
|
||||||
|
stickers=stickers_to_add,
|
||||||
|
emojis=is_emoji_pack
|
||||||
|
))
|
||||||
|
return short_name, full_title
|
||||||
|
except:
|
||||||
|
return "already_exists", None
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating pack: {e}")
|
||||||
|
return None, None
|
||||||
|
|
||||||
@loader.command(
|
@loader.command(
|
||||||
ru_doc="- Создать стикерпак из аватаров в группе",
|
ru_doc="- Создать стикерпак из аватаров в группе",
|
||||||
only_groups=True
|
only_groups=True
|
||||||
@@ -236,11 +275,7 @@ class CreatePacks(loader.Module):
|
|||||||
if not files:
|
if not files:
|
||||||
return await message.edit(self.strings("no_avatars"))
|
return await message.edit(self.strings("no_avatars"))
|
||||||
|
|
||||||
tag = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
|
all_stickers = []
|
||||||
short_name = f"f{abs(message.chat_id)}_{tag}_by_fcreateavatars"
|
|
||||||
title = f"AvaPack {tag}"
|
|
||||||
|
|
||||||
stickers = []
|
|
||||||
for path in files:
|
for path in files:
|
||||||
try:
|
try:
|
||||||
await asyncio.sleep(0.3)
|
await asyncio.sleep(0.3)
|
||||||
@@ -248,42 +283,42 @@ class CreatePacks(loader.Module):
|
|||||||
msg = await self._client.send_file("me", file, force_document=True)
|
msg = await self._client.send_file("me", file, force_document=True)
|
||||||
doc = msg.document
|
doc = msg.document
|
||||||
await self._client.delete_messages("me", msg.id)
|
await self._client.delete_messages("me", msg.id)
|
||||||
stickers.append(InputStickerSetItem(
|
all_stickers.append(InputStickerSetItem(
|
||||||
document=InputDocument(doc.id, doc.access_hash, doc.file_reference),
|
document=InputDocument(doc.id, doc.access_hash, doc.file_reference),
|
||||||
emoji="🖼️"
|
emoji="🖼️"
|
||||||
))
|
))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Sticker loading error {path}: {e}")
|
logger.error(f"Sticker loading error {path}: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not stickers:
|
if not all_stickers:
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
return await message.edit(self.strings("no_valid"))
|
return await message.edit(self.strings("no_valid"))
|
||||||
|
|
||||||
try:
|
created_packs_links = []
|
||||||
await self._client(CreateStickerSetRequest(
|
pack_number = 1
|
||||||
user_id="me",
|
for i in range(0, len(all_stickers), STATIC_STICKER_LIMIT):
|
||||||
title=title,
|
current_pack_stickers = all_stickers[i : i + STATIC_STICKER_LIMIT]
|
||||||
short_name=short_name,
|
short_name, full_title = await self._create_sticker_pack(message, current_pack_stickers, False, pack_number)
|
||||||
stickers=stickers
|
if short_name == "already_exists":
|
||||||
))
|
await message.edit(self.strings("already"))
|
||||||
await message.edit(self.strings("done_pack").format(short_name))
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
except PackShortNameOccupiedError:
|
return
|
||||||
await message.edit(self.strings("already"))
|
elif short_name:
|
||||||
except Exception as e:
|
created_packs_links.append(f"<a href=\'https://t.me/addstickers/{short_name}\\''>{full_title}</a>")
|
||||||
error_details = f"❌ Ошибка создания стикерпака:\n<code>{type(e).__name__}: {e}</code>\n"
|
pack_number += 1
|
||||||
error_details += f"Пак: {short_name}\nСтикеров: {len(stickers)}\n"
|
|
||||||
if files:
|
if created_packs_links:
|
||||||
error_details += f"Последний файл: {files[-1]}\n"
|
if len(created_packs_links) == 1:
|
||||||
try:
|
# Extract short name for the single link format
|
||||||
error_details += f"Размер: {Image.open(files[-1]).size}\n"
|
sn = created_packs_links[0].split('/')[-1].split("'")[0]
|
||||||
error_details += f"Вес: {os.path.getsize(files[-1])} байт"
|
await message.edit(self.strings("done_pack").format(sn))
|
||||||
except:
|
else:
|
||||||
pass
|
await message.edit(self.strings("done_packs").format("\n".join(created_packs_links)))
|
||||||
await message.edit(error_details)
|
else:
|
||||||
logger.exception("Error creating sticker pack")
|
await message.edit(self.strings("no_valid"))
|
||||||
finally:
|
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
|
|
||||||
@loader.command(
|
@loader.command(
|
||||||
ru_doc="[эмодзи] - Создать эмодзи-пак из всех аватаров",
|
ru_doc="[эмодзи] - Создать эмодзи-пак из всех аватаров",
|
||||||
@@ -303,11 +338,7 @@ class CreatePacks(loader.Module):
|
|||||||
if not files:
|
if not files:
|
||||||
return await message.edit(self.strings("no_avatars"))
|
return await message.edit(self.strings("no_avatars"))
|
||||||
|
|
||||||
tag = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
|
all_emojis = []
|
||||||
short_name = f"f{abs(message.chat_id)}_{tag}_by_fcreateemojis"
|
|
||||||
title = f"EmojiPack {tag}"
|
|
||||||
|
|
||||||
stickers = []
|
|
||||||
for path in files:
|
for path in files:
|
||||||
try:
|
try:
|
||||||
await asyncio.sleep(0.3)
|
await asyncio.sleep(0.3)
|
||||||
@@ -315,7 +346,7 @@ class CreatePacks(loader.Module):
|
|||||||
msg = await self._client.send_file("me", file, force_document=True)
|
msg = await self._client.send_file("me", file, force_document=True)
|
||||||
doc = msg.document
|
doc = msg.document
|
||||||
await self._client.delete_messages("me", msg.id)
|
await self._client.delete_messages("me", msg.id)
|
||||||
stickers.append(InputStickerSetItem(
|
all_emojis.append(InputStickerSetItem(
|
||||||
document=InputDocument(doc.id, doc.access_hash, doc.file_reference),
|
document=InputDocument(doc.id, doc.access_hash, doc.file_reference),
|
||||||
emoji=emoji
|
emoji=emoji
|
||||||
))
|
))
|
||||||
@@ -323,32 +354,30 @@ class CreatePacks(loader.Module):
|
|||||||
logger.error(f"Error loading emoji {path}: {e}")
|
logger.error(f"Error loading emoji {path}: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not stickers:
|
if not all_emojis:
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
return await message.edit(self.strings("no_valid"))
|
return await message.edit(self.strings("no_valid"))
|
||||||
|
|
||||||
try:
|
created_packs_links = []
|
||||||
await self._client(CreateStickerSetRequest(
|
pack_number = 1
|
||||||
user_id="me",
|
for i in range(0, len(all_emojis), EMOJI_LIMIT):
|
||||||
title=title,
|
current_pack_emojis = all_emojis[i : i + EMOJI_LIMIT]
|
||||||
short_name=short_name,
|
short_name, full_title = await self._create_sticker_pack(message, current_pack_emojis, True, pack_number, emoji)
|
||||||
stickers=stickers,
|
if short_name == "already_exists":
|
||||||
emojis=True
|
await message.edit(self.strings("already"))
|
||||||
))
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
await message.edit(self.strings("done_emoji_pack").format(short_name))
|
return
|
||||||
except PackShortNameOccupiedError:
|
elif short_name:
|
||||||
await message.edit(self.strings("already"))
|
created_packs_links.append(f"<a href=\'https://t.me/addstickers/{short_name}\\''>{full_title}</a>")
|
||||||
except Exception as e:
|
pack_number += 1
|
||||||
error_details = f"❌ Ошибка создания эмодзи-пака:\n<code>{type(e).__name__}: {e}</code>\n"
|
|
||||||
error_details += f"Пак: {short_name}\nСмайликов: {len(stickers)}\n"
|
if created_packs_links:
|
||||||
if files:
|
if len(created_packs_links) == 1:
|
||||||
error_details += f"Последний файл: {files[-1]}\n"
|
sn = created_packs_links[0].split('/')[-1].split("'")[0]
|
||||||
try:
|
await message.edit(self.strings("done_emoji_pack").format(sn))
|
||||||
error_details += f"Размер: {Image.open(files[-1]).size}\n"
|
else:
|
||||||
error_details += f"Вес: {os.path.getsize(files[-1])} байт"
|
await message.edit(self.strings("done_emoji_packs").format("\n".join(created_packs_links)))
|
||||||
except:
|
else:
|
||||||
pass
|
await message.edit(self.strings("no_valid"))
|
||||||
await message.edit(error_details)
|
|
||||||
logger.exception("Error creating emoji pack")
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
||||||
finally:
|
|
||||||
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
||||||
|
|||||||
@@ -57,6 +57,12 @@
|
|||||||
"gifts":[
|
"gifts":[
|
||||||
{"id": 5969796561943660080, "emoji": "🧸", "name": "Пасхальный мишка", "price": 50}
|
{"id": 5969796561943660080, "emoji": "🧸", "name": "Пасхальный мишка", "price": 50}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"may_1th": {
|
||||||
|
"name": "🛠 1 Мая",
|
||||||
|
"gifts":[
|
||||||
|
{"id": 6026193266406327981, "emoji": "🧸", "name": "1 Мая мишка", "price": 50}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user