Advertisement
disk6969

Untitled

Jan 19th, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. import asyncio
  2. from telethon.tl.types import (
  3.     InputStickerSetShortName,
  4.     InputStickerSetItem,
  5.     DocumentAttributeCustomEmoji,
  6. )
  7. from telethon.tl.functions.messages import GetStickerSetRequest, UploadMediaRequest
  8. from telethon.tl.functions.stickers import CreateStickerSetRequest
  9. from telethon.tl.custom.file import File
  10. from telethon.utils import get_input_document
  11. import os
  12.  
  13. custom_emoji = lambda s: File(s)._from_attr(DocumentAttributeCustomEmoji, "alt")
  14.  
  15.  
  16. async def clone_pack(set_url, new_shortname=None, new_title=None):
  17.     r = await client(
  18.         GetStickerSetRequest(InputStickerSetShortName(set_url.split("/")[-1]), 0)
  19.     )
  20.     sticker_set = r.set
  21.     new_shortname = new_shortname or sticker_set.short_name + "_2"
  22.     new_title = new_title or sticker_set.title + " 2"
  23.  
  24.     if not (sticker_set.videos or sticker_set.animated):
  25.         stickers = [
  26.             InputStickerSetItem(
  27.                 get_input_document(doc), File(doc).emoji or custom_emoji(doc)
  28.             )
  29.             for doc in r.documents
  30.         ]
  31.     else:
  32.         files = await asyncio.gather(
  33.             *[client.download_media(s, "stickers_temp/") for s in r.documents]
  34.         )
  35.         medias = [
  36.             (await client._file_to_media(file))[1]
  37.             for file in await asyncio.gather(
  38.                 *[client.upload_file(file) for file in files]
  39.             )
  40.         ]
  41.         medias = await asyncio.gather(
  42.             *[client(UploadMediaRequest("me", file)) for file in medias]
  43.         )
  44.         stickers = [
  45.             InputStickerSetItem(
  46.                 get_input_document(doc), File(sticker).emoji or custom_emoji(sticker)
  47.             )
  48.             for (doc, sticker) in zip(medias, r.documents)
  49.         ]
  50.         for file in files:
  51.             os.remove(file)
  52.  
  53.     cloned_pack = await client(
  54.         CreateStickerSetRequest(
  55.             'me',
  56.             title=new_title,
  57.             short_name=new_shortname,
  58.             stickers=stickers,
  59.             animated=sticker_set.animated,
  60.             videos=sticker_set.videos,
  61.             emojis=sticker_set.emojis,
  62.         )
  63.     )
  64.     return f"https://t.me/addstickers/{cloned_pack.set.short_name}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement