def __chat_settings__(chat_id, user_id): notes = sql.get_all_chat_notes(chat_id) timer = sql.get_clearnotes(chat_id) clear = timer > 0 return "There are `{}` notes in this chat.\nClear welcome is set to {}".format( len(notes), clear) + (" with timer set to {}".format(timer) if clear else ".")
def list_notes(update: Update, context: CallbackContext): bot = context.bot chat_id = update.effective_chat.id timer = sql.get_clearnotes(chat_id) chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] note_list = sql.get_all_chat_notes(chat_id) chat_name = chat.title or chat.first or chat.username msg = "*List of notes in {}:*\n" des = "You can get notes by using `/get notename`, or `#notename`.\n" delmsg = "" for note in note_list: note_name = (" • `{}`\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*List of notes in {}:*\n": delmsg = update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: delmsg = update.effective_message.reply_text( msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN) if timer != 0: sleep(int(timer)) try: delmsg.delete() update.effective_message.delete() except: pass
def list_notes(update: Update, context: CallbackContext): bot = context.bot chat_id = update.effective_chat.id timer = sql.get_clearnotes(chat_id) chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] note_list = sql.get_all_chat_notes(chat_id) msg = "*Get notes* available in here\n" msg += "by adding the *ID* or *Name*\n" msg += "after doing `#` or `/get `\n\n" msg += "*ID* *Name*\n" delmsg = msg count = 1 for note in note_list: if count < 10: note_name = "`{}`. ".format(count) + "`{}`\n".format( note.name) if count >= 10 and count < 100: note_name = "`{}`. ".format(count) + "`{}`\n".format(note.name) if count >= 100: note_name = "`{}`. ".format(count) + "`{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name count = count + 1 if delmsg == msg: delmsg = update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: delmsg = update.effective_message.reply_text( text=msg, parse_mode=ParseMode.MARKDOWN) if timer != 0: sleep(int(timer)) try: delmsg.delete() update.effective_message.delete() except: pass
def clearnotes(update: Update, context: CallbackContext): bot, args = context.bot, context.args chat_id = update.effective_chat.id message = update.effective_message if len(args) > 0 and args[0].isdigit(): timer = int(args[0]) if timer > 900 or (timer < 60 and timer != 0): message.reply_text( "Cannot set clearnotes value higher than 900 and lower than 60." ) return sql.set_clearnotes(chat_id, timer=timer) if timer != 0: message.reply_text( f"Success! Set timer to {args[0]}s and clearnotes to on!") else: message.reply_text("Disabled clearnotes!") else: timer = sql.get_clearnotes(chat_id) clear = timer > 0 message.reply_text(f"Clearnotes is currently set to {clear}" + (( (" with timer set to " + str(timer) + "s")) if clear else "!"))
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id message = update.effective_message # type: Optional[Message] timer = sql.get_clearnotes(chat_id) delmsg = "" count = 0 if notename.isnumeric(): check = sql.get_note(chat_id, notename) # If check == true, it means that notename and noteid conflicts each other if check: message.reply_text(warning.format(notename=notename)) # If check == false, it means that we need to search notename for given noteid else: note_list = sql.get_all_chat_notes(chat_id) for note in note_list: count = count + 1 if str(count) == notename: notename = note.name break # As it can be overwritten later note = sql.get_note(chat_id, notename) # Removed lower() for compatibility if note: # If we're replying to a message, reply to that message (unless it's an error) if message.reply_to_message: reply_id = message.reply_to_message.message_id else: reply_id = message.message_id if note.is_reply: if MESSAGE_DUMP: try: delmsg = bot.forward_message( chat_id=chat_id, from_chat_id=MESSAGE_DUMP, message_id=note.value, ) except BadRequest as excp: if excp.message == "Message to forward not found": message.reply_text( "This message seems to have been lost - I'll remove it " "from your notes list.") sql.rm_note(chat_id, notename) else: raise else: try: delmsg = bot.forward_message(chat_id=chat_id, from_chat_id=chat_id, message_id=note.value) except BadRequest as excp: if excp.message == "Message to forward not found": message.reply_text( "Looks like the original sender of this note has deleted " "their message - sorry! Get your bot admin to start using a " "message dump to avoid this. I'll remove this note from " "your saved notes.") sql.rm_note(chat_id, notename) else: raise else: text = note.value keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): delmsg = bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard, ) else: delmsg = ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, reply_markup=keyboard, ) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "Looks like you tried to mention someone I've never seen before. If you really " "want to mention them, forward one of their messages to me, and I'll be able " "to tag them!") elif FILE_MATCHER.match(note.value): message.reply_text( "This note was an incorrectly imported file from another bot - I can't use " "it. If you really need it, you'll have to save it again. In " "the meantime, I'll remove it from your notes list.") sql.rm_note(chat_id, notename) else: message.reply_text( "This note could not be sent, as it is incorrectly formatted. Ask in " "@bot_workshop if you can't figure out why!") LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) if timer != 0: sleep(int(timer)) try: delmsg.delete() message.delete() except: pass return if show_none: message.reply_text("This note doesn't exist")