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) 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: 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(buttons) keyboard = InlineKeyboardMarkup(keyb) ENUM_FUNC_MAP[goodbye_type](chat.id, cust_content, caption=goodbye_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_gdbye_preference(str(chat.id), True) try: update.effective_message.reply_text( "I'll be sorry when people leave!") except: print("Nut") 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, cust_content, goodbye_type = sql.get_gdbye_pref( chat.id) 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(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(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: 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'))
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( "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, disable_web_page_preview=True) elif len(args) >= 1: if args[0].lower() in ("on", "yes", "yas"): sql.set_welc_preference(str(chat.id), True) update.effective_message.reply_text("I'll be polite!") elif args[0].lower() in ("off", "no", "nou"): 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/yas' or 'off/no/nou' only!")
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 goodbye(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat if not args or args[0] == "noformat": noformat = True pref, goodbye_m, goodbye_type = sql.get_gdbye_pref(chat.id) update.effective_message.reply_text( f"This chat has it's goodbye setting set to: `{pref}`.\n" f"*The goodbye message (not filling the {{}}) is:*", 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("Ok!") elif args[0].lower() in ("off", "no"): sql.set_gdbye_preference(str(chat.id), False) update.effective_message.reply_text("Ok!") 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 = 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("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(send_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](send_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: print(excp.message) 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 " "@Prakaska 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 = update.effective_chat user = update.effective_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 if note: pass elif notename[0] == "#": hashnote = sql.get_note(chat_id, notename[1:]) if hashnote: note = hashnote elif show_none: message.reply_text(tld(chat.id, "note_not_existed")) 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=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(tld(chat.id, "note_lost")) 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(tld(chat.id, "note_msg_del")) 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): try: bot.send_message(send_id, 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 == "Wrong http url": failtext = tld(chat.id, "note_url_invalid") failtext += "\n\n```\n{}```".format( note.value + revert_buttons(buttons)) message.reply_text(failtext, parse_mode="markdown") else: ENUM_FUNC_MAP[note.msgtype](send_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(tld(chat.id, "note_mention_invalid")) elif FILE_MATCHER.match(note.value): message.reply_text(tld(chat.id, "note_incorrect_import")) sql.rm_note(chat_id, notename) else: message.reply_text(tld(chat.id, "note_cannot_send")) LOGGER.exception("Could not parse message #%s in chat %s", notename, str(chat_id)) LOGGER.warning("Message was: %s", str(note.value)) return
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 += "(Muted forever until user clicked the button)" else: welcsec += "(Muting user for {})".format(cur_value) text = "This chat has it's welcome setting set to: `{}`\n".format(pref) text += "Deleting old welcome message: `{}`\n".format(prev_welc) text += "Deleting service message: `{}`\n".format(cleanserv) text += "Muting users when they joined: `{}`\n".format(welcsec) text += "Mute button text: `{}`\n".format(cust_text) text += "\n*The welcome message (not filling the {}) is:*" 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(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(buttons) keyboard = InlineKeyboardMarkup(keyb) 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( "New member will be greeted with warm welcome message now!") 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 :V") else: # idek what you're writing, say yes or no update.effective_message.reply_text( "Please choose 'on/yes' or 'off/no' only!")
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(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(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'))