Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from telethon.tl.types import (
- InputStickerSetShortName,
- InputStickerSetItem,
- DocumentAttributeCustomEmoji,
- )
- from telethon.tl.functions.messages import GetStickerSetRequest, UploadMediaRequest
- from telethon.tl.functions.stickers import CreateStickerSetRequest
- from telethon.tl.custom.file import File
- from telethon.utils import get_input_document
- import os
- custom_emoji = lambda s: File(s)._from_attr(DocumentAttributeCustomEmoji, "alt")
- async def clone_pack(set_url, new_shortname=None, new_title=None):
- r = await client(
- GetStickerSetRequest(InputStickerSetShortName(set_url.split("/")[-1]), 0)
- )
- sticker_set = r.set
- new_shortname = new_shortname or sticker_set.short_name + "_2"
- new_title = new_title or sticker_set.title + " 2"
- if not (sticker_set.videos or sticker_set.animated):
- stickers = [
- InputStickerSetItem(
- get_input_document(doc), File(doc).emoji or custom_emoji(doc)
- )
- for doc in r.documents
- ]
- else:
- files = await asyncio.gather(
- *[client.download_media(s, "stickers_temp/") for s in r.documents]
- )
- medias = [
- (await client._file_to_media(file))[1]
- for file in await asyncio.gather(
- *[client.upload_file(file) for file in files]
- )
- ]
- medias = await asyncio.gather(
- *[client(UploadMediaRequest("me", file)) for file in medias]
- )
- stickers = [
- InputStickerSetItem(
- get_input_document(doc), File(sticker).emoji or custom_emoji(sticker)
- )
- for (doc, sticker) in zip(medias, r.documents)
- ]
- for file in files:
- os.remove(file)
- cloned_pack = await client(
- CreateStickerSetRequest(
- 'me',
- title=new_title,
- short_name=new_shortname,
- stickers=stickers,
- animated=sticker_set.animated,
- videos=sticker_set.videos,
- emojis=sticker_set.emojis,
- )
- )
- return f"https://t.me/addstickers/{cloned_pack.set.short_name}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement