def clearall_btn(update: Update, context: CallbackContext): query = update.callback_query chat = update.effective_chat message = update.effective_message member = chat.get_member(query.from_user.id) if query.data == "notes_rmall": if member.status == "creator" or query.from_user.id in SUDO_USERS: note_list = sql.get_all_chat_notes(chat.id) try: for notename in note_list: note = notename.name.lower() sql.rm_note(chat.id, note) message.edit_text("Deleted all notes.") except BadRequest: return if member.status == "administrator": query.answer("Only owner of the chat can do this.") if member.status == "member": query.answer("You need to be admin to do this.") elif query.data == "notes_cancel": if member.status == "creator" or query.from_user.id in SUDO_USERS: message.edit_text("Clearing of all notes has been cancelled.") return if member.status == "administrator": query.answer("Only owner of the chat can do this.") if member.status == "member": query.answer("You need to be admin to do this.")
def rmbutton(bot: Bot, update: Update): query = update.callback_query userid = update.effective_user.id match = query.data.split("_")[1] chat = update.effective_chat owner = chat.get_member(userid).status if match == "cancel" and owner == "creator": return query.message.edit_text("Cancelled deletion of notes.") elif match == "true" and owner == "creator": allnotes = sql.get_all_chat_notes(chat.id) count = 0 notelist = [] for notename in allnotes: count += 1 note = notename.name.lower() notelist.append(note) for i in notelist: sql.rm_note(chat.id, i) query.message.edit_text( f"Successfully cleaned {count} notes in {chat.title}.")
def clear(update, context): args = context.args chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message conn = connected(context.bot, update, chat, user.id) note_name, text, data_type, content, buttons = get_note_type(msg) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0].lower() if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Successfully deleted '`{note_name}`' from {chat_name}!".format( note_name=note_name, chat_name=chat_name ), parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "There is no such notes saved in {chat_name}!".format( chat_name=chat_name ) )
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("هشتگتو ورداشتم عجقم😎.") else: update.effective_message.reply_text("این هشتگ تو دیتابیس من نیس!")
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Successfully removed note.") else: update.effective_message.reply_text("That's not a note in my database!")
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("노트를 성공적으로 제거했어요.") else: update.effective_message.reply_text("그 노트는 제 데이터베이스에 있는 메모가 아니에요!")
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Not başarıyla kaldırıldı.") else: update.effective_message.reply_text( "Benim veritabanımda böyle bir not yok!")
def clear(update: Update, context: CallbackContext): args = context.args chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("노트를 성공적으로 제거했어요.") else: update.effective_message.reply_text("그 노트는 제 데이터베이스에 있는 메모가 아니에요!")
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Catatan berhasil dihapus.") else: update.effective_message.reply_text( "Itu bukan catatan di database saya!")
def clear(update: Update, context: CallbackContext): args = context.args chat_id = update.effective_chat.id if len(args) >= 1: notename = args[0].lower() if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Successfully removed note.") else: update.effective_message.reply_text("That's not a note in my database!")
def clear(update, context): chat_id = update.effective_chat.id args = context.args if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text( tld(chat_id, "Successfully removed note.")) else: update.effective_message.reply_text( tld(chat_id, "That's not a note in my database!"))
def clear(bot: Bot, update: Update, args: List[str]): chat_id = update.effective_chat.id msg = update.effective_message chat = update.effective_chat chat_name = chat.title or chat.first or chat.username note_name, text, data_type, content, buttons = get_note_type(msg) if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Note for '`{note_name}`' has been deleted!".format(note_name=note_name), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Unfortunately, There is no such notes saved on {chat_name}!".format(chat_name=chat_name))
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if conn != False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id chat_name = "local notes" if chat.type == "private" else chat.title if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Successfully removed note.") else: update.effective_message.reply_text( "That's not a note in my database!")
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("Notka usunięta pomyślnie.") else: update.effective_message.reply_text( "To nie jest notka z mojej bazy danych!")
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("catatan berhasil dihapus.") else: update.effective_message.reply_text( "itu bukan catatan di database saya!")
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text("සටහන සාර්ථකව ඉවත් කරන ලදි.") else: update.effective_message.reply_text( "එය මගේ දත්ත ගබඩාවේ සටහනක් නොවේ!")
def clear(update: Update, context: CallbackContext): bot, args = context.bot, context.args chat_id = update.effective_chat.id chat = update.effective_chat chat_name = chat.title or chat.first or chat.username count = 0 if len(args) >= 1: notename = args[0] else: update.effective_message.reply_text("I can't clear empty notes!") return if notename.isnumeric(): check = sql.get_note(chat_id, notename) # If check == true, it means that notename and noteid conflicts each other if check: update.effective_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 if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Note for '`{}`' has been deleted!".format(notename), parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "Unfortunately, There is no such notes saved on {chat_name}!". format(chat_name=chat_name))
def clear(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0] if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Note succesfully removed from *{}*.".format(chat_name), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "That's not a note in my database!")
def get(update, context, notename, show_none=True, no_format=False): bot = context.bot chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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 JOIN_LOGGER: try: bot.forward_message( chat_id=chat_id, from_chat_id=JOIN_LOGGER, 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: 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: VALID_NOTE_FORMATTERS = [ "first", "last", "fullname", "username", "id", "chatname", "mention", ] valid_format = escape_invalid_curly_brackets( note.value, VALID_NOTE_FORMATTERS ) if valid_format: text = valid_format.format( first=escape_markdown(message.from_user.first_name), last=escape_markdown( message.from_user.last_name or message.from_user.first_name ), fullname=escape_markdown( " ".join( [message.from_user.first_name, message.from_user.last_name] if message.from_user.last_name else [message.from_user.first_name] ) ), username="******" + message.from_user.username if message.from_user.username else mention_markdown( message.from_user.id, message.from_user.first_name ), mention=mention_markdown( message.from_user.id, message.from_user.first_name ), chatname=escape_markdown( message.chat.title if message.chat.type != "private" else message.from_user.first_name ), id=message.from_user.id, ) else: text = "" 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): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, reply_markup=keyboard, ) else: if ENUM_FUNC_MAP[note.msgtype] == dispatcher.bot.send_sticker: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, reply_to_message_id=reply_id, reply_markup=keyboard, ) else: 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 " f"@YorkTownEagleUnion if you can't figure out why!" ) log.exception( "Could not parse message #%s in chat %s", notename, str(chat_id) ) log.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("This note doesn't exist")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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( "Wygląda na to że ta wiadomość się zagubiła - Usunę ją " "z twojej listy notek.") sql.rm_note(chat_id, notename) else: raise else: try: 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( "Wygląda na to że oryginalny wysyłający usunął swoją " "wiadomość - przepraszam! Poproś administratora bota aby zasczął " "tworzyć zrzuty wiadomości żeby uniknąć takich rzeczy. " "Usunę tą notkę z twoich zapisanych notek.") sql.rm_note(chat_id, notename) else: raise else: text = note.value keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) should_preview_disabled = True if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) if "telegra.ph" in text or "youtu.be" in text: should_preview_disabled = False keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "Wygląda na to że próbujesz wspomnieć o futrzaku którego nigdy nie widziałem wcześniej. Jeżeli serio " "go wspomnieć, prześlij mi jedną wiadomość od tego futrzaka do mnie a ja będę mógł wtedy " "go otagować!") elif FILE_MATCHER.match(note.value): message.reply_text( "Ta notka jest niepoprawna zimportowana od innego bota - Nie mogę " "użyć jej. Jeżeli serio chcesz ją mieć, musisz ją zapisać ponownie. Przez " "ten czas usunę ją z listy twoich notek.") sql.rm_note(chat_id, notename) else: message.reply_text( "Nie można wysłać tej notki, ponieważ jest niepoprawnie sformatowana. Spytaj " "na @MarieSupport jeśli nie możesz zrozumieć dlaczego!" ) LOGGER.exception( "Nie można sparsować notki #%s w czacie %s", notename, str(chat_id)) LOGGER.warning("Wiadomość była: %s", str(note.value)) return elif show_none: message.reply_text("Ta notka nie istnieje")
def get(bot, update, notename, show_none=True): chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] if note: # If not is replying to a message, reply to that message (unless its an error) if message.reply_to_message: reply_text = message.reply_to_message.reply_text else: reply_text = message.reply_text if note.is_reply: if MESSAGE_DUMP: try: 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: 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: keyb = [] if note.has_buttons: buttons = sql.get_buttons(chat_id, notename) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: reply_text(note.value, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, 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 is not formatted correctly. Could not send. Contact @{} if you " "can't figure out why!".format(OWNER_USERNAME)) LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("This note doesn't exist")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: bot.forward_message(chat_id=chat_id, from_chat_id=MESSAGE_DUMP, message_id=note.value) except BadRequest as excp: if excp.message == "ඉදිරියට යැවීමේ පණිවිඩය හමු නොවීය": message.reply_text( "Tඔහුගේ පණිවිඩය නැති වී ඇති බව පෙනේ - මම එය ඉවත් කරමි" "ඔබගේ සටහන් ලැයිස්තුවෙන්.") sql.rm_note(chat_id, notename) else: raise else: try: bot.forward_message(chat_id=chat_id, from_chat_id=chat_id, message_id=note.value) except BadRequest as excp: if excp.message == "ඉදිරියට යැවීමේ පණිවිඩය හමු නොවීය": message.reply_text( "මෙම සටහනේ මුල් යවන්නා මකා දමා ඇති බව පෙනේ" "ඔවුන්ගේ පණිවිඩය - සමාවෙන්න! භාවිතා කිරීම ආරම්භ කිරීමට ඔබේ බොට් පරිපාලක ලබා ගන්න " "මෙය වළක්වා ගැනීම සඳහා පණිවිඩ ඩම්ප් කරන්න. මම මෙම සටහන ඉවත් කරමි " "ඔබගේ සුරකින ලද සටහන්.") sql.rm_note(chat_id, notename) else: raise else: text = note.value keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) should_preview_disabled = True if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) if "telegra.ph" in text or "youtu.be" in text: should_preview_disabled = False keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) except BadRequest as excp: if excp.message == "ආයතනය_සඳහන්_කිරීම_පරිශීලකයා_අවලංගුය": message.reply_text( "මම මීට පෙර කවදාවත් දැක නැති කෙනෙකු ගැන සඳහන් කිරීමට ඔබ උත්සාහ කළ බවක් පෙනේ. ඔබ ඇත්තටම නම් " "ඒවා සඳහන් කිරීමට අවශ්යයි, ඔවුන්ගේ පණිවිඩයක් මා වෙත යොමු කරන්න, එවිට මට හැකි වනු ඇත" "ඒවා ටැග් කිරීමට!") elif FILE_MATCHER.match(note.value): message.reply_text( "මෙම සටහන වෙනත් බොට් එකකින් වැරදි ලෙස ආනයනය කරන ලද ගොනුවකි - මට භාවිතා කළ නොහැක " "එය. ඔබට එය සැබවින්ම අවශ්ය නම්, ඔබට එය නැවත සුරැකීමට සිදුවේ. තුළ " "මේ අතර, මම එය ඔබගේ සටහන් ලැයිස්තුවෙන් ඉවත් කරමි.") sql.rm_note(chat_id, notename) else: message.reply_text( "මෙම සටහන වැරදි ලෙස සංයුති කර ඇති බැවින් එය යැවිය නොහැක. ඇතුලට අහන්න" "@cyberwordk ඇයි කියලා හිතාගන්න බැරි නම්!") LOGGER.exception( "පණිවිඩය විග්රහ කිරීමට නොහැකි විය #%s කතාබස් කරමින් %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("මෙම සටහන නොපවතී")
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")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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( "يبدو أن هذه الرسالة قد فقدت - سأزيله" "من قائمة الملاحظات الخاصة بك.") sql.rm_note(chat_id, notename) else: raise else: try: 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( "يبدو وكأنه المرسل الأصلي لهذه المذكرة حذف" "رسالتهم - آسف! احصل على مشرف بوتك للبدء في استخدام" "تفريغ الرسالة لتجنب ذلك. سأزيل هذه المذكرة من" "ملاحظات المحفوظة الخاصة بك.") sql.rm_note(chat_id, notename) else: raise else: text = note.value keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) should_preview_disabled = True if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) if "telegra.ph" in text or "youtu.be" in text: should_preview_disabled = False keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "يبدو أنك حاولت ذكر شخص ما لم أره من قبل. ان كنت حقا" "هل تريد أن تذكرها، إلى الأمام إحدى رسائلها لي، وسأكون قادرا" "لعلامةهم!") elif FILE_MATCHER.match(note.value): message.reply_text( "كانت هذه الملاحظة ملف مستورد بشكل غير صحيح من بوت آخر - لا يمكنني استخدامه" "ذلك. إذا كنت في حاجة فعلا، فسيتعين عليك حفظها مرة أخرى. في" "في هذه الأثناء، سأزيله من قائمة الملاحظات الخاصة بك.") sql.rm_note(chat_id, notename) else: message.reply_text( "لا يمكن إرسال هذه الملاحظة، حيث يتم تنسيقها بشكل غير صحيح. اسأل في" "@MarieSupport إذا كنت لا تستطيع معرفة السبب!") LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("هذه المذكرة غير موجودة")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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( "پیامی که نشونم داده بودی رو گم کردم😶 " "از لیست پاکش میکنم.") sql.rm_note(chat_id, notename) else: raise else: try: 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( "عه فک کنم کسی که صاحب فایل بود دیلیت زده " "لطفا دوباره از اول" "برام تعریف کن این قسمتو . تا اون موقع " "من این بخشو از لیست پاک میکنم") 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): bot.send_message(chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype](chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "اومم بنظر میاد میخوای یه شخصو بهم معرفی کنی که من تا حالا ندیدمش " "اگه واقعا لازمه که اون شخصو من اضافه کنم . اول یه پیام ازش فوروارد کن " "تا بتونم تگش کنم!") elif FILE_MATCHER.match(note.value): message.reply_text( "اومم ما رباتا نمیتونیم از اموال هم اسکی بریم . زشته! " "اگه واقعا نیازه . یا از فور پیشرفته استفاده کن یا دوباره برام " "آپلود کن که لو نریم🤪.") sql.rm_note(chat_id, notename) else: message.reply_text( "فرمت این فایل برای من مجاز نیست . حق ندارم اینو نگه دارم! " "با @colonel294 ارتباط برقرار کن واسه دلیلش!") LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("این هشتگ دیگه وجود نداره!")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] if note: if MessageHandlerChecker.check_user(update.effective_user.id): return # 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: bot.forward_message( chat_id=update.effective_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: bot.forward_message( chat_id=update.effective_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: VALID_NOTE_FORMATTERS = [ "first", "last", "fullname", "username", "id", "chatname", "mention", ] valid_format = escape_invalid_curly_brackets( note.value, VALID_NOTE_FORMATTERS) if valid_format: text = valid_format.format( first=escape(message.from_user.first_name), last=escape(message.from_user.last_name or message.from_user.first_name), fullname=" ".join([ escape(message.from_user.first_name), escape(message.from_user.last_name), ] if message.from_user.last_name else [escape(message.from_user.first_name)]), username="******" + escape(message.from_user.username) if message.from_user.username else mention_html( message.from_user.id, message.from_user.first_name), mention=mention_html(message.from_user.id, message.from_user.first_name), chatname=escape(message.chat.title) if message.chat.type != "private" else escape( message.from_user.first_name), id=message.from_user.id, ) else: text = "" keyb = [] parseMode = ParseMode.HTML buttons = sql.get_buttons(chat_id, notename) if no_format: parseMode = None text += revert_buttons(buttons) else: text = markdown_to_html(text) keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): bot.send_message( update.effective_chat.id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard, ) else: ENUM_FUNC_MAP[note.msgtype]( update.effective_chat.id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, 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." ) LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return if show_none: message.reply_text("This note doesn't exist")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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( "Pesan ini sepertinya telah hilang - Saya akan menghapusnya " "dari daftar catatan Anda.") sql.rm_note(chat_id, notename) else: raise else: try: 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( "Sepertinya pengirim asli catatan ini telah dihapus " "pesan mereka - maaf! Minta admin bot Anda untuk mulai menggunakan file " "pesan dump untuk menghindari ini. Saya akan menghapus catatan ini dari " "catatan Anda yang disimpan.") 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): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard, ) else: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard, ) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "Sepertinya Anda mencoba menyebut seseorang yang belum pernah saya lihat sebelumnya. Jika Anda benar-benar " "ingin menyebutkan mereka, meneruskan salah satu pesan mereka kepada saya, dan saya akan bisa " "untuk menandai mereka!") elif FILE_MATCHER.match(note.value): message.reply_text( "Catatan ini adalah file yang diimpor dengan tidak benar dari bot lain - Saya tidak dapat menggunakan " "Itu. Jika Anda benar-benar membutuhkannya, Anda harus menyimpannya lagi. Di " "sementara itu, saya akan menghapusnya dari daftar catatan Anda." ) sql.rm_note(chat_id, notename) else: message.reply_text( "Catatan ini tidak dapat dikirim, karena formatnya salah." ) LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("Catatan ini tidak ada")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: bot.forward_message(chat_id=chat_id, from_chat_id=MESSAGE_DUMP, message_id=note.value) except BadRequest as excp: if excp.message == "pesan untuk diteruskan tidak ditemukan!": message.reply_text( "pesan ini sepertinya sudah hilang - saya akan menghapusnya " "dari daftar catatan anda.") sql.rm_note(chat_id, notename) else: raise else: try: bot.forward_message(chat_id=chat_id, from_chat_id=chat_id, message_id=note.value) except BadRequest as excp: if excp.message == "pesan untuk diteruskan tidak ditemukan!": message.reply_text( "sepertinya pengirim asli catatan ini telah menghapus " "pesan mereka - maaf, minta admin bot anda untuk mulai melakukan " "penghapusan pesan untuk menghindari hal ini, saya akan menghapus catatan ini dari " "catatan yang anda simpan.") sql.rm_note(chat_id, notename) else: raise else: text = note.value keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) should_preview_disabled = True if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) if "telegra.ph" in text or "youtu.be" in text: should_preview_disabled = False keyboard = InlineKeyboardMarkup(keyb) try: if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): bot.send_message( chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=should_preview_disabled, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "Sepertinya Anda mencoba menyebut seseorang yang belum pernah saya lihat sebelumnya. Jika Anda benar-benar" "ingin menyebutkan mereka, meneruskan salah satu pesan mereka kepada saya, dan saya akan bisa" "untuk menandai mereka!") elif FILE_MATCHER.match(note.value): message.reply_text( "Catatan ini adalah file yang diimpor dengan tidak benar dari bot lain - saya tidak dapat menggunakan" "itu. Jika Anda benar-benar membutuhkannya, Anda harus menyimpannya lagi. Dalam" "Sementara itu, saya akan menghapusnya dari daftar catatan Anda." ) sql.rm_note(chat_id, notename) else: message.reply_text( "Catatan ini tidak dapat dikirim, karena formatnya salah. Tanyakan dalam" "@levinachannel jika Anda tidak tahu mengapa!") LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return elif show_none: message.reply_text("note ini tidak tersedia")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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: 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): bot.send_message(chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype](chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, 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 " "@MarieSupport 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)) return elif show_none: message.reply_text("This note doesn't exist")
def get(bot, update, notename, show_none=True, no_format=False): chat_id = update.effective_chat.id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] 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: 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("이 메시지가 손실된 것 같아요. - 기록 목록에서 " "제거할게요.") sql.rm_note(chat_id, notename) else: raise else: try: 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( "이 노트의 원래 발신인이 메시지를 삭제한 것 같아요. " "미안해요! 이를 방지하기 위해 봇 관리자에게 메시지 덤프 사용을 " "시작하도록 하세요. " "저장된 노트에서 이 노트를 제거할게요.") 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): bot.send_message(chat_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype](chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": message.reply_text( "전에 본 적이 없는 사람을 언급하려 했던 것 같군요. " "정말로 그들에 대해 언급하고 싶다면, 그들의 메시지들 중 하나를 나에게 전달해주세요, " "그러면 저는 그들에게 태그를 붙일 수 있을 거예요!") elif FILE_MATCHER.match(note.value): message.reply_text("이 노트는 다른 봇에서 잘못 가져온 파일이에요 - 전 그것을 " "사용할 수 없어요. 만약 정말 필요하다면, 다시 저장할 수 있어요. " "그동안에 그것을 메모 목록에서 삭제해 드릴게요.") sql.rm_note(chat_id, notename) else: message.reply_text("이 노트의 형식이 잘못되었기 때문에 보낼 수 없어요. " "이유를 알 수 없다면 @MarieSupport 에 문의하세요!") LOGGER.exception("메시지를 구문 분석할 수 없어요 #%s - %s ", notename, str(chat_id)) LOGGER.warning("메시지가 있었어요: %s", str(note.value)) return elif show_none: message.reply_text("이 기록은 존재하지 않아요.")