def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text( "මෙම කතාබහට එය පිළිගැනීමේ සැකසුම සකසා ඇත: `{}`.\n*පිළිගැනීමේ පණිවිඩය" "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("I'll be polite!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("මම දුක් වෙමි, තවදුරටත් ආයුබෝවන් නොකියමි😥. ") else: # idek what you're writing, say yes or no update.effective_message.reply_text("මට තේරෙනවා'on/yes' හෝ 'off/no' පමනි!")
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text( "Bu sohbette hoş geldiniz ayarı şu şekilde ayarlandı:` {} `. \ N * Hoş geldiniz mesajı " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("Kibar olacağım!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("Somurtuyorum, artık merhaba demiyorum.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("ben sadece 'on/yes' yada 'off/no' anlıyorum!")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "This chat has it's goodbye setting set to: `{}`.\n*The goodbye message " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("Ich entschuldige mich, wenn Leute die Gruppe verlassen!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("Wenn Leute die Gruppe verlassen, sind sie für mich gestorben.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("Ich verstehe nur 'on/yes' oder 'off/no' !")
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text( "Der Chat hat seine Willkommenseinstellung gesetzt zu: `{}`.\n*Die Willkommensnachricht " "(ohne die ausgefüllten {{}}) lautet:*".format(pref), parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("Ich werde neue Nutzer begrüßen!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("Ich schweige ab jetzt, wenn neue Nutzer der Gruppe beitreten.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("Ich verstehe nur 'on/yes' oder 'off/no' !")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "මෙම කතාබහට එය සමුගැනීමේ සැකසුම සකසා ඇත: `{}`.\n*සමුගැනීමේ පණිවිඩය " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("මිනිස්සු පිටව යන විට මට කණගාටුයි!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("ඔවුන් යනවා😌.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("මම දුක් වෙමි, තවදුරටත් ආයුබෝවන් නොකියමි😥")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "This chat has it's goodbye setting set to: `{}`.\n*The goodbye message " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("I'll be sorry when people leave!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("They leave, they're dead to me.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("I understand 'on/yes' or 'off/no' only!")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "Bu sohbetin veda ayarı şu şekilde ayarlanmıştır: `{}`. \ N * Hoşçakal mesajı " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("İnsanlar gittiğinde sessiz olacağım!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("Onlar benim için öldüler.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("Lütfen sadece 'on/yes' or 'off/no' ile kullanın.")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "Bu sohbet için ayrılma mesajı: `{}`.\n*Şuanki ayrılma mesajı " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("Insanlar ayrıldığında arkalarından üzüleceğim!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("Eğer ayrılırlarsa benim için ölürler.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("ben sadece 'on/yes' veya 'off/no' anlıyorum!")
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text( "This chat has it's welcome setting set to: `{}`.\n*The welcome message " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("I'll be polite!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("I'm sulking, not saying hello anymore.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("I understand 'on/yes' or 'off/no' only!")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( "Bu qrupda olan xoş getdin mesajı: `{}`.\n*" "( {{}}) *".format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: if noformat: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m) else: ENUM_FUNC_MAP[goodbye_type](chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) update.effective_message.reply_text("İnsanlar gedəndə vidalaşma mərasimi təşkil edirəm!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("Yaxşı yaxşı bundan sora gedən insan üçün yas tutmayacam.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("Mən 'on/yes' və 'off/no' başa düşürəm!")
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text( "Qrupun xoş gəldin mesajı: `{}`.\n* " "( {{}}) :*".format(pref), parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("Mən nəzakətli olacağam!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("Artıq salam söyləmirəm, çəkirəm.") else: # idek what you're writing, say yes or no update.effective_message.reply_text("Mən 'on/yes' və 'off/no' başa düşürəm!")
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # if no args, show current replies. if not args or args[0].lower() == "noformat": noformat = True pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text(f"This chat has it's welcome setting set to: `{pref}`.\n" f"*The welcome message (not filling the {{}}) is:*", parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME)
def welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # if no args, show current replies. if not args or args[0].lower() == "noformat": noformat = True pref, welcome_m, welcome_type = sql.get_welc_pref(chat.id) update.effective_message.reply_text(f"This chat has it's welcome setting set to: `{pref}`.\n" f"*The welcome message (not filling the {{}}) is:*", parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) else: ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("Okay! I'll greet members when they join.") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text("I'll go loaf around and not welcome anyone then.") else: update.effective_message.reply_text("I understand 'on/yes' or 'off/no' only!")
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("이 메시지가 손실된 것 같아요. - 기록 목록에서 " "제거할게요.") 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("이 기록은 존재하지 않아요.")
def goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) == 0 or args[0] == "noformat": noformat = args and args[0] == "noformat" pref, goodbye_m, cust_content, goodbye_type = sql.get_gdbye_pref( chat.id) if cust_content == None: cust_content = goodbye_m update.effective_message.reply_text(tld( chat.id, 'welcome_goodbye_settings').format(pref), parse_mode=ParseMode.MARKDOWN) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) update.effective_message.reply_text(goodbye_m) else: keyb = build_keyboard_parser(bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, goodbye_m, keyboard, sql.DEFAULT_GOODBYE) else: buttons = sql.get_gdbye_buttons(chat.id) if noformat: goodbye_m += revert_buttons(buttons) ENUM_FUNC_MAP[goodbye_type](chat.id, cust_content, caption=goodbye_m) else: keyb = build_keyboard_parser(bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) ENUM_FUNC_MAP[goodbye_type](chat.id, cust_content, caption=goodbye_m, reply_markup=keyboard, parse_mode=ParseMode.HTML, disable_web_page_preview=True) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_gdbye_preference(str(chat.id), True) try: update.effective_message.reply_text( tld(chat.id, 'welcome_goodbye_set_on')) except Exception: print("Nut") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text( tld(chat.id, 'welcome_goodbye_set_off')) else: # idek what you're writing, say yes or no update.effective_message.reply_text(tld(chat.id, 'common_invalid_arg'), parse_mode=ParseMode.MARKDOWN)
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( "يبدو أن هذه الرسالة قد فقدت - سأزيله" "من قائمة الملاحظات الخاصة بك.") 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 welcome(update, context): chat = update.effective_chat args = context.args # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, cust_content, welcome_type = sql.get_welc_pref( chat.id) update.effective_message.reply_text( "This chat has it's welcome setting set to: `{}`.\n*The welcome message " "(not filling the {{}}) is:*".format(pref), parse_mode=ParseMode.MARKDOWN, ) buttons = sql.get_welc_buttons(chat.id) if welcome_type == sql.Types.BUTTON_TEXT or welcome_type == sql.Types.TEXT: if noformat: welcome_m += revert_buttons(buttons) send_message(update.effective_message, welcome_m) else: if buttons: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) else: keyboard = None send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: if noformat: welcome_m += revert_buttons(buttons) ENUM_FUNC_MAP[welcome_type](chat.id, cust_content, caption=welcome_m) else: if buttons: keyb = build_keyboard_parser(context.bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) else: keyboard = None ENUM_FUNC_MAP[welcome_type]( chat.id, cust_content, caption=welcome_m, reply_markup=keyboard, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, ) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("I'll be polite!") elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text( "I'm sulking, not gonna greet anymore.") else: # idek what you're writing, say yes or no update.effective_message.reply_text( "I understand 'on/yes' or 'off/no' only!")
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 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.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 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, 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 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 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 welcome(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] # if no args, show current replies. if len(args) == 0 or args[0].lower() == "noformat": noformat = args and args[0].lower() == "noformat" pref, welcome_m, cust_content, welcome_type = sql.get_welc_pref( chat.id) prev_welc = sql.get_clean_pref(chat.id) if prev_welc: prev_welc = True else: prev_welc = False cleanserv = sql.clean_service(chat.id) getcur, cur_value, cust_text = sql.welcome_security(chat.id) if getcur: welcsec = "True " else: welcsec = "False " if cur_value[:1] == "0": welcsec += tld(chat.id, 'welcome_mute_time_short_none') else: welcsec += tld(chat.id, 'welcome_mute_time_short').format(cur_value) text = tld(chat.id, 'welcome_settings').format(pref, prev_welc, cleanserv, welcsec, cust_text) update.effective_message.reply_text(text, parse_mode=ParseMode.MARKDOWN) if welcome_type == sql.Types.BUTTON_TEXT or welcome_type == sql.Types.TEXT: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) update.effective_message.reply_text(welcome_m) else: keyb = build_keyboard_parser(bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) else: buttons = sql.get_welc_buttons(chat.id) if noformat: welcome_m += revert_buttons(buttons) ENUM_FUNC_MAP[welcome_type](chat.id, cust_content, caption=welcome_m) else: keyb = build_keyboard_parser(bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) ENUM_FUNC_MAP[welcome_type](chat.id, cust_content, caption=welcome_m, reply_markup=keyboard, parse_mode=ParseMode.HTML, disable_web_page_preview=True) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text( tld(chat.id, 'welcome_greet_set_on')) elif args[0].lower() in ("off", "no"): sql.set_welc_preference(str(chat.id), False) update.effective_message.reply_text( tld(chat.id, 'welcome_greet_set_off')) else: # idek what you're writing, say yes or no update.effective_message.reply_text( tld(chat.id, 'common_invalid_arg'))