def handle_private_text(bot, update, session, chat, user): """Read all messages and handle the tagging of stickers.""" # Handle the name of a sticker set to initialize full sticker set tagging if chat.tag_mode in [TagMode.sticker_set.value, TagMode.random.value]: # Try to tag the sticker. Return early if it didn't work. tag_sticker( session, update.message.text, chat.current_sticker, user, tg_chat=update.message.chat, chat=chat, message_id=update.message.message_id, ) session.commit() handle_next(session, bot, chat, update.message.chat, user) elif chat.tag_mode == TagMode.single_sticker.value: tag_sticker( session, update.message.text, chat.current_sticker, user, tg_chat=update.message.chat, chat=chat, message_id=update.message.message_id, ) chat.cancel(bot) return "Sticker tags adjusted."
def handle_tag_next(session, context): """Send the next sticker for tagging.""" chat = context.chat current_sticker = chat.current_sticker handle_next(session, context.bot, chat, context.tg_chat, context.user) if chat.current_sticker is not None: keyboard = get_fix_sticker_tags_keyboard(current_sticker.id) context.query.message.edit_reply_markup(reply_markup=keyboard)
def tag_random(session, context): """Initialize tagging of a whole set.""" chat = context.chat chat.cancel(context.bot) chat.tag_mode = TagMode.random.value handle_next(session, context.bot, chat, context.query.message.chat, context.user) return
def replace_single(bot, update, session, chat, user): """Tag the last sticker send to this chat.""" # The replace command has been replied to another message # If it's a sticker, replace the tags of this specific sticker if (update.message.reply_to_message is not None and update.message.reply_to_message.sticker is not None): tg_sticker = update.message.reply_to_message.sticker sticker = session.query(Sticker).get(tg_sticker.file_unique_id) if sticker is None: return "This sticker has not yet been added." is_single_sticker = True # The replace command has been normally called elif chat.current_sticker: sticker = chat.current_sticker is_single_sticker = chat.tag_mode not in [ TagMode.sticker_set.value, TagMode.random.value, ] else: return "No sticker for replacement selected" # Remove the /replace command text = update.message.text[8:] if text.strip() == "": return 'You need to add some tags to the /replace command. E.g. "/replace meme prequel obi wan"' tag_sticker( session, text, sticker, user, tg_chat=update.message.chat, chat=chat, message_id=update.message.message_id, single_sticker=is_single_sticker, replace=True, ) if not is_single_sticker: handle_next(session, bot, chat, update.message.chat, user) else: return "Sticker tags replaced."