def stretch(update: Update, context: CallbackContext): """ Stretch the vowels in a message by a random count :param update: object representing the incoming update. :param context: object containing data about the command call. """ if context.args: update.effective_message.reply_markdown( sub( r"([aeiouAEIOUaeiouAEIOU])", (r"\1" * randint(3, 10)), update.effective_message.text_markdown.replace("/stretch ", "").strip(), ) ) elif update.effective_message.reply_to_message and update.effective_message.reply_to_message.text: update.effective_message.reply_to_message.reply_markdown( sub( r"([aeiouAEIOUaeiouAEIOU])", (r"\1" * randint(3, 10)), update.effective_message.reply_to_message.text_markdown, ) ) # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) else: update.effective_message.reply_text( "If you're not gonna give me something to meme then bring some catnip atleast..." )
def vapor(update: Update, context: CallbackContext): """ Make a message look more aesthetic :param update: object representing the incoming update. :param context: object containing data about the command call. """ if not context.args and not ( update.effective_message.reply_to_message and update.effective_message.reply_to_message.text ): update.effective_message.reply_text( "If you're not gonna give me something to meme then bring some catnip atleast..." ) return # get content to vaporwave if context.args: text = " ".join(context.args) else: text = update.effective_message.reply_to_message.text # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) aesthetic_text = text.translate(dict((i, i + 0xFEE0) for i in range(0x21, 0x7F))) # make text more aesthetic # reply with more aesthetics if context.args: update.effective_message.reply_markdown(f"`{aesthetic_text}`") else: update.effective_message.reply_to_message.reply_markdown(f"`{aesthetic_text}`")
def stretch(update: Update, context: CallbackContext): """ Stretch the vowels in a message by a random count :param update: object representing the incoming update. :param context: object containing data about the command call. """ if not update.effective_message.reply_to_message: update.effective_message.reply_text( "If you're not gonna give me a message to meme, at least give me some catnip..." ) else: # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) update.effective_message.reply_to_message.reply_markdown( sub( r'([aeiouAEIOUaeiouAEIOU])', (r'\1' * randint(3, 10)), update.effective_message.reply_to_message.text_markdown, ))
def inner(update: Update, context: CallbackContext, *args, **kwargs): """ check and execute the function :param update: object representing the incoming update. :param context: object containing data about the bot_action call. :param args: anything extra :param kwargs: anything extra :return: inner function to execute """ if update.effective_message.reply_to_message: # store user info for future usage try: add_user( user_id=update.effective_message.reply_to_message. from_user.id, username=update.effective_message.reply_to_message. from_user.username, ) except: print_exc() return func(update, context, *args, **kwargs) # execute the function else: update.effective_message.reply_markdown(error_msg)
def quote(update: Update, context: CallbackContext): """ convert message into quote and reply :param update: object representing the incoming update. :param context: object containing data about the command call. """ context.bot.send_chat_action(update.effective_chat.id, "upload_photo") # tell chat that a sticker is incoming # make sticker and save on disk try: file_name = _message_to_sticker(update, context) except AttributeError: update.effective_message.reply_text( "Please reply to a message to get its quote...\nThis cat can't read your mind!" ) return # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # send generated image as sticker update.effective_message.reply_sticker(sticker=open(file_name, "rb")) # remove stored image if isfile(file_name): remove(file_name)
def get_user_from_message(message: Message) -> Tuple[int, str]: """ Get the User ID of a user from a given message from either the reply to message, or username given in content :param message: The message whose content or reply to message we need to check :return: User ID of the user """ if message.reply_to_message: # get user who made the quoted message user_id = message.reply_to_message.from_user.id username = message.reply_to_message.from_user.username add_user(user_id=user_id, username=username) # for future usage elif len(message.text.split(" ")) > 1: # get user from our users database using his username usernames = list( message.parse_entities([MessageEntity.MENTION]).values()) if usernames: user_id = get_user(username=usernames[0][1:]) if not user_id: raise UserRecordError() username = usernames[0][1:] else: raise UserError() else: raise UserError() return user_id, username
def inner(update: Update, context: CallbackContext, *args, **kwargs): """ log and execute the function :param update: object representing the incoming update. :param context: object containing data about the bot_action call. :param args: anything extra :param kwargs: anything extra :return: inner function to execute """ try: add_user(user_id=update.effective_user.id, username=update.effective_user.username) except: print_exc() if func_name: log(update, func_name, extra_text) try: return func(update, context, *args, **kwargs) except: print_exc() update.effective_message.reply_markdown( f"```{format_exc()}```\n\n" f"Show this to {mention_markdown(user_id=config.ADMIN, name='my master')} and bribe him with some " f"catnip to fix it for you...")
def pin(update: Update, context: CallbackContext): """ Pin a message in the chat :param update: object representing the incoming update. :param context: object containing data about the command call. """ # check if user has enough perms if update.effective_chat.id not in get_command_exception_chats("admin"): user = update.effective_chat.get_member(update.effective_user.id) if not user.can_pin_messages and user.status != "creator": update.effective_message.reply_markdown( "Ask your sugar daddy to give you perms required to use the method `CanPinMessages`." ) return # check if bot has perms to pin a message if (update.effective_chat.type == "supergroup" and not update.effective_chat.get_member( context.bot.id).can_pin_messages) or ( update.effective_chat.type == "channel" and not update.effective_chat.get_member( context.bot.id).can_edit_messages): update.effective_message.reply_text( "Bribe your sugar daddy with some catnip and ask him to allow me to pin messages..." ) return # check if there is a message to pin if not update.effective_message.reply_to_message: update.effective_message.reply_text( "I'm a cat, not a psychic! Reply to the message you want to pin..." ) return # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # Don't always loud pin if context.args: disable_notification = context.args[0].lower() in ("silent", "quiet") else: disable_notification = None # pin the message context.bot.pin_chat_message( update.effective_chat.id, update.effective_message.reply_to_message.message_id, disable_notification=disable_notification, )
def reorder1(update: Update, context: CallbackContext): """ First step in reordering sticker in pack - take input of sticker who's position is to be changed :param update: object representing the incoming update. :param context: object containing data about the bot_action call. :return: 0 if successful to move on to next step, else -1 (ConversationHandler.END) """ # check if there is a sticker to kang set from if not update.effective_message.reply_to_message or not update.effective_message.reply_to_message.sticker: update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack created by me") return ConversationHandler.END # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # check if the bot has perms to delete the sticker sticker = update.effective_message.reply_to_message.sticker set_name = sticker.set_name if not search(f"{context.bot.username}$", set_name): update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack created by me") return ConversationHandler.END # if sticker position is given as arg, then set position and fugg off try: context.bot.set_sticker_position_in_set( update.effective_message.reply_to_message.sticker.file_id, int(context.args[0])) update.effective_message.reply_markdown( f"I have updated [{context.bot.get_sticker_set(set_name).title}](t.me/addstickers/{set_name})!" ) return ConversationHandler.END except: pass # store sticker to reorder reorder[str(update.effective_user.id) + str(update.effective_chat.id )] = update.effective_message.reply_to_message.sticker.file_id update.effective_message.reply_markdown( "Please send the sticker that is going to be on the `left` of this sticker __after__ the reorder, or /cancel to stop" ) return 0
def purge(update: Update, context: CallbackContext): """ Delete all messages from quoted message :param update: object representing the incoming update. :param context: object containing data about the command call. """ # check if user has enough perms if update.effective_chat.type != "private" and update.effective_chat.id not in get_command_exception_chats( "admin"): user = update.effective_chat.get_member(update.effective_user.id) if not user.can_delete_messages and user.status != "creator": update.effective_message.reply_markdown( "Ask your sugar daddy to give you perms required to use the method `CanDeleteMessages`." ) return # check if bot has perms to delete a message if (update.effective_chat.type != "private" and not update.effective_chat.get_member( context.bot.id).can_delete_messages): update.effective_message.reply_text( "Bribe your sugar daddy with some catnip and ask him to allow me to delete messages..." ) return # check if start point is given if not update.effective_message.reply_to_message: update.effective_message.reply_text( "I'm a cat, not a psychic! Reply to the message you want to start deleting from..." ) return # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # delete messages for id_ in range(update.effective_message.message_id - 1, update.effective_message.reply_to_message.message_id - 1, -1): try: context.bot.delete_message(update.effective_chat.id, id_) except BadRequest: continue update.effective_message.reply_text("Just like we do it in china....")
def mock(update: Update, context: CallbackContext) -> None: """ Mock a message like spongebob, and reply :param update: object representing the incoming update. :param context: object containing data about the command call. """ if context.args: update.effective_message.reply_text(mock_text(update.effective_message.text.replace("/mock ", "").strip())) elif update.effective_message.reply_to_message and update.effective_message.reply_to_message.text: update.effective_message.reply_to_message.reply_text(mock_text(update.effective_message.reply_to_message.text)) # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) else: update.effective_message.reply_text("I don't see anything to mock here other than your ugly face...")
def zalgofy(update: Update, context: CallbackContext) -> None: """ Corrupt the way the text looks, and reply :param update: object representing the incoming update. :param context: object containing data about the command call. """ if update.effective_message.reply_to_message: # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) update.effective_message.reply_to_message.reply_text(zalgo().zalgofy( update.effective_message.reply_to_message.text)) else: update.effective_message.reply_text( "Gimme a message to zalgofy before I claw your t**s off...")
def del_sticker(update: Update, context: CallbackContext) -> None: """ Delete a sticker form one of the user's packs :param update: object representing the incoming update. :param context: object containing data about the bot_action call. """ # check if there's anything to delete if not update.effective_message.reply_to_message or not update.effective_message.reply_to_message.sticker: update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack created by me") return # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # check if the bot has perms to delete the sticker sticker = update.effective_message.reply_to_message.sticker set_name = sticker.set_name if not search(f"{context.bot.username}$", set_name): update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack created by me") return # get sticker set info (for better replies) set_title = context.bot.get_sticker_set(set_name).title # delete the sticker try: context.bot.delete_sticker_from_set(sticker.file_id) except BadRequest: update.effective_message.reply_text( "Telegram seems to be high on catnip at the moment, try again in a while!" ) update.effective_message.reply_markdown( f"Deleted that sticker from [{set_title}](t.me/addstickers/{set_name})." )
def get_sticker(update: Update, context: CallbackContext) -> None: """ Reply with the PNG image as a document for a given sticker :param update: object representing the incoming update. :param context: object containing data about the bot_action call. """ rep_msg = update.effective_message.reply_to_message chat_id = update.effective_chat.id if rep_msg and rep_msg.sticker: # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) # check if sticker is animated, fugg off if it is if rep_msg.sticker.is_animated: update.effective_message.reply_text( f"Sorry, cannyot get animated stickers for now {emojize(':crying_cat_face:', use_aliases=True)} I can meow tho..." ) else: # download file file_id = rep_msg.sticker.file_id new_file = context.bot.get_file(file_id) new_file.download(f'{file_id}.png') # send picture context.bot.send_document(chat_id, document=open(f'{file_id}.png', 'rb')) # delete locally created image remove(f'{file_id}.png') else: update.effective_message.reply_text( "Please reply to a sticker for me to upload its PNG.")
def sticker_id(update: Update, context: CallbackContext) -> None: """ Reply with the file ID of a given sticker :param update: object representing the incoming update. :param context: object containing data about the bot_action call. """ rep_msg = update.effective_message.reply_to_message if rep_msg and rep_msg.sticker: # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) update.effective_message.reply_markdown( "Sticker ID:\n```" + escape_markdown(rep_msg.sticker.file_id) + "```") else: update.effective_message.reply_text( "Please reply to a sticker to get its ID.")
def inner(update: Update, context: CallbackContext, *args, **kwargs): """ log and execute the function :param update: object representing the incoming update. :param context: object containing data about the bot_action call. :param args: anything extra :param kwargs: anything extra :return: inner function to execute """ try: add_user(user_id=update.effective_user.id, username=update.effective_user.username) except: print_exc() if func_name: log(update, func_name, extra_text) try: return func(update, context, *args, **kwargs) except BadRequest as e: if e.message == "Message is too long": update.effective_message.reply_text( emojize( "I tried to send a message so long that my tongue got tired :sad_but_relieved_face: " "This is not gonna work, let's try something else..." )) else: print_exc() update.effective_message.reply_markdown( f"```{format_exc()}```\n\n" f"Show this to {mention_markdown(user_id=config.ADMIN, name='my master')} and bribe him with " "some catnip to fix it for you...") except: print_exc() update.effective_message.reply_markdown( f"```{format_exc()}```\n\n" f"Show this to {mention_markdown(user_id=config.ADMIN, name='my master')} and bribe him with some " "catnip to fix it for you...")
def owo(update: Update, context: CallbackContext) -> None: """ Change a message to look like it was said by a moe weeb :param update: object representing the incoming update. :param context: object containing data about the command call. """ def transform(text: str): """ Transform message text :param text: The text in the message :return: owo-fied text """ # list of all kaomojis to use in owo kaomoji = [ r"`(・\`ω´・)`", "`;;w;;`", "`owo`", "`UwU`", "`>w<`", "`^w^`", "`( ^ _ ^)∠☆`", "`(ô_ô)`", "`~:o`", "`;____;`", "`(*^*)`", "`(>_`", "`(♥_♥)`", "`*(^O^)*`", "`((+_+))`", ] # replace certain characters and add a kaomoji reply_text = sub(r"[rl]", "w", text) reply_text = sub(r"[rl]", "w", reply_text) reply_text = sub(r"[RL]", "W", reply_text) reply_text = sub(r"[RL]", "W", reply_text) reply_text = sub(r"n([aeiouaeiou])", r"ny\1", reply_text) reply_text = sub(r"n([aeiou])", r"ny\1", reply_text) reply_text = sub(r"N([aeiouAEIOU])", r"Ny\1", reply_text) reply_text = sub(r"N([aeiouAEIOU])", r"Ny\1", reply_text) reply_text = sub(r"!+", " " + choice(kaomoji), reply_text) reply_text = sub(r"!+", " " + choice(kaomoji), reply_text) reply_text = reply_text.replace("ove", "uv") reply_text = reply_text.replace("ove", "uv") reply_text += " " + choice(kaomoji) return reply_text if context.args: try: update.effective_message.reply_markdown_v2( transform(update.effective_message.text_markdown_v2.replace("/owo ", "").strip()) ) except BadRequest as e: print(e) # in case we messed up markdown while replacing characters and adding kaomoji update.effective_message.reply_text( "Gommenye, I over-owo'd myself.... please try again. " "If it still doesn't work, then this must be the language of god's you're trying to translate...." ) elif update.effective_message.reply_to_message and update.effective_message.reply_to_message.text: try: update.effective_message.reply_to_message.reply_markdown( transform(update.effective_message.reply_to_message.text_markdown) ) # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) except BadRequest as e: print(e) # in case we messed up markdown while replacing characters and adding kaomoji update.effective_message.reply_text( "Gommenye, I over-owo'd myself.... please try again. " "If it still doesn't work, then this must be the language of god's you're trying to translate...." ) else: update.effective_message.reply_text( "Gommenye, I don't nyaruhodo what normie text you want to henshin into the moe weeb dialect" )
def migrate(update: Update, context: CallbackContext) -> None: """ Migrate all stickers from a given pack into user's pack(s) :param update: object representing the incoming update. :param context: object containing data about the bot_action call. """ # check if there is a sticker to kang set from if not update.effective_message.reply_to_message or not update.effective_message.reply_to_message.sticker: update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack you want to migrate!" ) return # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # get original set name og_set_name = update.effective_message.reply_to_message.sticker.set_name if og_set_name is None: update.effective_message.reply_text( "Please reply to a sticker that belongs to a pack you want to migrate!" ) return # check if the sticker set already belongs to this bot if search(f"{context.bot.username}$", og_set_name): update.effective_message.reply_markdown( f"This pack already belongs to `{context.bot.first_name}`...") return update.effective_message.reply_text( "Please be patient, this little kitty's paws can only kang so fast...." ) # get original set data og_stickers_set = context.bot.get_sticker_set(og_set_name) og_set_title = og_stickers_set.title stickers = og_stickers_set.stickers is_animated = stickers[0].is_animated # get the pack to migrate the stickers into packs = _get_packs(update.effective_user, context.bot, is_animated) if packs: pack_num, pack = packs[-1] pack_name = pack.name else: # default pack number and name of the first pack pack_num = 0 pack_name = "a" + str(update.effective_user.id) if is_animated: pack_name += "_animated" pack_name += "_by_" + update.effective_user.username pack_title = f"{update.effective_user.id}'s " if is_animated: pack_title += "animated " pack_title += "kang pack" # name of the file in which we locally store sticker rendum_str = uuid4() file = (f"{update.effective_user.id}_{rendum_str}_migrate_sticker.tgs" if is_animated else f"{update.effective_user.id}_{rendum_str}_migrate_sticker.png") try: sticker_pack = context.bot.get_sticker_set(pack_name) except BadRequest: # download sticker context.bot.get_file(stickers[0].file_id).download(file) # make pack try: _make_pack( None, update.effective_user, open(file, 'rb'), stickers[0].emoji, context.bot, pack_name, pack_num, is_animated, ) # we don't want to send a message, hence passed msg as None to _make_pack # this leads to an AttributeError being raised except AttributeError: pass stickers = stickers[ 1:] # because the first sticker is already in the new pack now sticker_pack = context.bot.get_sticker_set(pack_name) appended_packs = [sticker_pack ] # list of packs the stickers were migrated into max_stickers = 50 if is_animated else 120 for sticker in stickers: # download sticker context.bot.get_file(sticker.file_id).download(file) # if current pack can still fit in more stickers if len(sticker_pack.stickers) < max_stickers: try: if is_animated: context.bot.add_sticker_to_set( user_id=update.effective_user.id, name=pack_name, tgs_sticker=open(file, 'rb'), emojis=sticker.emoji, ) else: context.bot.add_sticker_to_set( user_id=update.effective_user.id, name=pack_name, png_sticker=open(file, 'rb'), emojis=sticker.emoji, ) except BadRequest: # make new pack try: _make_pack( None, update.effective_user, open(file, 'rb'), sticker.emoji, context.bot, pack_name, pack_num, is_animated, ) # we don't want to send a message, hence passed msg as None to _make_pack # this leads to an AttributeError being raised except AttributeError: pass # if current pack is full else: # new pack info pack_num += 1 pack_name = "a" + str(pack_num) + "_" + str( update.effective_user.id) if is_animated: pack_name += "_animated" pack_name += "_by_" + context.bot.username # make new pack try: _make_pack( None, update.effective_user, open(file, 'rb'), sticker.emoji, context.bot, pack_name, pack_num, is_animated, ) # we don't want to send a message, hence passed msg as None to _make_pack # this leads to an AttributeError being raised except AttributeError: pass sticker_pack = context.bot.get_sticker_set(pack_name) appended_packs.append(sticker_pack) # send success reply to the user reply = f"Done! Pack [{og_set_title}](t.me/addstickers/{og_set_name}) was migrated into :-" for pack in appended_packs: reply += f"\n[{pack.title}](t.me/addstickers/{pack.name})" update.effective_message.reply_markdown(reply) # don't want rendum files on server if os.path.isfile(file): os.remove(file)
def kang(update: Update, context: CallbackContext) -> None: """ Add a sticker to user's pack :param update: object representing the incoming update. :param context: object containing data about the bot_action call. """ # check for exception, but skip exception if user is a superuser if update.effective_user.id not in config.SUPERUSERS and update.effective_chat.id in get_command_exception_chats( "kang"): return msg = update.effective_message user = update.effective_user bot = context.bot # get sticker pack of user try: is_animated = msg.reply_to_message.sticker.is_animated except AttributeError: is_animated = False packs = _get_packs(user, bot, is_animated) if packs: pack_num, pack = packs[-1] pack_name = pack.name pack_title = pack.title else: # default pack number and name of the first pack pack_num = 0 pack_name = "a" + str(user.id) if is_animated: pack_name += "_animated" pack_name += "_by_" + bot.username pack_title = f"{user.id}'s " if is_animated: pack_title += "animated " pack_title += "kang pack" # file name to download sticker file as rendum_str = uuid4() kang_sticker = f"{user.id}_{rendum_str}_kang_sticker." + "tgs" if is_animated else "png" # If user has replied to some message if is_animated: # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) # download sticker sticker = msg.reply_to_message.sticker context.bot.get_file(sticker.file_id).download(kang_sticker) # add to pack try: bot.add_sticker_to_set(user_id=user.id, name=pack_name, tgs_sticker=open(kang_sticker, 'rb'), emojis=sticker.emoji) msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is: {sticker.emoji}") except TelegramError as e: if e.message == "Stickerset_invalid": _make_pack(msg, user, open(kang_sticker, 'rb'), sticker.emoji, bot, pack_name, pack_num, is_animated) elif e.message == "Invalid sticker emojis": msg.reply_text("Invalid emoji(s).") elif e.message == "Stickers_too_much": msg.reply_text( "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc." ) elif e.message == "Internal Server Error: sticker set not found (500)": msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is : {sticker.emoji}") elif msg.reply_to_message: # future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) # get sticker file if msg.reply_to_message.sticker: file_id = msg.reply_to_message.sticker.file_id elif msg.reply_to_message.photo: file_id = msg.reply_to_message.photo[-1].file_id elif msg.reply_to_message.document: file_id = msg.reply_to_message.document.file_id else: msg.reply_text( "Nyet, can't kang that. Even if you bribe me with catnip.") return # download sticker file bot.get_file(file_id).download(kang_sticker) # get emoji(s) for sticker if context.args: sticker_emoji = str(context.args[0]) elif msg.reply_to_message.sticker and msg.reply_to_message.sticker.emoji: sticker_emoji = msg.reply_to_message.sticker.emoji else: sticker_emoji = "🤔" # resize image im = _resize(kang_sticker) if not msg.reply_to_message.sticker: im.save(kang_sticker, "PNG") # add to sticker pack try: bot.add_sticker_to_set(user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, 'rb'), emojis=sticker_emoji) msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is: {sticker_emoji}") except OSError: msg.reply_text( "I can only kang images.\nAnd catnip. If I'm feeling like it.") return except TelegramError as e: if e.message == "Stickerset_invalid": _make_pack(msg, user, open(kang_sticker, 'rb'), sticker_emoji, bot, pack_name, pack_num) elif e.message == "Sticker_png_dimensions": im.save(kang_sticker, "PNG") bot.add_sticker_to_set(user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, 'rb'), emojis=sticker_emoji) msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is: {sticker_emoji}") elif e.message == "Invalid sticker emojis": msg.reply_text("Invalid emoji(s).") elif e.message == "Stickers_too_much": msg.reply_text( "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc." ) elif e.message == "Internal Server Error: sticker set not found (500)": msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is : {sticker_emoji}") elif context.args: # get the emoji to use as sticker and the emojis to set to said sticker png_sticker = context.args[0] try: sticker_emoji = context.args[1] except IndexError: sticker_emoji = "🤔" # fetch the image for the emoji urlretrieve(png_sticker, kang_sticker) im = _resize(kang_sticker) im.save(kang_sticker, "PNG") # add to pack try: msg.reply_photo(photo=open(kang_sticker, 'rb')) bot.add_sticker_to_set(user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, 'rb'), emojis=sticker_emoji) msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is: {sticker_emoji}") except OSError: msg.reply_text( "I can only kang images.\nAnd catnip. If I'm feeling like it.") return except TelegramError as e: if e.message == "Stickerset_invalid": _make_pack(msg, user, open(kang_sticker, 'rb'), sticker_emoji, bot, pack_name, pack_num) elif e.message == "Sticker_png_dimensions": im.save(kang_sticker, "PNG") bot.add_sticker_to_set(user_id=user.id, name=pack_name, png_sticker=open(kang_sticker, 'rb'), emojis=sticker_emoji) msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is : {sticker_emoji}") elif e.message == "Invalid sticker emojis": msg.reply_text("Invalid emoji(s).") elif e.message == "Stickers_too_much": msg.reply_text( "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc." ) elif e.message == "Internal Server Error: sticker set not found (500)": msg.reply_markdown( f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})" + f"\nEmoji is : {sticker_emoji}") else: msg.reply_markdown("Please reply to a sticker, or image to kang it!") # delete stray files if os.path.isfile(kang_sticker): os.remove(kang_sticker)
def owo(update: Update, context: CallbackContext) -> None: """ Change a message to look like it was said by a moe weeb :param update: object representing the incoming update. :param context: object containing data about the command call. """ if not update.effective_message.reply_to_message: update.effective_message.reply_text( "Gommenye, I don't nyaruhodo what normie text you want to henshin into the moe weeb dialect" ) return # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) # list of all kaomojis to use in owo kaomoji = [ escape_markdown("```\n(・`ω´・)\n```"), escape_markdown("```\n;;w;;\n```"), escape_markdown("```\nowo\n```"), escape_markdown("```\nUwU\n```"), escape_markdown("```\n>w<\n```"), escape_markdown("```\n^w^\n```"), escape_markdown("```\n" + r"\(^o\) (/o^)/" + "\n```"), escape_markdown("```\n( ^ _ ^)∠☆\n```"), escape_markdown("```\n(ô_ô)\n```"), escape_markdown("```\n~:o\n```"), escape_markdown("```\n;____;\n```"), escape_markdown("```\n(*^*)\n```"), escape_markdown("```\n(>_\n```"), escape_markdown("```\n(♥_♥)\n```"), escape_markdown("```\n*(^O^)*\n```"), escape_markdown("```\n((+_+))\n```"), ] try: # replace certain characters and add a kaomoji reply_text = sub( r'[rl]', "w", update.effective_message.reply_to_message.text_markdown) reply_text = sub(r'[rl]', "w", reply_text) reply_text = sub(r'[RL]', 'W', reply_text) reply_text = sub(r'[RL]', 'W', reply_text) reply_text = sub(r'n([aeiouaeiou])', r'ny\1', reply_text) reply_text = sub(r'n([aeiou])', r'ny\1', reply_text) reply_text = sub(r'N([aeiouAEIOU])', r'Ny\1', reply_text) reply_text = sub(r'N([aeiouAEIOU])', r'Ny\1', reply_text) reply_text = sub(r'!+', ' ' + choice(kaomoji), reply_text) reply_text = sub(r'!+', ' ' + choice(kaomoji), reply_text) reply_text = reply_text.replace("ove", "uv") reply_text = reply_text.replace("ove", "uv") reply_text += "\n" + choice(kaomoji) # reply to the original message update.effective_message.reply_to_message.reply_markdown(reply_text) except BadRequest: # in case we messed up markdown while replacing characters and adding kaomoji update.effective_message.reply_text( "Gommenye, I over-owo'd myself.... please try again. " "If it still doesn't work, then this must be the language of god's you're trying to translate...." )
def add_note_in_chat(update: Update, context: CallbackContext): """ Add a note in the chat :param update: object representing the incoming update. :param context: object containing data about the command call. """ # check exception if update.effective_chat.id in get_command_exception_chats("notes"): return # for ease of reference msg = update.effective_message # get name and content from the message try: name, content = msg.text_markdown.split(None, 2)[1:] except ValueError: try: name = context.args[0] content = None except IndexError: msg.reply_markdown("No name, No content....\n\nYou could've at least come with some catnip\n`._.`") return # set kwargs to be passed to add_note function kwargs = {"chat": update.effective_chat.id, "name": name.replace(r"\_", "_").replace(r"\*", "*")} # add content and content type to kwargs if content is not None: kwargs["content"] = content kwargs["content_type"] = "text" elif msg.reply_to_message: # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user.username, ) if msg.reply_to_message.text_markdown: kwargs["content"] = msg.reply_to_message.text_markdown kwargs["content_type"] = "text" elif msg.reply_to_message.sticker: kwargs["content"] = msg.reply_to_message.sticker.file_id kwargs["content_type"] = "sticker" elif msg.reply_to_message.document: kwargs["content"] = msg.reply_to_message.document.file_id kwargs["content_type"] = "document" elif msg.reply_to_message.photo: kwargs["content"] = msg.reply_to_message.photo[-1].file_id kwargs["content_type"] = "photo" elif msg.reply_to_message.audio: kwargs["content"] = msg.reply_to_message.audio.file_id kwargs["content_type"] = "audio" elif msg.reply_to_message.voice: kwargs["content"] = msg.reply_to_message.voice.file_id kwargs["content_type"] = "voice" elif msg.reply_to_message.video: kwargs["content"] = msg.reply_to_message.video.file_id kwargs["content_type"] = "video" else: msg.reply_markdown("This cat isn't a random reply generator, baka! Give some content to reply with......") return else: msg.reply_markdown("This cat isn't a random reply generator, baka! Give some content to reply with......") return # save note and reply to user msg.reply_markdown(add_note(**kwargs))
def add_filter_handler(update: Update, context: CallbackContext): """ Add a filter in a chat :param update: object representing the incoming update. :param context: object containing data about the command call. """ # check for exception if update.effective_chat.id in get_command_exception_chats("filter"): return # for ease of reference msg = update.effective_message # get trigger and content from the message try: trigger, content = msg.text_markdown.split(None, 2)[1:] except ValueError: try: trigger = msg.text.split()[1] content = None except IndexError: msg.reply_markdown( "No trigger, No content....\n\nYou could've at least come with some catnip\n`._.`" ) return trigger = trigger.replace(r"\_", "_").replace(r"\*", "*") # set kwargs to be passed to add_filter function kwargs = {'chat': update.effective_chat.id, 'trigger': trigger} # add content and filter type to kwargs if content is not None: kwargs['content'] = content kwargs['filter_type'] = "text" elif msg.reply_to_message: # for future usage add_user( user_id=update.effective_message.reply_to_message.from_user.id, username=update.effective_message.reply_to_message.from_user. username, ) if msg.reply_to_message.text_markdown: kwargs['content'] = msg.reply_to_message.text_markdown kwargs['filter_type'] = "text" elif msg.reply_to_message.sticker: kwargs['content'] = msg.reply_to_message.sticker.file_id kwargs['filter_type'] = "sticker" elif msg.reply_to_message.document: kwargs['content'] = msg.reply_to_message.document.file_id kwargs['filter_type'] = "document" elif msg.reply_to_message.photo: kwargs['content'] = msg.reply_to_message.photo[-1].file_id kwargs['filter_type'] = "photo" elif msg.reply_to_message.audio: kwargs['content'] = msg.reply_to_message.audio.file_id kwargs['filter_type'] = "audio" elif msg.reply_to_message.voice: kwargs['content'] = msg.reply_to_message.voice.file_id kwargs['filter_type'] = "voice" elif msg.reply_to_message.video: kwargs['content'] = msg.reply_to_message.video.file_id kwargs['filter_type'] = "video" else: msg.reply_markdown( "This cat isn't a random reply generator, baka! Give some content to reply with......" ) return else: msg.reply_markdown( "This cat isn't a random reply generator, baka! Give some content to reply with......" ) return # add filter in DB msg.reply_markdown(add_filter(**kwargs))