async def send_complain_sticker(event) -> None: """send a sticker complaning that the user asks too much.""" sticker_set = await userbot( GetStickerSetRequest(stickerset=InputStickerSetShortName("yixinFQJ"))) sticker_message = await event.reply(file=sticker_set.documents[1]) await asyncio.sleep(60) try: await sticker_message.delete() except: logger.info("删除表情提示消息失败")
async def stickerset_exists(conv, setname): try: await borg(GetStickerSetRequest(InputStickerSetShortName(setname))) response = await silently_send_message(conv, "/addsticker") if response.text == "Invalid pack selected.": await silently_send_message(conv, "/cancel") return False await silently_send_message(conv, "/cancel") return True except StickersetInvalidError: return False
def upload(tc, sets, subscribe=False): """Talk to Stickers bot and create the sets.""" if not sets: print(ERROR_NO_SET_UPLOAD) return from functools import partial from telethon.tl.functions.messages import SendMessageRequest, SendMediaRequest, InstallStickerSetRequest from telethon.tl.types import InputMediaUploadedDocument, DocumentAttributeFilename, InputStickerSetShortName from telethon.tl.types.messages import StickerSetInstallResultSuccess _stickerbot = tc.get_input_entity('stickers') send_bot_cmd = partial(_send_bot_cmd, tc, _stickerbot) upload_file = partial(_upload_file, tc) # TODO: check if set already created (by anyone), ask to subscribe if set exists send_bot_cmd(SendMessageRequest, message='/cancel') send_bot_cmd(SendMessageRequest, message='/start') for _set in sets: set_title, set_short_name, stickers = _set send_bot_cmd(SendMessageRequest, message='/newpack') send_bot_cmd(SendMessageRequest, message=set_title) for index, (sticker_image, emojis) in enumerate(stickers): uploaded_file = upload_file(sticker_image) uploaded_doc = InputMediaUploadedDocument( file=uploaded_file, mime_type='image/png', attributes=[DocumentAttributeFilename(uploaded_file.name)]) send_bot_cmd(SendMediaRequest, media=uploaded_doc, message='') send_bot_cmd(SendMessageRequest, message=emojis) print(NOTICE_UPLOADED % { 'fn': uploaded_file.name, 'cur': index + 1, 'total': len(stickers) }) send_bot_cmd(SendMessageRequest, message='/publish') send_bot_cmd(SendMessageRequest, message=set_short_name) print(NOTICE_SET_AVAILABLE % { 'title': set_title, 'short_name': set_short_name }) if subscribe: result = tc.invoke( InstallStickerSetRequest( InputStickerSetShortName(short_name=set_short_name), archived=False)) if isinstance(result, StickerSetInstallResultSuccess): print(NOTICE_SET_SUBSCRIBED % set_title)
async def get_sticker_set( token: str = TOKEN_VALIDATION, name: str = Query(..., description='Name of the sticker set'), ) -> JSONableResponse: """ Use this method to get a sticker set. On success, a StickerSet object is returned. https://core.telegram.org/bots/api#getstickerset """ from ....main import _get_bot bot = await _get_bot(token) result = await bot( GetStickerSetRequest(stickerset=InputStickerSetShortName(name))) data = await to_web_api(result, bot) return r_success(data.to_array())
async def _(e): x = await e.get_reply_message() if not (x and x.media and hasattr(x.media, "document")): return await eod(e, "`Reply To Sticker Only`") set = x.document.attributes[1] sset = await ultroid_bot( GetStickerSetRequest( InputStickerSetID( id=set.stickerset.id, access_hash=set.stickerset.access_hash, ))) pack = sset.set.short_name docs = [ utils.get_input_document(x) for x in (await bot( GetStickerSetRequest(InputStickerSetShortName(pack)))).documents ] for xx in docs: await e.respond(file=(xx))
async def create_sticker_pack( bot: TelegramClient, item: InputStickerSetItem) -> Tuple[bool, Optional[StickerSet]]: try: stickerset: StickerSet = await bot( GetStickerSetRequest( InputStickerSetShortName(STICKER_PACK_SHORT_NAME))) created = False except StickersetInvalidError: stickerset: StickerSet = await bot( CreateStickerSetRequest(user_id=ADMIN_USER_ID, title=STICKER_PACK_TITLE, short_name=STICKER_PACK_SHORT_NAME, stickers=[item])) created = True global sticker_pack sticker_pack = InputStickerSetID(id=stickerset.set.id, access_hash=stickerset.set.access_hash) save_cache() return created, stickerset
async def kantek(client: Client, chat: Channel) -> KanTeXDocument: """Show information about Kantek. Examples: {cmd} """ config = Config() stickerset: StickerSet = await client(GetStickerSetRequest(InputStickerSetShortName("kantek"))) try: await client.send_file(chat, stickerset.documents[0]) except ChatSendStickersForbiddenError: pass return KanTeXDocument( Section(f"{Bold('Kantek')} Userbot", KeyValueItem(Bold('Source'), config.source_url), KeyValueItem(Bold('Version'), client.kantek_version), KeyValueItem(Bold('Telethon version'), telethon.__version__), KeyValueItem(Bold('Python version'), platform.python_version()), KeyValueItem(Bold('KanTeX version'), kantex.__version__), KeyValueItem(Bold('Plugins loaded'), len(client.plugin_mgr.commands) + len(client.plugin_mgr.events))))
async def do_magic(ult): ko = udB.get_key("STICKERS") or {} if not ko.get(ult.sender_id): return await ult.reply("No Sticker Pack Found!") al_ = [] ul = ko[ult.sender_id] if ul.get("static"): al_.extend(ul["static"]) if ul.get("anim"): al_.extend(ul["anim"]) msg = "• **Stickers Owned by You!**\n\n" for _ in al_: try: pack = await ult.client(GetSticker(InputStickerSetShortName(_), hash=0)) msg += f"• [{pack.set.title}](https://t.me/addstickers/{_})\n" except StickerSetInvalidError: if ul.get("anim") and _ in ul["anim"]: ul["anim"].remove(_) else: ul["static"].remove(_) udB.set_key("STICKERS", ko) await ult.reply(msg)
def _do_uploads(self, subscribe): """Talk to Stickers bot and create the sets.""" self._sticker_bot_cmd(SendMessageRequest, message='/cancel') self._sticker_bot_cmd(SendMessageRequest, message='/start') for _set in self._stickersets: set_title, set_short_name, stickers = _set self._sticker_bot_cmd(SendMessageRequest, message='/newpack') self._sticker_bot_cmd(SendMessageRequest, message=set_title) for index, (sticker_image, emojis) in enumerate(stickers): uploaded_file = self._do_upload_file(sticker_image) uploaded_doc = InputMediaUploadedDocument( file=uploaded_file, mime_type='image/png', attributes=[DocumentAttributeFilename(uploaded_file.name)], caption='') self._sticker_bot_cmd(SendMediaRequest, media=uploaded_doc) self._sticker_bot_cmd(SendMessageRequest, message=emojis) print( NOTICE_UPLOADED % { 'fn': uploaded_file.name, 'cur': index + 1, 'total': len(stickers) }) self._sticker_bot_cmd(SendMessageRequest, message='/publish') self._sticker_bot_cmd(SendMessageRequest, message=set_short_name) print(NOTICE_SET_AVAILABLE % { 'title': set_title, 'short_name': set_short_name }) if subscribe: result = self._TC.invoke( InstallStickerSetRequest( InputStickerSetShortName(short_name=set_short_name), archived=False)) if type(result) == StickerSetInstallResultSuccess: print(NOTICE_SET_SUBSCRIBED % set_title)
async def _(event): try: if not event.is_reply: await event.reply( "Reply to a sticker to remove it from your personal sticker pack." ) return reply_message = await event.get_reply_message() kanga = await event.reply("`Deleting .`") if not is_message_image(reply_message): await kanga.edit("Please reply to a sticker.") return rmsticker = await ubot.get_messages(event.chat_id, ids=reply_message.id) stickerset_attr_s = reply_message.document.attributes stickerset_attr = find_instance(stickerset_attr_s, DocumentAttributeSticker) if not stickerset_attr.stickerset: await event.reply("Sticker does not belong to a pack.") return get_stickerset = await tbot( GetStickerSetRequest( InputStickerSetID( id=stickerset_attr.stickerset.id, access_hash=stickerset_attr.stickerset.access_hash, ))) packname = get_stickerset.set.short_name sresult = (await ubot( functions.messages.GetStickerSetRequest( InputStickerSetShortName(packname)))).documents for c in sresult: if int(c.id) != int(stickerset_attr.stickerset.id): await kanga.edit( "This sticker is already removed from your personal sticker pack." ) return await kanga.edit("`Deleting ..`") async with ubot.conversation("@Stickers") as bot_conv: await silently_send_message(bot_conv, "/cancel") response = await silently_send_message(bot_conv, "/delsticker") if "Choose" not in response.text: await tbot.edit_message( kanga, f"**FAILED**! @Stickers replied: {response.text}") return response = await silently_send_message(bot_conv, packname) if not response.text.startswith("Please"): await tbot.edit_message( kanga, f"**FAILED**! @Stickers replied: {response.text}") return try: await rmsticker.forward_to("@Stickers") except Exception as e: print(e) if response.text.startswith("This pack has only"): await silently_send_message(bot_conv, "Delete anyway") await kanga.edit("`Deleting ...`") response = await bot_conv.get_response() if "I have deleted" not in response.text: await tbot.edit_message( kanga, f"**FAILED**! @Stickers replied: {response.text}") return await kanga.edit( "Successfully deleted that sticker from your personal pack.") except Exception as e: os.remove("sticker.webp") print(e)
async def kangcmd(self, message): """Забрасывай в анал свой крючок! использовать: .kang ответить на стикер/документ/фото и можно выбрать эмодзи для стикера Если doesn\'t он будет создан автоматически. """ user = await self.client.get_me() if not user.username: user.username = user.first_name reply = await message.get_reply_message() photo = None emojibypass = False is_anim = False emoji = "" silent_mode = self.config['silent_mode'] if silent_mode != "on": await utils.answer(message, self.strings('preparing_msg', message)) if reply and reply.media: try: if reply.photo: photo = io.BytesIO() photo = await self.client.download_media( reply.photo, photo) elif reply.file: if reply.file.mime_type == "application/x-tgsticker": await self.client.download_file( reply.media.document, 'AnimatedSticker.tgs') try: emoji = reply.media.document.attributes[0].alt except AttributeError: emoji = reply.media.document.attributes[1].alt emojibypass = True is_anim = True photo = 1 else: photo = io.BytesIO() await self.client.download_file( reply.media.document, photo) # For kanging other sticker if reply.sticker: emoji = reply.file.emoji emojibypass = True else: await utils.answer( message, self.strings('unsupported_err', message)) return except AttributeError: photo = io.BytesIO() photo = await self.client.download_media(reply.photo, photo) try: emoji = reply.media.document.attributes[1].alt emojibypass = True except AttributeError: emojibypass = False else: await utils.answer(message, self.strings('reply_err', message)) return if silent_mode != "on": await utils.answer(message, self.strings('gettingType_msg', message)) if photo: splat = message.text.split() if not emojibypass or not emoji: emoji = "🤔" pack = 1 if len(splat) == 3: pack = splat[2] # User sent both emoji = splat[1] elif len(splat) == 2: if splat[1].isnumeric(): pack = int(splat[1]) else: emoji = splat[1] packname = f"a{user.id}_by_{user.username}_{pack}" packnick = self.config['pack_name'].replace( '%username%', f'@{user.username}').replace("%packNumber%", str(pack)) cmd = '/newpack' file = io.BytesIO() if not is_anim: image = await resize_photo(photo) file.name = "sticker.png" image.save(file, "PNG") if silent_mode != "on": await utils.answer( message, self.strings('image_kanging_msg', message)) else: packname += "_anim" packnick += " animated" cmd = '/newanimated' if silent_mode != "on": await utils.answer( message, self.strings('animated_kanging_msg', message)) try: response = await self.client( GetStickerSetRequest(stickerset=InputStickerSetShortName( short_name=packname))) except StickersetInvalidError: response = None if response is not None: async with self.client.conversation('Stickers') as conv: await conv.send_message('/addsticker') await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packname) x = await conv.get_response() mtext = x.text while '120' in mtext: pack += 1 packname = f"a{user.id}_by_{user.username}_{pack}" packnick = self.config['pack_name'].replace( '%username%', f'@{user.username}').replace( "%packNumber%", # noqa: E128 str(pack)) if silent_mode != "on": await utils.answer(message, self.strings('switching_msg', message)\ .format(str(pack))) await conv.send_message(packname) x = await conv.get_response() mtext = x.text if x.text == "Invalid pack selected." or x.text == "Не выбран набор стикеров.": await conv.send_message(cmd) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await conv.send_message(packnick) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) if is_anim: await conv.send_file('AnimatedSticker.tgs', force_document=True) DelFile('AnimatedSticker.tgs') else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await conv.send_message("/publish") if is_anim: await conv.get_response() await conv.send_message(f"<{packnick}>") await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await conv.send_message("/skip") await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await conv.send_message(packname) await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await utils.answer(message, self.strings('added_to_different_msg', message)\ .format( # noqa: E127 f"t.me/addstickers/{packname}" )) await sleep(5) await message.delete() return if is_anim: await conv.send_file('AnimatedSticker.tgs', force_document=True) # noqa: E128 DelFile('AnimatedSticker.tgs') else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message('/done') await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) else: if silent_mode != "on": await utils.answer(message, self.strings('pack_notExist', message)) async with self.client.conversation('Stickers') as conv: await conv.send_message(cmd) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packnick) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) if is_anim: await conv.send_file('AnimatedSticker.tgs', force_document=True) # noqa: E128 DelFile('AnimatedSticker.tgs') else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message("/publish") if is_anim: await conv.get_response() await conv.send_message(f"<{packnick}>") await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message("/skip") await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message(packname) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await utils.answer(message, self.strings('added_msg', message)\ .format( # noqa: E127 f"t.me/addstickers/{packname}" )) await sleep(5) await message.delete()
async def send_complain_sticker(event) -> None: """send a sticker complaning that the user asks too much.""" sticker_set = await userbot( GetStickerSetRequest(stickerset=InputStickerSetShortName("yixinFQJ"))) await event.reply(file=sticker_set.documents[1])
async def kang_cmd(ult): sender = await ult.get_sender() if not isinstance(sender, User): return if not ult.is_reply: return await ult.eor("`Reply to a sticker/photo..`", time=5) reply = await ult.get_reply_message() if sender.username: pre = sender.username[:4] else: pre = random.random_string(length=3) animated, dl = None, None try: emoji = ult.text.split(maxsplit=1)[1] except IndexError: emoji = None if reply.sticker: file = get_input_document(reply.sticker) emoji = emoji or reply.file.emoji if reply.file.name.endswith(".tgs"): animated = True dl = await reply.download_media() elif reply.photo: dl = await reply.download_media() name = "sticker.webp" image = resize_photo(dl) image.save(name, "WEBP") elif reply.text: dl = await create_quotly(reply) else: return await ult.eor("`Reply to sticker or text to add it in your pack...`") if not emoji: emoji = "🏵" if dl: upl = await ult.client.upload_file(dl) file = get_input_document( await ult.client(UploadMediaRequest(InputPeerSelf(), upl)) ) get_ = udB.get_key("STICKERS") or {} type_ = "static" if not animated else "anim" if not get_.get(ult.sender_id) or not get_.get(ult.sender_id, {}).get(type_): sn = f"{pre}_{ult.sender_id}" title = f"{get_display_name(sender)}'s Kang Pack" if animated: type_ = "anim" sn += "_anim" title += " (Animated)" sn += f"_by_{asst.me.username}" try: await asst(GetSticker(InputStickerSetShortName(sn), hash=0)) sn = sn.replace(str(ult.sender_id), f"{ult.sender_id}_{ult.id}") except StickersetInvalidError: pass try: pack = await ult.client( CreateStickerSetRequest( user_id=sender.id, title=title, short_name=sn, stickers=[SetItem(file, emoji=emoji)], animated=animated, ) ) except Exception as er: return await ult.eor(str(er)) sn = pack.set.short_name if not get_.get(ult.sender_id): get_.update({ult.sender_id: {type_: [sn]}}) else: get_[ult.sender_id].update({type_: [sn]}) udB.set_key("STICKERS", get_) return await ult.reply( f"**Kanged Successfully!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})" ) name = get_[ult.sender_id][type_][-1] try: await asst(GetSticker(InputStickerSetShortName(name), hash=0)) except StickersetInvalidError: get_[ult.sender_id][type_].remove(name) try: await asst( AddSticker(InputStickerSetShortName(name), SetItem(file, emoji=emoji)) ) except (errors.StickerpackStickersTooMuchError, errors.StickersTooMuchError): sn = f"{pre}{ult.sender_id}_{ult.id}" title = f"{get_display_name(sender)}'s Kang Pack" if animated: sn += "_anim" title += " (Animated)" sn += f"_by_{asst.me.username}" try: pack = await ult.client( CreateStickerSetRequest( user_id=sender.id, title=title, short_name=sn, stickers=[SetItem(file, emoji=emoji)], animated=animated, ) ) except Exception as er: return await ult.eor(str(er)) get_[ult.sender_id][type_].append(pack.set.short_name) udB.set_key("STICKERS", get_) return await ult.reply( f"**Created New Kang Pack!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})" ) except Exception as er: LOGS.exception(er) return await ult.reply(str(er)) await ult.reply( f"Sticker Added to Pack Successfully\n**Link :** [Click Here](https://t.me/addstickers/{name})" )
async def kangcmd(self, message): """Kangs a sticker or image to your own pack! Usage: .kang (reply) (optional: emoji) If pack doesn\'t exist it will be created automatically. """ user = await self.client.get_me() if not user.username: user.username = user.first_name reply = await message.get_reply_message() photo = None is_anim = False emoji = "" silent_mode = "on" if self.config["silent_mode"] == "on" else "off" if silent_mode != "on": await utils.answer(message, self.strings("preparing_msg", message)) if reply and reply.media: try: if reply.photo: photo = io.BytesIO() await self.client.download_media(reply.photo, photo) elif reply.file: if reply.file.mime_type == "application/x-tgsticker": await self.client.download_file( reply.media.document, "AnimatedSticker.tgs") emoji = reply.file.emoji is_anim = True else: photo = io.BytesIO() await self.client.download_file( reply.media.document, photo) if reply.sticker: emoji = reply.file.emoji else: await utils.answer( message, self.strings("unsupported_err", message)) return except AttributeError: photo = io.BytesIO() await self.client.download_media(reply.photo, photo) emoji = reply.file.emoji else: await utils.answer(message, self.strings("reply_err", message)) return if silent_mode != "on": await utils.answer(message, self.strings("gettingType_msg", message)) if photo or is_anim: splat = message.text.split() if not emoji: emoji = "🤔" pack = 1 if len(splat) == 3: pack = splat[2] # User sent both emoji = splat[1] elif len(splat) == 2: if splat[1].isnumeric(): pack = int(splat[1]) else: emoji = splat[1] packname = f"a{user.id}_by_{user.username}_{pack}" packnick = self.config["pack_name"].replace( "%username%", f"@{user.username}").replace("%packNumber%", str(pack)) cmd = "/newpack" file = io.BytesIO() if not is_anim: image = await resize_photo(photo) file.name = "sticker.png" image.save(file, "PNG") if silent_mode != "on": await utils.answer( message, self.strings("image_kanging_msg", message)) else: packname += "_anim" packnick += " animated" cmd = "/newanimated" if silent_mode != "on": await utils.answer( message, self.strings("animated_kanging_msg", message)) try: response = await self.client( GetStickerSetRequest(stickerset=InputStickerSetShortName( short_name=packname))) except StickersetInvalidError: response = None if response is not None: async with self.client.conversation("Stickers") as conv: await conv.send_message("/addsticker") await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packname) x = await conv.get_response() mtext = x.text while "120" in mtext: pack += 1 packname = f"a{user.id}_by_{user.username}_{pack}" packnick = self.config["pack_name"] packnick = packnick.replace( "%username%", f"@{user.username}").replace( "%packNumber%", str(pack)) if silent_mode != "on": await utils.answer( message, self.strings("switching_msg", message).format(str(pack))) await conv.send_message(packname) x = await conv.get_response() mtext = x.text if x.text == "Invalid pack selected." or x.text == "Не выбран набор стикеров.": await conv.send_message(cmd) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await conv.send_message(packnick) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) if is_anim: await conv.send_file("AnimatedSticker.tgs", force_document=True) DelFile("AnimatedSticker.tgs") else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await conv.send_message("/publish") if is_anim: await conv.get_response() await conv.send_message(f"<{packnick}>") await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await conv.send_message("/skip") await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await conv.send_message(packname) await self.client.send_read_acknowledge( conv.chat_id) await conv.get_response() await self.client.send_read_acknowledge( conv.chat_id) await utils.answer( message, self.strings( "added_to_different_msg", message).format( f"t.me/addstickers/{packname}")) await sleep(5) await message.delete() return if is_anim: await conv.send_file("AnimatedSticker.tgs", force_document=True) # noqa: E128 DelFile("AnimatedSticker.tgs") else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message("/done") await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) else: if silent_mode != "on": await utils.answer(message, self.strings("pack_notExist", message)) async with self.client.conversation("Stickers") as conv: await conv.send_message(cmd) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message(packnick) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) if is_anim: await conv.send_file("AnimatedSticker.tgs", force_document=True) # noqa: E128 DelFile("AnimatedSticker.tgs") else: file.seek(0) await conv.send_file(file, force_document=True) await conv.get_response() await conv.send_message(emoji) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message("/publish") if is_anim: await conv.get_response() await conv.send_message(f"<{packnick}>") await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await conv.send_message("/skip") await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await conv.send_message(packname) await self.client.send_read_acknowledge(conv.chat_id) await conv.get_response() await self.client.send_read_acknowledge(conv.chat_id) await utils.answer( message, self.strings("added_msg", message).format(f"t.me/addstickers/{packname}")) await sleep(5) await message.delete()
async def kang(event): """ <b>param:</b> <code>emoji</code> <b>return:</b> <i>Sticker Pack link including the kanged sticker</i> """ if not event.is_reply: await event.edit("There's no image given for me to kang!") return rep_msg = await event.get_reply_message() file = rep_msg.photo or rep_msg.document if has_image(file): st_emoji = event.args.emoji or "🤔" if st_emoji not in (list(emoji.EMOJI_UNICODE.values())): await event.edit("Not a valid emoji!") return user = await event.get_sender() packname = user.username or user.first_name + "'s sticker pack!" packshort = "tg_companion_" + str(user.id) await event.edit("Processing sticker! Please wait...") async with event.client.conversation('Stickers') as conv: until_time = (datetime.datetime.now() + datetime.timedelta(minutes=1)).timestamp() await event.client( UpdateNotifySettingsRequest(peer="Stickers", settings=InputPeerNotifySettings( show_previews=False, mute_until=until_time))) try: await conv.send_message("/cancel") except YouBlockedUserError: await event.reply( "You blocked the sticker bot. Please unblock it and try again" ) return file = await event.client.download_file(file) with BytesIO(file) as mem_file, BytesIO() as sticker: resize_image(mem_file, (512, 512), sticker) sticker.seek(0) uploaded_sticker = await event.client.upload_file( sticker, file_name="sticker.png") try: await event.client( GetStickerSetRequest(InputStickerSetShortName(packname))) new_pack = False except StickersetInvalidError: new_pack = True if new_pack is False: await conv.send_message("/newpack") response = await conv.get_response() if not response.text.startswith("Yay!"): await event.edit(response.text) return await conv.send_message(packname) response = await conv.get_response() if not response.text.startswith("Alright!"): await event.edit(response.text) return await conv.send_file(InputMediaUploadedDocument( file=uploaded_sticker, mime_type='image/png', attributes=[DocumentAttributeFilename("sticker.png")]), force_document=True) await conv.send_message(st_emoji) await conv.send_message("/publish") await conv.send_message("/skip") await conv.send_message(packshort) response = conv.get_response() else: await conv.send_message("/addsticker") await conv.send_message(packshort) await conv.send_file(InputMediaUploadedDocument( file=uploaded_sticker, mime_type='image/png', attributes=[DocumentAttributeFilename("sticker.png")]), force_document=True) await conv.send_message(st_emoji) await conv.send_message("/done") await event.edit( "Sticker added! Your pack can be found [here](https://t.me/addstickers/{})" .format(packshort)) else: await event.edit("Not a valid media entity!")