Advertisement
disk6969

pyro stickers

Oct 9th, 2023 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.52 KB | None | 0 0
  1. async def get_sticker_set_by_name(
  2.     client: Client, name: str
  3. ) -> raw.base.messages.StickerSet:
  4.     try:
  5.         return await client.invoke(
  6.             raw.functions.messages.GetStickerSet(
  7.                 stickerset=raw.types.InputStickerSetShortName(short_name=name),
  8.                 hash=0,
  9.             )
  10.         )
  11.     except errors.exceptions.not_acceptable_406.StickersetInvalid:
  12.         return None
  13.  
  14.  
  15. async def create_sticker_set(
  16.     client: Client,
  17.     owner: int,
  18.     title: str,
  19.     short_name: str,
  20.     stickers: List[raw.base.InputStickerSetItem],
  21.     animated:bool=False,
  22.     video:bool=False
  23. ) -> raw.base.messages.StickerSet:
  24.     return await client.invoke(
  25.         raw.functions.stickers.CreateStickerSet(
  26.             user_id=await client.resolve_peer(owner),
  27.             title=title,
  28.             short_name=short_name,
  29.             stickers=stickers,
  30.             animated=animated,
  31.             videos=video
  32.         )
  33.     )
  34.  
  35.  
  36. async def add_sticker_to_set(
  37.     client: Client,
  38.     stickerset: raw.base.messages.StickerSet,
  39.     sticker: raw.base.InputStickerSetItem,
  40. ) -> raw.base.messages.StickerSet:
  41.     return await client.invoke(
  42.         raw.functions.stickers.AddStickerToSet(
  43.             stickerset=raw.types.InputStickerSetShortName(
  44.                 short_name=stickerset.set.short_name
  45.             ),
  46.             sticker=sticker,
  47.         )
  48.     )
  49.  
  50.  
  51. async def create_sticker(
  52.     sticker: raw.base.InputDocument, emoji: str
  53. ) -> raw.base.InputStickerSetItem:
  54.     return raw.types.InputStickerSetItem(document=sticker, emoji=emoji)
  55.  
  56.  
  57. async def upload_document(
  58.     client: Client, file_path: str, chat_id: int
  59. ) -> raw.base.InputDocument:
  60.     media = await client.invoke(
  61.         raw.functions.messages.UploadMedia(
  62.             peer=await client.resolve_peer(chat_id),
  63.             media=raw.types.InputMediaUploadedDocument(
  64.                 mime_type=client.guess_mime_type(file_path) or "application/zip",
  65.                 file=await client.save_file(file_path),
  66.                 attributes=[
  67.                     raw.types.DocumentAttributeFilename(
  68.                         file_name=os.path.basename(file_path)
  69.                     )
  70.                 ],
  71.             ),
  72.         )
  73.     )
  74.     return raw.types.InputDocument(
  75.         id=media.document.id,
  76.         access_hash=media.document.access_hash,
  77.         file_reference=media.document.file_reference,
  78.     )
  79.  
  80. async def get_document_from_file_id(
  81.     file_id: str,
  82. ) -> raw.base.InputDocument:
  83.     decoded = FileId.decode(file_id)
  84.     return raw.types.InputDocument(
  85.         id=decoded.media_id,
  86.         access_hash=decoded.access_hash,
  87.         file_reference=decoded.file_reference,
  88.     )
  89.  
  90. # ==========================================
  91.  
  92. @Gojo.on_message(command(["kang", "steal"]))
  93. async def kang(c:Gojo, m: Message):
  94.     if not m.reply_to_message:
  95.         return await m.reply_text("Reply to a sticker or image to kang it.")
  96.     elif not (m.reply_to_message.sticker or m.reply_to_message.photo or (m.reply_to_message.document and m.reply_to_message.document.mime_type.split("/")[0]=="image")):
  97.         return await m.reply_text("Reply to a sticker or image to kang it.")
  98.     if not m.from_user:
  99.         return await m.reply_text("You are anon admin, kang stickers in my pm.")
  100.     msg = await m.reply_text("Kanging Sticker..")
  101.     # Find the proper emoji
  102.     args = m.text.split()
  103.     if len(args) > 1:
  104.         sticker_emoji = str(args[1])
  105.     else:
  106.         edit_ = await msg.edit_text("No emoji provided choosing a random emoji")
  107.         ran = ["๐Ÿคฃ", "๐Ÿ˜‘", "๐Ÿ˜", "๐Ÿ‘", "๐Ÿ”ฅ", "๐Ÿ™ˆ", "๐Ÿ™", "๐Ÿ˜", "๐Ÿ˜˜", "๐Ÿ˜ฑ", "โ˜บ๏ธ", "๐Ÿ™ƒ", "๐Ÿ˜Œ", "๐Ÿคง", "๐Ÿ˜", "๐Ÿ˜ฌ", "๐Ÿคฉ", "๐Ÿ˜€", "๐Ÿ™‚", "๐Ÿฅน", "๐Ÿฅบ", "๐Ÿซฅ", "๐Ÿ™„", "๐Ÿซก", "๐Ÿซ ", "๐Ÿคซ", "๐Ÿ˜“", "๐Ÿฅต", "๐Ÿฅถ", "๐Ÿ˜ค", "๐Ÿ˜ก", "๐Ÿคฌ", "๐Ÿคฏ", "๐Ÿฅด", "๐Ÿคข", "๐Ÿคฎ", "๐Ÿ’€", "๐Ÿ—ฟ", "๐Ÿ’ฉ", "๐Ÿคก", "๐Ÿซถ", "๐Ÿ™Œ", "๐Ÿ‘", "โœŠ", "๐Ÿ‘Ž", "๐Ÿซฐ", "๐ŸคŒ", "๐Ÿ‘Œ", "๐Ÿ‘€", "๐Ÿ’ƒ", "๐Ÿ•บ", "๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘ฉ", "๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘จ","๐Ÿ‘จโ€โค๏ธโ€๐Ÿ‘จ", "๐Ÿ’‘", "๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘ฉ", "๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘จ", "๐Ÿ’", "๐Ÿ‘จโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘จ", "๐Ÿ˜ช", "๐Ÿ˜ด", "๐Ÿ˜ญ", "๐Ÿฅธ", "๐Ÿค“", "๐Ÿซค", "๐Ÿ˜ฎ", "๐Ÿ˜ง", "๐Ÿ˜ฒ", "๐Ÿฅฑ", "๐Ÿ˜ˆ", "๐Ÿ‘ฟ", "๐Ÿค–", "๐Ÿ‘พ", "๐Ÿ™Œ", "๐Ÿฅด", "๐Ÿฅฐ", "๐Ÿ˜‡", "๐Ÿคฃ" ,"๐Ÿ˜‚", "๐Ÿ˜œ", "๐Ÿ˜Ž"]
  108.         sticker_emoji = choice(ran)
  109.         await edit_.edit_text(f"Makeing a sticker with {sticker_emoji} emoji")
  110.     # Get the corresponding fileid, resize the file if necessary
  111.     try:
  112.         if m.reply_to_message.photo or (m.reply_to_message.document and m.reply_to_message.document.mime_type.split("/")[0]=="image"):
  113.             sizee = (await get_file_size(m.reply_to_message)).split()
  114.             if (sizee[1] == "mb" and sizee > 10) or sizee[1] == "gb":
  115.                 await m.reply_text("File size is too big")
  116.                 return
  117.             path = await m.reply_to_message.download()
  118.             try:
  119.                 path = await resize_file_to_sticker_size(path)
  120.             except OSError as e:
  121.                 await m.reply_text(f"Error\n{e}")
  122.                 LOGGER.error(e)
  123.                 LOGGER.error(format_exc)
  124.                 os.remove(path)
  125.                 return
  126.     except Exception as e:
  127.         await m.reply_text(f"Got an error:\n{e}")
  128.         LOGGER.error(e)
  129.         LOGGER.error(format_exc())
  130.         return
  131.     try:
  132.         if not m.reply_to_message.sticker:
  133.             sticker = await create_sticker(
  134.                 await upload_document(
  135.                     c, path, m.chat.id
  136.                 ),
  137.                 sticker_emoji
  138.             )
  139.             await edit_.delete()
  140.             os.remove(path)
  141.         elif m.reply_to_message.sticker:
  142.             sticker = await create_sticker(
  143.                 await get_document_from_file_id(
  144.                     m.reply_to_message.sticker.file_id
  145.                 ),
  146.                 sticker_emoji
  147.             )
  148.     except ShortnameOccupyFailed:
  149.         await m.reply_text("Change Your Name Or Username")
  150.         return
  151.     except Exception as e:
  152.         await m.reply_text(str(e))
  153.         e = format_exc()
  154.         LOGGER.error(e)
  155.         LOGGER.error(format_exc())
  156.     # Find an available pack & add the sticker to the pack; create a new pack if needed
  157.     # Would be a good idea to cache the number instead of searching it every single time...
  158.     kang_lim = 120
  159.     st_in = m.reply_to_message.sticker
  160.     st_type = "norm"
  161.     is_anim = is_vid = False
  162.     if st_in:
  163.         if st_in.is_animated:
  164.             st_type = "ani"
  165.             kang_lim = 50
  166.             is_anim = True
  167.         elif st_in.is_video:
  168.             st_type = "vid"
  169.             kang_lim = 50
  170.             is_vid = True
  171.     packnum = 0
  172.     limit = 0
  173.     volume = 0
  174.     packname_found = False
  175.    
  176.     try:
  177.         while not packname_found:
  178.             packname = f"CE{str(m.from_user.id)}{st_type}{packnum}_by_{Config.BOT_USERNAME}"
  179.             kangpack = f"{('@'+m.from_user.username) if m.from_user.username else m.from_user.first_name[:10]} {st_type} {('vOl '+str(volume)) if volume else ''} by @{Config.BOT_USERNAME}"
  180.             if limit >= 50: # To prevent this loop from running forever
  181.                 await msg.delete()
  182.                 await m.reply_text("Failed to kang\nMay be you have made more than 50 sticker packs with me try deleting some")
  183.                 return
  184.             sticker_set = await get_sticker_set_by_name(c,packname)
  185.             if not sticker_set:
  186.                 sticker_set = await create_sticker_set(
  187.                     client=c,
  188.                     owner=m.from_user.id,
  189.                     title=kangpack,
  190.                     short_name=packname,
  191.                     stickers=[sticker],
  192.                     animated=is_anim,
  193.                     video=is_vid
  194.                 )
  195.             elif sticker_set.set.count >= kang_lim:
  196.                 packnum += 1
  197.                 limit += 1
  198.                 volume += 1
  199.                 continue
  200.             else:
  201.                 try:
  202.                     await add_sticker_to_set(c,sticker_set,sticker)
  203.                 except StickerEmojiInvalid:
  204.                     return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT")
  205.             limit += 1
  206.             packname_found = True
  207.         kb = IKM(
  208.             [
  209.                 [
  210.                     IKB("โž• Add Pack โž•",url=f"t.me/addstickers/{packname}")
  211.                 ]
  212.             ]
  213.         )
  214.         await msg.edit_text(
  215.             f"Kanged the sticker\nPack name: {kangpack}\nEmoji: {sticker_emoji}",
  216.             reply_markup=kb
  217.         )
  218.     except (PeerIdInvalid, UserIsBlocked):
  219.         keyboard = IKM(
  220.             [[IKB("Start me first", url=f"t.me/{Config.BOT_USERNAME}")]]
  221.         )
  222.         await msg.edit_text(
  223.             "You Need To Start A Private Chat With Me.",
  224.             reply_markup=keyboard,
  225.         )
  226.     except StickerPngNopng:
  227.         await msg.delete()
  228.         await m.reply_text(
  229.             "Stickers must be png files but the provided image was not a png"
  230.         )
  231.     except StickerPngDimensions:
  232.         await msg.delete()
  233.         await m.reply_text("The sticker png dimensions are invalid.")
  234.     except StickerTgsNotgs:
  235.         await msg.delete()
  236.         await m.reply_text("Sticker must be tgs file but the provided file was not tgs")
  237.     except StickerVideoNowebm:
  238.         await msg.delete()
  239.         await m.reply_text("Sticker must be webm file but the provided file was not webm")
  240.     except Exception as e:
  241.         await msg.delete()
  242.         await m.reply_text(f"Error occured\n{e}")
  243.     return
  244.  
  245.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement