Skip to content

Commit

Permalink
Refactor stickertools.py for better code organization and readability
Browse files Browse the repository at this point in the history
  • Loading branch information
xAmarnath committed May 5, 2024
1 parent 38ba4f9 commit 13c3138
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion modules/stickertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

from ._config import bot
from ._handler import new_cmd
from telethon.tl.functions.messages import GetCustomEmojiDocumentsRequest
from telethon.tl.functions.messages import GetStickerSetRequest
from telethon.tl.functions.stickers import CreateStickerSetRequest, AddStickerToSetRequest
from telethon import types as t


async def run_cmd(cmd):
Expand Down Expand Up @@ -78,7 +82,8 @@ async def _animate(msg):
return await mg.edit(str(err))
similarize_image(f)
await run_cmd(
FFMPEG_COMMAND.format(f, color_f, f, color_f, "{}-anim.mp4".format(msg.id))
FFMPEG_COMMAND.format(f, color_f, f, color_f,
"{}-anim.mp4".format(msg.id))
)
await msg.respond(file="{}-anim.mp4".format(msg.id))
await mg.delete()
Expand Down Expand Up @@ -153,3 +158,51 @@ async def get_shortname(title: str):
@new_cmd(pattern="kang")
async def _kang(message):
await message.reply("Kang is not implemented yet.")


@new_cmd(pattern="kangemoji")
async def q_s(e):
try:
emoji_pack = e.text.split(None, 1)[1]
except IndexError:
return await e.reply("Give me the emoji pack name")
if "t.me" in emoji_pack:
emoji_pack = emoji_pack.split("/")[-1]
shortname = emoji_pack + "e_to_m_by_missvaleri_bot"
s = await bot(GetStickerSetRequest(t.InputStickerSetShortName(emoji_pack), 0))
_i = 0
msg = await e.reply("Kanging emojis...")
for i in s.packs:
doc = await bot(GetCustomEmojiDocumentsRequest(i.documents))
_i += 1
_j = 0
for j in doc:
doc_inp = t.InputDocument(
id=j.id, access_hash=j.access_hash, file_reference=j.file_reference)
if _i == 1 and _j == 0:
s = await bot(CreateStickerSetRequest(
user_id=e.sender,
title=e.sender.first_name+" CustomWebm",
short_name=shortname,
stickers=[
t.InputStickerSetItem(
document=doc_inp,
emoji="🤍",
)
],
))
_j += 1
continue

s = await bot(AddStickerToSetRequest(
stickerset=t.InputStickerSetShortName(
shortname),
sticker=t.InputStickerSetItem(
document=doc_inp,
emoji="🤍",
)
))

await msg.edit(f"Stickers added to [{shortname}](https://t.me/addstickers/{shortname})")


0 comments on commit 13c3138

Please sign in to comment.