async def quote(event: NewMessage.Event) -> None: if event.fwd_from: return if not event.reply_to_msg_id: await event.edit("```Reply to any user message.```") return reply_message = await event.get_reply_message() if not reply_message.text: await event.edit("```Reply to text message```") return chat = "@QuotLyBot" sender = reply_message.sender if reply_message.sender.bot: await event.edit("```Reply to actual users message.```") return await event.edit("```Making a Quote```") async with client.conversation(chat) as conv: try: response = conv.wait_event(events.NewMessage(incoming=True, from_users=1031952739)) await client.forward_messages(chat, reply_message) response = await response except YouBlockedUserError: await event.reply("```Please unblock @QuotLyBot and try again```") return if response.text.startswith("Hi!"): await event.edit("```Can you kindly disable your forward privacy settings for good?```") else: await event.delete() await client.forward_messages(event.chat_id, response.message) await client.send_read_acknowledge(event.chat_id)
async def _list_packs() -> Tuple[List[str], types.Message]: async with client.conversation(**conversation_args) as conv: first = await conv.send_message("/cancel") r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await conv.send_message("/packstats") r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) if r2.text.startswith("You don't have any sticker packs yet."): return [], first buttons = list(itertools.chain.from_iterable(r2.buttons or [])) await conv.send_message("/cancel") r3 = await conv.get_response() LOGGER.debug("Stickers:" + r3.text) await client.send_read_acknowledge(conv.chat_id) return [button.text for button in buttons] if buttons else [], first
async def _list_packs(): async with client.conversation(**conversation_args) as conv: first = await conv.send_message('/cancel') r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message('/packstats') r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) if r2.text.startswith("You don't have any sticker packs yet."): return [], first await client.send_read_acknowledge(conv.chat_id) buttons = list(chain.from_iterable(r2.buttons)) await conv.send_message('/cancel') r3 = await conv.get_response() LOGGER.debug("Stickers:" + r3.text) await client.send_read_acknowledge(conv.chat_id) return [button.text for button in buttons], first
async def kang(event: NewMessage.Event) -> None: """ Steal (AKA kang) stickers and images to your Sticker packs. `{prefix}kang [pack] [emojis]` or **{prefix}kang (short)=(title) [emojis]** `pack` and `emojis` can be used as arguments as well. """ match = event.matches[0].group(1) or "" if event.reply_to_msg_id: sticker_event = await event.get_reply_message() if not await _is_sticker_event(sticker_event): await event.answer("`Invalid message type!`") return else: sticker_event = None async for msg in client.iter_messages( event.chat_id, offset_id=event.message.id, limit=10 ): if await _is_sticker_event(msg): sticker_event = msg break if not sticker_event: await event.answer( "`Couldn't find any acceptable media in the recent messages.`" ) return new_pack = False first_msg = None new_first_msg = None args, kwargs = await client.parse_arguments(match) pack, emojis, name, is_animated = await _resolve_messages( args, kwargs, sticker_event ) prefix = client.prefix if client.prefix is not None else "." notif = await client(functions.account.GetNotifySettingsRequest(peer="Stickers")) await _update_stickers_notif(DEFAULT_MUTE) if pack or len(kwargs) == 1: if pack and pack.lower() == "auto": pack, packnick = await _get_userbot_auto_pack(is_animated) if kwargs: pack = None packnick = None for x, y in kwargs.items(): pack = str(x) packnick = str(y) if not (pack and packnick): await event.answer( "`Are you sure you're using the correct syntax?`\n" f"`{prefix}kang <packName>=<packsShortName>`\n" "`You can also choose emojis whilst making a new pack.`" ) await _update_stickers_notif(notif) return packs, first_msg = await _list_packs() is_pack = await _verify_cs_name(pack, packs) if is_pack: pack = is_pack new_pack = False else: new_pack = True attribute_emoji = None if sticker_event.sticker: for attribute in sticker_event.media.document.attributes: if isinstance(attribute, types.DocumentAttributeSticker): attribute_emoji = attribute.alt if attribute_emoji: if emojis and attribute_emoji not in emojis: emojis += attribute_emoji else: emojis = attribute_emoji else: packs, first_msg = await _list_packs() is_pack = await _verify_cs_name(pack, packs) if "_kang_pack" in pack: new_pack = True elif not is_pack: await event.answer( NO_PACK.format( pack, prefix, pack or "<pack username>", emojis or default_emoji ) ) await _delete_sticker_messages(first_msg) await _update_stickers_notif(notif) return else: pack = is_pack else: basic, animated = await _get_default_packs() packs, first_msg = await _list_packs() if is_animated: pack = await _verify_cs_name(animated, packs) if not pack: if "_kang_pack" in animated: await event.answer( "`Making a new animated kang pack, please wait!`" ) pack = animated _, packnick = await _get_userbot_auto_pack(is_animated) new_pack = True else: pack = animated or "a default animated pack" await event.answer(FALSE_DEFAULT.format(pack, prefix)) await _delete_sticker_messages(first_msg) await _update_stickers_notif(notif) return else: pack = await _verify_cs_name(basic, packs) if not pack: if "_kang_pack" in basic: await event.answer("`Making a new kang pack, please wait!`") pack = basic _, packnick = await _get_userbot_auto_pack(is_animated) new_pack = True else: pack = basic or "a default pack" await event.answer(FALSE_DEFAULT.format(pack, prefix)) await _delete_sticker_messages(first_msg) await _update_stickers_notif(notif) return await event.answer(f"`{random.choice(KANGING_STR)}`") async with client.conversation(**conversation_args) as conv: if new_pack: packtype = "/newanimated" if is_animated else "/newpack" new_first_msg = await conv.send_message(packtype) r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await conv.send_message(packnick) r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) else: await conv.send_message("/addsticker") r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await conv.send_message(pack) r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) if "120 stickers" in r2.text: if "_kang_pack" in pack: pack, packnick, new_pack = await _get_new_ub_pack( conv, packs, is_animated ) if new_pack: await event.answer( "`Current kang pack is full, making a new one!`" ) await conv.send_message("/cancel") r12 = await conv.get_response() LOGGER.debug("Stickers:" + r12.text) packtype = "/newanimated" if is_animated else "/newpack" await conv.send_message(packtype) r13 = await conv.get_response() LOGGER.debug("Stickers:" + r13.text) await conv.send_message(packnick) r14 = await conv.get_response() LOGGER.debug("Stickers:" + r14.text) else: await event.answer(f"`{pack} has reached it's limit!`") await _delete_sticker_messages(first_msg or new_first_msg) await _update_stickers_notif(notif) return elif ".TGS" in r2.text and not is_animated: await event.answer( "`I can't kang a normal sticker" " to an animated pack!`" ) await _delete_sticker_messages(first_msg or new_first_msg) await _update_stickers_notif(notif) return elif ".PSD" in r2.text and is_animated: await event.answer( "`I can't kang an animated sticker" "to a normal pack!`" ) await _delete_sticker_messages(first_msg or new_first_msg) await _update_stickers_notif(notif) return sticker = io.BytesIO() sticker.name = name await sticker_event.download_media(file=sticker) if ( sticker_event.sticker and sticker_event.sticker.mime_type == "application/x-tgsticker" ): sticker.seek(0) await conv.send_message(file=sticker, force_document=True) else: new_sticker = io.BytesIO() if sticker_event.sticker: resized_sticker = await _resize_image(sticker, new_sticker, False) else: resized_sticker = await _resize_image(sticker, new_sticker) if isinstance(resized_sticker, str): await event.answer(resized_sticker) await _update_stickers_notif(notif) return await conv.send_message(file=new_sticker, force_document=True) new_sticker.close() sticker.close() r3 = await conv.get_response() LOGGER.debug("Stickers:" + r3.text) await conv.send_message(emojis) r4 = await conv.get_response() LOGGER.debug("Stickers:" + r4.text) if new_pack: await conv.send_message("/publish") r5 = await conv.get_response() LOGGER.debug("Stickers:" + r5.text) if is_animated: await conv.send_message("<" + packnick + ">") r41 = await conv.get_response() LOGGER.debug("Stickers:" + r41.text) if r41.text == "Invalid pack selected.": await event.answer("`Invalid pack selected.`") await conv.send_message("/cancel") await conv.get_response() await client.send_read_acknowledge(conv.chat_id) await _update_stickers_notif(notif) return await conv.send_message("/skip") r6 = await conv.get_response() LOGGER.debug("Stickers:" + r6.text) await conv.send_message(pack) r7 = await conv.get_response() LOGGER.debug("Stickers:" + r7.text) if "Sorry" in r7.text: await conv.send_message("/cancel") r61 = await conv.get_response() LOGGER.debug("Stickers:" + r61.text) await event.answer( "`Pack's short name is unacceptable or already taken. " "Try thinking of a better short name.`" ) await _delete_sticker_messages(first_msg or new_first_msg) await _update_stickers_notif(notif) return else: await conv.send_message("/done") r5 = await conv.get_response() LOGGER.debug("Stickers:" + r5.text) pack = f"[{pack}](https://t.me/addstickers/{pack})" extra = await get_chat_link(event, sticker_event.id) await event.answer( f"`Successfully added the sticker to` {pack} `!`", self_destruct=4, log=("kang", f"Successfully kanged a sticker from {extra} to {pack}"), ) await client.send_read_acknowledge(conv.chat_id) await _delete_sticker_messages(first_msg or new_first_msg) await _update_stickers_notif(notif)
async def delsticker(event: NewMessage.Event) -> None: """ Remove a sticker from your existing pack. `{prefix}delsticker` in reply to your sticker """ if not event.reply_to_msg_id: await event.answer("`Reply to a sticker to delete it.`") return reply = await event.get_reply_message() if not reply.sticker: await event.answer("`Wait a minute, this isn't a sticker!`") return stickerset = None for a in reply.document.attributes: if isinstance(a, types.DocumentAttributeSticker): stickerset = a.stickerset break if not stickerset: await event.answer("`Couldn't find the sticker set.`") return result = await client( functions.messages.GetStickerSetRequest(stickerset=stickerset) ) short_name = result.set.short_name notif = await client(functions.account.GetNotifySettingsRequest(peer="Stickers")) await _update_stickers_notif(DEFAULT_MUTE) await event.answer("`Fetching all your sticker packs.`") packs, first_msg = await _list_packs() target_pack = None for pack in packs: if short_name in pack: target_pack = pack break if not target_pack: await event.answer("`Couldn't find the specified set in your packs.`") await _delete_sticker_messages(first_msg) await _update_stickers_notif(notif) return await event.answer("`Deleting the sticker from your pack.`") async with client.conversation(**conversation_args) as conv: await conv.send_message("/delsticker") await conv.get_response() await conv.send_message(target_pack) r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await reply.forward_to("@Stickers") r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) status = True if "I have deleted that sticker for you" in r2.text else r2.text await conv.send_message("/cancel") await conv.get_response() if status is True: pack = f"[{short_name}](https://t.me/addstickers/{short_name})" await event.answer( f"`Successfully removed the sticker from` {pack}!", self_destruct=4, log=("delsticker", f"Successfully deleted a sticker from {pack}!"), ) await _delete_sticker_messages(first_msg) else: await event.answer( "**Couldn't delete the sticker. Perhaps it's not in your pack.**" "\n`Check the chat with @Stickers for more information.`" ) await client.send_read_acknowledge("@Stickers") await _update_stickers_notif(notif)
async def kang(event): """Steal stickers to your Sticker packs""" if event.reply_to_msg_id: sticker_event = await event.get_reply_message() if not await _is_sticker_event(sticker_event): await event.edit("`Invalid message type!`") return else: sticker_event = None async for msg in client.iter_messages(event.chat_id, offset_id=event.message.id, limit=10): if await _is_sticker_event(msg): sticker_event = msg break if not sticker_event: await event.edit( "`Couldn't find any acceptable media in the recent messages.`") return new_pack = False first_msg = None new_first_msg = None pack, emojis, name, is_animated = await _resolve_messages( event, sticker_event) prefix = client.prefix if client.prefix is not None else '.' if pack: if (':' in pack) or ('=' in pack): text = event.matches[0].group(1) pack, packnick, new_emojis = await _resolve_pack_name( text, is_animated) if not pack and not packnick: await event.edit( "`Are you sure you're using the correct syntax?`\n" f"`{prefix}kang <packName>=<packsShortName>`\n" "`You can also choose emojis whilst making a new pack.`") return packs, first_msg = await _list_packs() is_pack = await _verify_cs_name(pack, packs) if is_pack: pack = is_pack new_pack = False else: new_pack = True attribute_emoji = None if sticker_event.sticker: attribute_emoji = ( attribute.alt for attribute in sticker_event.media.document.attributes if isinstance(attribute, DocumentAttributeSticker)) emojis = new_emojis or attribute_emoji or default_emoji else: packs, first_msg = await _list_packs() is_pack = await _verify_cs_name(pack, packs) if "_kang_pack" in pack: new_pack = True elif not is_pack: await event.edit( NO_PACK.format(pack, prefix, pack or "<pack username>", emojis or default_emoji)) await _delete_sticker_messages(first_msg) return else: pack = is_pack else: basic, animated = await _get_default_packs() packs, first_msg = await _list_packs() if is_animated: pack = await _verify_cs_name(animated, packs) if not pack: if "_kang_pack" in animated: await event.edit("`Making a custom TG-UserBot pack!`") user = await client.get_me() tag = '@' + user.username if user.username else user.id new_pack = True pack = animated packnick = f"{tag}'s animated kang pack" else: pack = animated or "a default animated pack" await event.edit(FALSE_DEFAULT.format(pack, prefix)) await _delete_sticker_messages(first_msg) return else: pack = await _verify_cs_name(basic, packs) if not pack: if "_kang_pack" in basic: await event.edit("`Making a custom TG-UserBot pack!`") user = await client.get_me() tag = '@' + user.username if user.username else user.id new_pack = True pack = basic packnick = f"{tag}'s kang pack" else: pack = basic or "a default pack" await event.edit(FALSE_DEFAULT.format(pack, prefix)) await _delete_sticker_messages(first_msg) return await event.edit( "`Turning on the kang machine... Your sticker? My sticker!`") async with client.conversation(**conversation_args) as conv: if new_pack: packtype = "/newanimated" if is_animated else "/newpack" new_first_msg = await conv.send_message(packtype) r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message(packnick) r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) await client.send_read_acknowledge(conv.chat_id) else: await conv.send_message('/addsticker') r1 = await conv.get_response() LOGGER.debug("Stickers:" + r1.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message(pack) r2 = await conv.get_response() LOGGER.debug("Stickers:" + r2.text) await client.send_read_acknowledge(conv.chat_id) if "120 stickers" in r2.text: if "_kang_pack" in pack: await event.edit( "`Current userbot pack is full, making a new one!`") await conv.send_message('/cancel') r11 = await conv.get_response() LOGGER.debug("Stickers:" + r11.text) await client.send_read_acknowledge(conv.chat_id) pack, packnick = await _get_new_ub_pack(packs, is_animated) packtype = "/newanimated" if is_animated else "/newpack" await conv.send_message(packtype) r12 = await conv.get_response() LOGGER.debug("Stickers:" + r12.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message(packnick) r13 = await conv.get_response() LOGGER.debug("Stickers:" + r13.text) await client.send_read_acknowledge(conv.chat_id) new_pack = True else: await event.edit(f"`{pack} has reached it's limit!`") await _delete_sticker_messages(first_msg or new_first_msg) return elif ".TGS" in r2.text and not is_animated: await event.edit( "`You're trying to kang a normal sticker " "to an animated pack. Choose the correct pack!`") await _delete_sticker_messages(first_msg or new_first_msg) return elif ".PSD" in r2.text and is_animated: await event.edit("`You're trying to kang an animated sticker " "to a normal pack. Choose the correct pack!`") await _delete_sticker_messages(first_msg or new_first_msg) return sticker = BytesIO() sticker.name = name await sticker_event.download_media(file=sticker) sticker.seek(0) if sticker_event.sticker: await conv.send_message(file=sticker, force_document=True) else: new_sticker = BytesIO() resized_sticker = await _resize_image(sticker, new_sticker) new_sticker.name = name new_sticker.seek(0) await conv.send_message(file=resized_sticker, force_document=True) new_sticker.close() sticker.close() r3 = await conv.get_response() LOGGER.debug("Stickers:" + r3.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message(emojis) r4 = await conv.get_response() LOGGER.debug("Stickers:" + r4.text) await client.send_read_acknowledge(conv.chat_id) if new_pack: await conv.send_message('/publish') r5 = await conv.get_response() LOGGER.debug("Stickers:" + r5.text) await client.send_read_acknowledge(conv.chat_id) if is_animated: await conv.send_message('<' + packnick + '>') r41 = await conv.get_response() LOGGER.debug("Stickers:" + r41.text) await client.send_read_acknowledge(conv.chat_id) if r41.text == "Invalid pack selected.": await event.edit("`You tried to kang to an invalid pack.`") await conv.send_message('/cancel') await conv.get_response() await client.send_read_acknowledge(conv.chat_id) return await conv.send_message('/skip') r6 = await conv.get_response() LOGGER.debug("Stickers:" + r6.text) await client.send_read_acknowledge(conv.chat_id) await conv.send_message(pack) r7 = await conv.get_response() LOGGER.debug("Stickers:" + r7.text) await client.send_read_acknowledge(conv.chat_id) if "Sorry" in r7.text: await conv.send_message('/cancel') r61 = await conv.get_response() LOGGER.debug("Stickers:" + r61.text) await client.send_read_acknowledge(conv.chat_id) await event.edit( "`Pack's short name is unacceptable or already taken. " "Try thinking of a better short name.`") await _delete_sticker_messages(first_msg or new_first_msg) return else: await conv.send_message('/done') r5 = await conv.get_response() LOGGER.debug("Stickers:" + r5.text) await client.send_read_acknowledge(conv.chat_id) await event.edit("`Successfully added the sticker to` " f"[{pack}](https://t.me/addstickers/{pack})`!`") await _delete_sticker_messages(first_msg or new_first_msg)
async def fban(event: NewMessage.Event) -> None: """ Fban a user in all your feds. `{prefix}fban` in reply or **{prefix}fban user1 user2 [kwargs]** **Arguments:** `r` """ match = event.matches[0].group(1) args, kwargs = await client.parse_arguments(match) reason = kwargs.get("r", None) skipped = {} fbanned = [] failed = [] fban_admin_chats_list = client.config["userbot"].get("fban_admin_chats", None) if not fban_admin_chats_list: await event.answer( "`Atleast one fedadmin chat should be set up for this to work!`" ) return fban_admin_chats = set(int(x) for x in fban_admin_chats_list.split(",")) if not args and event.reply_to_msg_id: reply = await event.get_reply_message() args.append(reply.sender_id) if not args: await event.answer("`At least specifiy a user, maybe?`") return entity = await event.get_chat() for chat in fban_admin_chats: if event.reply_to_msg_id: reply = await event.get_reply_message() await reply.forward_to(chat) for user in args: if isinstance(user, list): continue try: async with client.conversation(chat) as conv: spammer = await client.get_entity(user) await conv.send_message( f'/fban [{spammer.id}](tg://user?id={spammer.id}){" " + reason if reason else ""}' ) resp = await conv.get_response() LOGGER.debug(f"FBan: {resp.text}") await client.send_read_acknowledge(conv.chat_id, resp) if resp.sender_id in success_toasts and any( success_toast in resp.message for success_toast in success_toasts[resp.sender_id] ): fbanned.append(user) await asyncio.sleep(0.3) else: failed.append(chat) skipped.update({str(user): failed}) continue except Exception as error: LOGGER.debug(f"FBan failed: {error}") failed.append(chat) skipped.update({str(user): failed}) if fbanned: text = f"`Successfully FBanned:`\n" text += ", ".join((f"`{user}`" for user in fbanned)) if reason: text += f"\n`Reason:` `{reason}`" e2 = await get_chat_link(entity, event.id) log_msg = text + f"\n`Chat:` {e2}" await event.answer(text, log=("fban", log_msg)) if skipped: text = "`Failed FBan requests:`\n" text += "\n".join( ( f"`{user}: [{', '.join(str(x) for x in feds)}]`" for user, feds in skipped.items() ) ) await event.answer(text, reply=True)