Merge pull request #3 from MuRuLOSE/update-submodules_33fe70e29663b7258d7ec30ef6daddf2c6f4b02c

Update of repositories 2025-07-22 20:40:16
This commit is contained in:
Zahar Vanilovv
2025-07-22 23:42:18 +03:00
committed by GitHub
5 changed files with 39619 additions and 39442 deletions

View File

@@ -0,0 +1,147 @@
# ______ ___ ___ _ _
# ____ | ___ \ | \/ | | | | |
# / __ \| |_/ / _| . . | ___ __| |_ _| | ___
# / / _` | __/ | | | |\/| |/ _ \ / _` | | | | |/ _ \
# | | (_| | | | |_| | | | | (_) | (_| | |_| | | __/
# \ \__,_\_| \__, \_| |_/\___/ \__,_|\__,_|_|\___|
# \____/ __/ |
# |___/
# На модуль распространяется лицензия "GNU General Public License v3.0"
# https://github.com/all-licenses/GNU-General-Public-License-v3.0
# meta developer: @pymodule
# requires: opencv-python
import os, shutil, cv2
from PIL import Image, UnidentifiedImageError
from telethon.tl.functions.stickers import CreateStickerSetRequest
from telethon.tl.types import InputStickerSetItem, InputDocument
from telethon.errors.rpcerrorlist import PackShortNameOccupiedError
from .. import loader
from telethon.tl.functions.photos import GetUserPhotosRequest
import asyncio
import random
import string
try:
resample = Image.Resampling.LANCZOS
except:
resample = Image.LANCZOS
@loader.tds
class CreateAvatarsPack(loader.Module):
"""Creates a sticker pack from photos and video avatars of participants"""
strings = {
"name": "CreateAvatarsPack",
"processing": "📥 I'm collecting avatars of participants...",
"no_avatars": "❌ No members with avatars",
"no_valid": "❌ Could not process any avatars",
"done": "✅ The sticker pack is ready:\n👉 <a href='https://t.me/addstickers/{}'>Open</a>",
"already": "⚠️ A sticker pack with this name already exists.",
}
strings_ru = {
"processing": "📥 Собираю аватарки участников...",
"no_avatars": "❌ Нет участников с аватарками",
"no_valid": "Не удалось обработать ни одну аватарку",
"done": "✅ Стикерпак готов:\n👉 <a href='https://t.me/addstickers/{}'>Открыть</a>",
"already": "⚠️ Стикерпак с таким именем уже существует",
}
@loader.command(doc="- Create a sticker pack from the avatars of users in the group", ru_doc="- Создать стикерпак из аватаров пользователей группы", only_groups=True)
async def createavatars(self, message):
"""- Create a sticker pack from the avatars of users in the group"""
chat = await message.get_chat()
cid = abs(message.chat_id)
await message.edit(self.strings["processing"])
users = []
async for u in self._client.iter_participants(chat.id):
if u.photo:
users.append(u)
if len(users) >= 100:
break
if not users:
return await message.edit(self.strings["no_avatars"])
tmp_dir = f"/tmp/avatars_{cid}"
os.makedirs(tmp_dir, exist_ok=True)
sticker_files = []
for u in users:
try:
photos = await self._client(GetUserPhotosRequest(u.id, 0, 0, 1))
if not photos.photos:
continue
raw = await self._client.download_media(photos.photos[0])
data = raw if isinstance(raw, (bytes, bytearray)) else open(raw, "rb").read()
path_raw = os.path.join(tmp_dir, f"{u.id}_raw")
with open(path_raw, "wb") as f:
f.write(data)
if b"ftyp" in data[:32] or path_raw.endswith((".mp4", ".webm", ".mov")):
cap = cv2.VideoCapture(path_raw)
success, frame = cap.read()
cap.release()
if not success:
continue
img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA))
else:
try:
img = Image.open(path_raw).convert("RGBA")
except UnidentifiedImageError:
continue
img.thumbnail((512, 512), resample)
w, h = img.size
final = Image.new("RGBA", (512, 512), (0, 0, 0, 0))
final.paste(img, ((512 - w)//2, (512 - h)//2))
out = os.path.join(tmp_dir, f"{u.id}.webp")
final.save(out, "WEBP")
sticker_files.append(out)
except:
continue
if not sticker_files:
shutil.rmtree(tmp_dir, ignore_errors=True)
return await message.edit(self.strings["no_valid"])
tag = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
short = f"f{cid}_{tag}_by_fcreateavatars"
title = f"AvaPack {tag}"
stickers = []
for p in sticker_files:
await asyncio.sleep(0.3)
file = await self._client.upload_file(p)
msg = await self._client.send_file("me", file, force_document=True)
doc = msg.document
await self._client.delete_messages("me", msg.id)
stickers.append(InputStickerSetItem(
document=InputDocument(doc.id, doc.access_hash, doc.file_reference),
emoji="🖼️"
))
try:
await self._client(CreateStickerSetRequest(
user_id="me",
title=title,
short_name=short,
stickers=stickers
))
except PackShortNameOccupiedError:
shutil.rmtree(tmp_dir, ignore_errors=True)
return await message.edit(self.strings["already"])
except Exception as e:
shutil.rmtree(tmp_dir, ignore_errors=True)
return await message.edit(f"❌ Error: {e}")
shutil.rmtree(tmp_dir, ignore_errors=True)
await message.edit(self.strings["done"].format(short))

View File

@@ -15,4 +15,5 @@ calc
githubinfo
qrgen
wiki
checkhost
checkhost
createavatarspack

View File

@@ -1,3 +1,3 @@
<script>
window.location.href = "https://module.newurp.online";
window.location.href = "https://pymodule.t.me";
</script>

78891
modules.json

File diff suppressed because one or more lines are too long

View File

@@ -334,7 +334,7 @@ class YaMusicMod(loader.Module):
else:
now['entity_type'] = "RADIO"
device_eid, volume, device = "6039404727542747508", "Unknown Device", ""
device_eid, device, volume = "6039404727542747508", "Unknown Device", ""
if now['device']:
device=now['device']['info']['title']
volume=round(now['device']['volume']*100, 2)
@@ -357,8 +357,9 @@ class YaMusicMod(loader.Module):
audio = io.BytesIO((await utils.run_sync(requests.get, now['track']['download_link'])).content)
audio.name = "audio.mp3"
await utils.answer_file(
message=message, file=audio, caption=out,
await utils.answer(
message=message, response=out,
file=audio,
attributes=([
telethon.types.DocumentAttributeAudio(
duration=now['track']['duration'],
@@ -397,7 +398,7 @@ class YaMusicMod(loader.Module):
else:
now['entity_type'] = "RADIO"
device_eid, volume, device = "6039404727542747508", "Unknown Device", ""
device_eid, device, volume = "6039404727542747508", "Unknown Device", ""
if now['device']:
device=now['device']['info']['title']
volume=round(now['device']['volume']*100, 2)
@@ -422,8 +423,8 @@ class YaMusicMod(loader.Module):
now['duration_ms'], now['progress_ms'],
requests.get(now['track']['img']).content
)
await utils.answer_file(
message=message, file=file, caption=out
await utils.answer(
message=message, response=out, file=file
)
@@ -561,8 +562,9 @@ class YaMusicMod(loader.Module):
audio = io.BytesIO((await utils.run_sync(requests.get, link)).content)
audio.name = "audio.mp3"
await utils.answer_file(
message=message, file=audio, caption=out,
await utils.answer(
message=message, response=out,
file=audio,
attributes=([
telethon.types.DocumentAttributeAudio(
duration=int(search.tracks.results[0].duration_ms / 1000),