From 489cd3a532df3013a893babe4e11b50f1de5c1ae Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 17:06:17 +0530 Subject: [PATCH 01/11] Response edit to broadcasting command --- SaitamaRobot/modules/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index fc53424b1d..51282dec8f 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -85,7 +85,7 @@ def broadcast(update: Update, context: CallbackContext): str(user.user_id)) update.effective_message.reply_text( - f"Broadcast complete. {failed} groups failed to receive the message, probably due to being kicked. {failed_user} failed to receive message, probably due to being blocked" + f"Broadcast complete.\nGroups failed: {failed}.\nUsers failed: {failed_user}." ) From e2c4761a07785d5ac769ac8e9b9b0f3b59b24458 Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 17:15:16 +0530 Subject: [PATCH 02/11] Markdown support for broadcast --- SaitamaRobot/modules/users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index 51282dec8f..01adac96b4 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -67,7 +67,7 @@ def broadcast(update: Update, context: CallbackContext): if to_group: for chat in chats: try: - context.bot.sendMessage(int(chat.chat_id), to_send[1]) + context.bot.sendMessage(int(chat.chat_id), to_send[1], parse_mode="MARKDOWN") sleep(0.1) except TelegramError: failed += 1 @@ -77,7 +77,7 @@ def broadcast(update: Update, context: CallbackContext): if to_user: for user in users: try: - context.bot.sendMessage(int(user.user_id), to_send[1]) + context.bot.sendMessage(int(user.user_id), to_send[1], parse_mode="MARKDOWN") sleep(0.1) except TelegramError: failed_user += 1 From ba877fa84dba0214bdb996f7240e3a0592411224 Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 17:36:09 +0530 Subject: [PATCH 03/11] Dont print broadcast warnings on console --- SaitamaRobot/modules/users.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index 01adac96b4..27e106b2c9 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -71,9 +71,6 @@ def broadcast(update: Update, context: CallbackContext): sleep(0.1) except TelegramError: failed += 1 - LOGGER.warning( - "Couldn't send broadcast to %s, group name %s", - str(chat.chat_id), str(chat.chat_name)) if to_user: for user in users: try: @@ -81,9 +78,6 @@ def broadcast(update: Update, context: CallbackContext): sleep(0.1) except TelegramError: failed_user += 1 - LOGGER.warning("Couldn't send broadcast to %s", - str(user.user_id)) - update.effective_message.reply_text( f"Broadcast complete.\nGroups failed: {failed}.\nUsers failed: {failed_user}." ) From 691cb21ddd60e6bef24e0205eb38696ad167d4ab Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 17:47:29 +0530 Subject: [PATCH 04/11] Disable webpage preview on broadcast --- SaitamaRobot/modules/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index 27e106b2c9..f548cd8187 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -67,7 +67,7 @@ def broadcast(update: Update, context: CallbackContext): if to_group: for chat in chats: try: - context.bot.sendMessage(int(chat.chat_id), to_send[1], parse_mode="MARKDOWN") + context.bot.sendMessage(int(chat.chat_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except TelegramError: failed += 1 From f383e2c2caee8e4f21c97f06e44a0850889a7faf Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 17:53:24 +0530 Subject: [PATCH 05/11] Actually Disable webpage preview on broadcast --- SaitamaRobot/modules/users.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index f548cd8187..683493e7cb 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -74,7 +74,7 @@ def broadcast(update: Update, context: CallbackContext): if to_user: for user in users: try: - context.bot.sendMessage(int(user.user_id), to_send[1], parse_mode="MARKDOWN") + context.bot.sendMessage(int(user.user_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) sleep(0.1) except TelegramError: failed_user += 1 From 4286f5911c5f8e1a538f0fc745904a8901a77334 Mon Sep 17 00:00:00 2001 From: starry69 Date: Thu, 27 Aug 2020 19:08:13 +0530 Subject: [PATCH 06/11] Welcome: Added caption & button support for media As well as fixed cleanwelcome & welcomemute if media is set as welcome message, this change require schema change in database given below; alter table welcome_pref add column custom_content text default null; Signed-off-by: starry69 --- .../modules/helper_funcs/msg_types.py | 53 +- SaitamaRobot/modules/sql/welcome_sql.py | 13 +- SaitamaRobot/modules/welcome.py | 569 +++++++++++------- 3 files changed, 405 insertions(+), 230 deletions(-) diff --git a/SaitamaRobot/modules/helper_funcs/msg_types.py b/SaitamaRobot/modules/helper_funcs/msg_types.py index 38b221ba47..59cab36c60 100644 --- a/SaitamaRobot/modules/helper_funcs/msg_types.py +++ b/SaitamaRobot/modules/helper_funcs/msg_types.py @@ -89,24 +89,20 @@ def get_welcome_type(msg: Message): content = None text = "" - args = msg.text.split(None, - 1) # use python's maxsplit to separate cmd and args - - buttons = [] - # determine what the contents of the filter are - text, image, sticker, etc - if len(args) >= 2: - offset = len(args[1]) - len( - msg.text) # set correct offset relative to command + notename - text, buttons = button_markdown_parser( - args[1], entities=msg.parse_entities(), offset=offset) - if buttons: - data_type = Types.BUTTON_TEXT + try: + if msg.reply_to_message: + if msg.reply_to_message.text: + args = msg.reply_to_message.text + else: + args = msg.reply_to_message.caption else: - data_type = Types.TEXT + args = msg.text.split(None, 1) # use python's maxsplit to separate cmd and args + except AttributeError: + args = False - elif msg.reply_to_message and msg.reply_to_message.sticker: + if msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id - text = msg.reply_to_message.caption + text = None data_type = Types.STICKER elif msg.reply_to_message and msg.reply_to_message.document: @@ -115,8 +111,7 @@ def get_welcome_type(msg: Message): data_type = Types.DOCUMENT elif msg.reply_to_message and msg.reply_to_message.photo: - content = msg.reply_to_message.photo[ - -1].file_id # last elem = best quality + content = msg.reply_to_message.photo[-1].file_id # last elem = best quality text = msg.reply_to_message.caption data_type = Types.PHOTO @@ -135,6 +130,30 @@ def get_welcome_type(msg: Message): text = msg.reply_to_message.caption data_type = Types.VIDEO + elif msg.reply_to_message and msg.reply_to_message.video_note: + content = msg.reply_to_message.video_note.file_id + text = None + data_type = Types.VIDEO_NOTE + + buttons = [] + # determine what the contents of the filter are - text, image, sticker, etc + if args: + if msg.reply_to_message: + argumen = msg.reply_to_message.caption if msg.reply_to_message.caption else "" + offset = 0 # offset is no need since target was in reply + entities = msg.reply_to_message.parse_entities() + else: + argumen = args[1] + offset = len(argumen) - len(msg.text) # set correct offset relative to command + notename + entities = msg.parse_entities() + text, buttons = button_markdown_parser(argumen, entities=entities, offset=offset) + + if not data_type: + if text and buttons: + data_type = Types.BUTTON_TEXT + elif text: + data_type = Types.TEXT + return text, data_type, content, buttons diff --git a/SaitamaRobot/modules/sql/welcome_sql.py b/SaitamaRobot/modules/sql/welcome_sql.py index 54b7bb5f0a..a52976e6a0 100644 --- a/SaitamaRobot/modules/sql/welcome_sql.py +++ b/SaitamaRobot/modules/sql/welcome_sql.py @@ -200,6 +200,7 @@ class Welcome(BASE): chat_id = Column(String(14), primary_key=True) should_welcome = Column(Boolean, default=True) should_goodbye = Column(Boolean, default=True) + custom_content = Column(UnicodeText, default=None) custom_welcome = Column( UnicodeText, default=random.choice(DEFAULT_WELCOME_MESSAGES)) @@ -361,10 +362,11 @@ def get_welc_pref(chat_id): welc = SESSION.query(Welcome).get(str(chat_id)) SESSION.close() if welc: - return welc.should_welcome, welc.custom_welcome, welc.welcome_type + return welc.should_welcome, welc.custom_welcome, welc.custom_content, welc.welcome_type + else: # Welcome by default. - return True, DEFAULT_WELCOME, Types.TEXT + return True, DEFAULT_WELCOME, None, Types.TEXT def get_gdbye_pref(chat_id): @@ -423,7 +425,7 @@ def set_gdbye_preference(chat_id, should_goodbye): SESSION.commit() -def set_custom_welcome(chat_id, custom_welcome, welcome_type, buttons=None): +def set_custom_welcome(chat_id, custom_content, custom_welcome, welcome_type, buttons=None): if buttons is None: buttons = [] @@ -432,12 +434,13 @@ def set_custom_welcome(chat_id, custom_welcome, welcome_type, buttons=None): if not welcome_settings: welcome_settings = Welcome(str(chat_id), True) - if custom_welcome: + if custom_welcome or custom_content: + welcome_settings.custom_content = custom_content welcome_settings.custom_welcome = custom_welcome welcome_settings.welcome_type = welcome_type.value else: - welcome_settings.custom_welcome = DEFAULT_GOODBYE + welcome_settings.custom_welcome = DEFAULT_WELCOME welcome_settings.welcome_type = Types.TEXT.value SESSION.add(welcome_settings) diff --git a/SaitamaRobot/modules/welcome.py b/SaitamaRobot/modules/welcome.py index 333c465c83..ba24d74415 100644 --- a/SaitamaRobot/modules/welcome.py +++ b/SaitamaRobot/modules/welcome.py @@ -5,29 +5,56 @@ from functools import partial import SaitamaRobot.modules.sql.welcome_sql as sql -from SaitamaRobot import (DEV_USERS, LOGGER, OWNER_ID, SUDO_USERS, - SUPPORT_USERS, TIGER_USERS, WHITELIST_USERS, sw, - dispatcher) +from SaitamaRobot import ( + DEV_USERS, + LOGGER, + OWNER_ID, + SUDO_USERS, + SUPPORT_USERS, + TIGER_USERS, + WHITELIST_USERS, + sw, + dispatcher, +) from SaitamaRobot.modules.helper_funcs.chat_status import ( - is_user_ban_protected, user_admin) -from SaitamaRobot.modules.helper_funcs.misc import (build_keyboard, - revert_buttons) + is_user_ban_protected, + user_admin, +) +from SaitamaRobot.modules.helper_funcs.misc import build_keyboard, revert_buttons from SaitamaRobot.modules.helper_funcs.msg_types import get_welcome_type from SaitamaRobot.modules.helper_funcs.string_handling import ( - escape_invalid_curly_brackets, markdown_parser) + escape_invalid_curly_brackets, + markdown_parser, +) from SaitamaRobot.modules.log_channel import loggable from SaitamaRobot.modules.sql.global_bans_sql import is_user_gbanned -from telegram import (ChatPermissions, InlineKeyboardButton, - InlineKeyboardMarkup, ParseMode, Update) +from telegram import ( + ChatPermissions, + InlineKeyboardButton, + InlineKeyboardMarkup, + ParseMode, + Update, +) from telegram.error import BadRequest -from telegram.ext import (CallbackContext, CallbackQueryHandler, CommandHandler, - Filters, MessageHandler, run_async) -from telegram.utils.helpers import (escape_markdown, mention_html, - mention_markdown) +from telegram.ext import ( + CallbackContext, + CallbackQueryHandler, + CommandHandler, + Filters, + MessageHandler, + run_async, +) +from telegram.utils.helpers import escape_markdown, mention_html, mention_markdown VALID_WELCOME_FORMATTERS = [ - 'first', 'last', 'fullname', 'username', 'id', 'count', 'chatname', - 'mention' + "first", + "last", + "fullname", + "username", + "id", + "count", + "chatname", + "mention", ] ENUM_FUNC_MAP = { @@ -38,7 +65,7 @@ sql.Types.PHOTO.value: dispatcher.bot.send_photo, sql.Types.AUDIO.value: dispatcher.bot.send_audio, sql.Types.VOICE.value: dispatcher.bot.send_voice, - sql.Types.VIDEO.value: dispatcher.bot.send_video + sql.Types.VIDEO.value: dispatcher.bot.send_video, } VERIFIED_USER_WAITLIST = {} @@ -61,42 +88,49 @@ def send(update, message, keyboard, backup_message): message, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) except BadRequest as excp: if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( - backup_message + - "\nNote: the current message has an invalid url " - "in one of its buttons. Please update."), + backup_message + "\nNote: the current message has an invalid url " + "in one of its buttons. Please update." + ), parse_mode=ParseMode.MARKDOWN, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( - markdown_parser(backup_message + - "\nNote: the current message has buttons which " - "use url protocols that are unsupported by " - "telegram. Please update."), + markdown_parser( + backup_message + "\nNote: the current message has buttons which " + "use url protocols that are unsupported by " + "telegram. Please update." + ), parse_mode=ParseMode.MARKDOWN, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser( - backup_message + - "\nNote: the current message has some bad urls. " - "Please update."), + backup_message + "\nNote: the current message has some bad urls. " + "Please update." + ), parse_mode=ParseMode.MARKDOWN, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) LOGGER.warning(message) LOGGER.warning(keyboard) LOGGER.exception("Could not parse! got invalid url host errors") else: msg = update.effective_message.reply_text( - markdown_parser(backup_message + - "\nNote: An error occured when sending the " - "custom message. Please update."), + markdown_parser( + backup_message + "\nNote: An error occured when sending the " + "custom message. Please update." + ), parse_mode=ParseMode.MARKDOWN, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) LOGGER.exception() return msg @@ -110,7 +144,7 @@ def new_member(update: Update, context: CallbackContext): user = update.effective_user msg = update.effective_message - should_welc, cust_welcome, welc_type = sql.get_welc_pref(chat.id) + should_welc, cust_welcome, cust_content, welc_type = sql.get_welc_pref(chat.id) welc_mutes = sql.welcome_mutes(chat.id) human_checks = sql.get_human_checks(user.id, chat.id) @@ -123,6 +157,7 @@ def new_member(update: Update, context: CallbackContext): sent = None should_mute = True welcome_bool = True + media_wel = False if sw != None: sw_ban = sw.get_ban(new_mem.id) @@ -136,8 +171,7 @@ def new_member(update: Update, context: CallbackContext): # Clean service welcome if cleanserv: try: - dispatcher.bot.delete_message(chat.id, - update.message.message_id) + dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False @@ -145,77 +179,84 @@ def new_member(update: Update, context: CallbackContext): # Give the owner a special welcome if new_mem.id == OWNER_ID: update.effective_message.reply_text( - "Oh, Genos? Let's get this moving.", - reply_to_message_id=reply) - welcome_log = (f"{html.escape(chat.title)}\n" - f"#USER_JOINED\n" - f"Bot Owner just joined the chat") + "Oh, Genos? Let's get this moving.", reply_to_message_id=reply + ) + welcome_log = ( + f"{html.escape(chat.title)}\n" + f"#USER_JOINED\n" + f"Bot Owner just joined the chat" + ) # Welcome Devs elif new_mem.id in DEV_USERS: update.effective_message.reply_text( "Whoa! A member of the Heroes Association just joined!", - reply_to_message_id=reply) + reply_to_message_id=reply, + ) # Welcome Sudos elif new_mem.id in SUDO_USERS: update.effective_message.reply_text( "Huh! A Dragon disaster just joined! Stay Alert!", - reply_to_message_id=reply) + reply_to_message_id=reply, + ) # Welcome Support elif new_mem.id in SUPPORT_USERS: update.effective_message.reply_text( "Huh! Someone with a Demon disaster level just joined!", - reply_to_message_id=reply) + reply_to_message_id=reply, + ) # Welcome Whitelisted elif new_mem.id in TIGER_USERS: update.effective_message.reply_text( - "Oof! A Tiger disaster just joined!", - reply_to_message_id=reply) + "Oof! A Tiger disaster just joined!", reply_to_message_id=reply + ) # Welcome Tigers elif new_mem.id in WHITELIST_USERS: update.effective_message.reply_text( - "Oof! A Wolf disaster just joined!", - reply_to_message_id=reply) + "Oof! A Wolf disaster just joined!", reply_to_message_id=reply + ) # Welcome yourself elif new_mem.id == bot.id: update.effective_message.reply_text( - "Watashi ga kita!", reply_to_message_id=reply) + "Watashi ga kita!", reply_to_message_id=reply + ) else: - # If welcome message is media, send with appropriate function + buttons = sql.get_welc_buttons(chat.id) + keyb = build_keyboard(buttons) + if welc_type not in (sql.Types.TEXT, sql.Types.BUTTON_TEXT): - ENUM_FUNC_MAP[welc_type](chat.id, cust_welcome) - continue + media_wel = True - # else, move on - first_name = new_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. + first_name = ( + new_mem.first_name or "PersonWithNoName" + ) # edge case of empty name - occurs for some bugs. if cust_welcome: if cust_welcome == sql.DEFAULT_WELCOME: cust_welcome = random.choice( - sql.DEFAULT_WELCOME_MESSAGES).format( - first=escape_markdown(first_name)) + sql.DEFAULT_WELCOME_MESSAGES + ).format(first=escape_markdown(first_name)) if new_mem.last_name: - fullname = escape_markdown( - f"{first_name} {new_mem.last_name}") + fullname = escape_markdown(f"{first_name} {new_mem.last_name}") else: fullname = escape_markdown(first_name) count = chat.get_members_count() - mention = mention_markdown(new_mem.id, - escape_markdown(first_name)) + mention = mention_markdown(new_mem.id, escape_markdown(first_name)) if new_mem.username: username = "@" + escape_markdown(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( - cust_welcome, VALID_WELCOME_FORMATTERS) + cust_welcome, VALID_WELCOME_FORMATTERS + ) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(new_mem.last_name or first_name), @@ -224,18 +265,18 @@ def new_member(update: Update, context: CallbackContext): mention=mention, count=count, chatname=escape_markdown(chat.title), - id=new_mem.id) - buttons = sql.get_welc_buttons(chat.id) - keyb = build_keyboard(buttons) + id=new_mem.id, + ) else: res = random.choice(sql.DEFAULT_WELCOME_MESSAGES).format( - first=escape_markdown(first_name)) + first=escape_markdown(first_name) + ) keyb = [] - backup_message = random.choice( - sql.DEFAULT_WELCOME_MESSAGES).format( - first=escape_markdown(first_name)) + backup_message = random.choice(sql.DEFAULT_WELCOME_MESSAGES).format( + first=escape_markdown(first_name) + ) keyboard = InlineKeyboardMarkup(keyb) else: @@ -246,8 +287,10 @@ def new_member(update: Update, context: CallbackContext): reply = None # User exceptions from welcomemutes - if is_user_ban_protected(chat, new_mem.id, chat.get_member( - new_mem.id)) or human_checks: + if ( + is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)) + or human_checks + ): should_mute = False # Join welcome: soft mute if new_mem.is_bot: @@ -267,30 +310,57 @@ def new_member(update: Update, context: CallbackContext): can_pin_messages=False, can_send_polls=False, can_change_info=False, - can_add_web_page_previews=False), - until_date=(int(time.time() + 24 * 60 * 60))) + can_add_web_page_previews=False, + ), + until_date=(int(time.time() + 24 * 60 * 60)), + ) if welc_mutes == "strong": welcome_bool = False - VERIFIED_USER_WAITLIST.update({ - new_mem.id: { - "should_welc": should_welc, - "status": False, - "update": update, - "res": res, - "keyboard": keyboard, - "backup_message": backup_message - } - }) + if not media_wel: + VERIFIED_USER_WAITLIST.update( + { + new_mem.id: { + "should_welc": should_welc, + "media_wel": False, + "status": False, + "update": update, + "res": res, + "keyboard": keyboard, + "backup_message": backup_message, + } + } + ) + else: + VERIFIED_USER_WAITLIST.update( + { + new_mem.id: { + "should_welc": should_welc, + "chat_id": chat.id, + "status": False, + "media_wel": True, + "cust_content": cust_content, + "welc_type": welc_type, + "res": res, + "keyboard": keyboard, + } + } + ) new_join_mem = f"[{escape_markdown(new_mem.first_name)}](tg://user?id={user.id})" message = msg.reply_text( f"{new_join_mem}, click the button below to prove you're human.\nYou have 120 seconds.", - reply_markup=InlineKeyboardMarkup([{ - InlineKeyboardButton( - text="Yes, I'm human.", - callback_data=f"user_join_({new_mem.id})") - }]), + reply_markup=InlineKeyboardMarkup( + [ + { + InlineKeyboardButton( + text="Yes, I'm human.", + callback_data=f"user_join_({new_mem.id})", + ) + } + ] + ), parse_mode=ParseMode.MARKDOWN, - reply_to_message_id=reply) + reply_to_message_id=reply, + ) bot.restrict_chat_member( chat.id, new_mem.id, @@ -302,16 +372,27 @@ def new_member(update: Update, context: CallbackContext): can_change_info=False, can_send_media_messages=False, can_send_other_messages=False, - can_add_web_page_previews=False)) + can_add_web_page_previews=False, + ), + ) job_queue.run_once( - partial(check_not_bot, new_mem, chat.id, - message.message_id), + partial(check_not_bot, new_mem, chat.id, message.message_id), 120, - name="welcomemute") + name="welcomemute", + ) if welcome_bool: - sent = send(update, res, keyboard, backup_message) - + if media_wel: + sent = ENUM_FUNC_MAP[welc_type]( + chat.id, + cust_content, + caption=res, + reply_markup=keyboard, + reply_to_message_id=reply, + parse_mode="markdown", + ) + else: + sent = send(update, res, keyboard, backup_message) prev_welc = sql.get_clean_pref(chat.id) if prev_welc: try: @@ -325,10 +406,12 @@ def new_member(update: Update, context: CallbackContext): if welcome_log: return welcome_log - return (f"{html.escape(chat.title)}\n" - f"#USER_JOINED\n" - f"User: {mention_html(user.id, user.first_name)}\n" - f"ID: {user.id}") + return ( + f"{html.escape(chat.title)}\n" + f"#USER_JOINED\n" + f"User: {mention_html(user.id, user.first_name)}\n" + f"ID: {user.id}" + ) return "" @@ -347,7 +430,8 @@ def check_not_bot(member, chat_id, message_id, context): bot.edit_message_text( "*kicks user*\nThey can always rejoin and try.", chat_id=chat_id, - message_id=message_id) + message_id=message_id, + ) except: pass @@ -368,8 +452,7 @@ def left_member(update: Update, context: CallbackContext): # Clean service welcome if cleanserv: try: - dispatcher.bot.delete_message(chat.id, - update.message.message_id) + dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass reply = False @@ -394,14 +477,16 @@ def left_member(update: Update, context: CallbackContext): # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text( - "Oi! Genos! He left..", reply_to_message_id=reply) + "Oi! Genos! He left..", reply_to_message_id=reply + ) return # Give the devs a special goodbye elif left_mem.id in DEV_USERS: update.effective_message.reply_text( "See you later at the Hero's Association!", - reply_to_message_id=reply) + reply_to_message_id=reply, + ) return # if media goodbye, use appropriate function for it @@ -409,15 +494,16 @@ def left_member(update: Update, context: CallbackContext): ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return - first_name = left_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. + first_name = ( + left_mem.first_name or "PersonWithNoName" + ) # edge case of empty name - occurs for some bugs. if cust_goodbye: if cust_goodbye == sql.DEFAULT_GOODBYE: - cust_goodbye = random.choice( - sql.DEFAULT_GOODBYE_MESSAGES).format( - first=escape_markdown(first_name)) + cust_goodbye = random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format( + first=escape_markdown(first_name) + ) if left_mem.last_name: - fullname = escape_markdown( - f"{first_name} {left_mem.last_name}") + fullname = escape_markdown(f"{first_name} {left_mem.last_name}") else: fullname = escape_markdown(first_name) count = chat.get_members_count() @@ -428,7 +514,8 @@ def left_member(update: Update, context: CallbackContext): username = mention valid_format = escape_invalid_curly_brackets( - cust_goodbye, VALID_WELCOME_FORMATTERS) + cust_goodbye, VALID_WELCOME_FORMATTERS + ) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), @@ -437,21 +524,25 @@ def left_member(update: Update, context: CallbackContext): mention=mention, count=count, chatname=escape_markdown(chat.title), - id=left_mem.id) + id=left_mem.id, + ) buttons = sql.get_gdbye_buttons(chat.id) keyb = build_keyboard(buttons) else: - res = random.choice( - sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name) + res = random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format( + first=first_name + ) keyb = [] keyboard = InlineKeyboardMarkup(keyb) send( - update, res, keyboard, - random.choice( - sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name)) + update, + res, + keyboard, + random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name), + ) @run_async @@ -462,13 +553,14 @@ def welcome(update: Update, context: CallbackContext): # 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) + pref, welcome_m, cust_content, 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) + parse_mode=ParseMode.MARKDOWN, + ) - if welcome_type == sql.Types.BUTTON_TEXT: + 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) @@ -479,29 +571,41 @@ def welcome(update: Update, context: CallbackContext): keyboard = InlineKeyboardMarkup(keyb) send(update, welcome_m, keyboard, sql.DEFAULT_WELCOME) - else: + buttons = sql.get_welc_buttons(chat.id) if noformat: - ENUM_FUNC_MAP[welcome_type](chat.id, welcome_m) + 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, welcome_m, parse_mode=ParseMode.MARKDOWN) + 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( - "Okay! I'll greet members when they join.") + "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.") + "I'll go loaf around and not welcome anyone then." + ) else: update.effective_message.reply_text( - "I understand 'on/yes' or 'off/no' only!") + "I understand 'on/yes' or 'off/no' only!" + ) @run_async @@ -516,7 +620,8 @@ def goodbye(update: Update, context: CallbackContext): 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) + parse_mode=ParseMode.MARKDOWN, + ) if goodbye_type == sql.Types.BUTTON_TEXT: buttons = sql.get_gdbye_buttons(chat.id) @@ -536,7 +641,8 @@ def goodbye(update: Update, context: CallbackContext): else: ENUM_FUNC_MAP[goodbye_type]( - chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) + chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN + ) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): @@ -550,7 +656,8 @@ def goodbye(update: Update, context: CallbackContext): else: # idek what you're writing, say yes or no update.effective_message.reply_text( - "I understand 'on/yes' or 'off/no' only!") + "I understand 'on/yes' or 'off/no' only!" + ) @run_async @@ -567,13 +674,15 @@ def set_welcome(update: Update, context: CallbackContext) -> str: msg.reply_text("You didn't specify what to reply with!") return "" - sql.set_custom_welcome(chat.id, content or text, data_type, buttons) + sql.set_custom_welcome(chat.id, content, text, data_type, buttons) msg.reply_text("Successfully set custom welcome message!") - return (f"{html.escape(chat.title)}:\n" - f"#SET_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Set the welcome message.") + return ( + f"{html.escape(chat.title)}:\n" + f"#SET_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Set the welcome message." + ) @run_async @@ -583,14 +692,17 @@ def reset_welcome(update: Update, context: CallbackContext) -> str: chat = update.effective_chat user = update.effective_user - sql.set_custom_welcome(chat.id, sql.DEFAULT_WELCOME, sql.Types.TEXT) + sql.set_custom_welcome(chat.id, None, sql.DEFAULT_WELCOME, sql.Types.TEXT) update.effective_message.reply_text( - "Successfully reset welcome message to default!") + "Successfully reset welcome message to default!" + ) - return (f"{html.escape(chat.title)}:\n" - f"#RESET_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Reset the welcome message to default.") + return ( + f"{html.escape(chat.title)}:\n" + f"#RESET_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Reset the welcome message to default." + ) @run_async @@ -608,10 +720,12 @@ def set_goodbye(update: Update, context: CallbackContext) -> str: sql.set_custom_gdbye(chat.id, content or text, data_type, buttons) msg.reply_text("Successfully set custom goodbye message!") - return (f"{html.escape(chat.title)}:\n" - f"#SET_GOODBYE\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Set the goodbye message.") + return ( + f"{html.escape(chat.title)}:\n" + f"#SET_GOODBYE\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Set the goodbye message." + ) @run_async @@ -623,12 +737,15 @@ def reset_goodbye(update: Update, context: CallbackContext) -> str: sql.set_custom_gdbye(chat.id, sql.DEFAULT_GOODBYE, sql.Types.TEXT) update.effective_message.reply_text( - "Successfully reset goodbye message to default!") + "Successfully reset goodbye message to default!" + ) - return (f"{html.escape(chat.title)}:\n" - f"#RESET_GOODBYE\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Reset the goodbye message.") + return ( + f"{html.escape(chat.title)}:\n" + f"#RESET_GOODBYE\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Reset the goodbye message." + ) @run_async @@ -648,16 +765,19 @@ def welcomemute(update: Update, context: CallbackContext) -> str: f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to OFF.") + f"Has toggled welcome mute to OFF." + ) elif args[0].lower() in ["soft"]: sql.set_welcome_mutes(chat.id, "soft") msg.reply_text( - "I will restrict users' permission to send media for 24 hours.") + "I will restrict users' permission to send media for 24 hours." + ) return ( f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to SOFT.") + f"Has toggled welcome mute to SOFT." + ) elif args[0].lower() in ["strong"]: sql.set_welcome_mutes(chat.id, "strong") msg.reply_text( @@ -667,17 +787,20 @@ def welcomemute(update: Update, context: CallbackContext) -> str: f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to STRONG.") + f"Has toggled welcome mute to STRONG." + ) else: msg.reply_text( "Please enter `off`/`no`/`soft`/`strong`!", - parse_mode=ParseMode.MARKDOWN) + parse_mode=ParseMode.MARKDOWN, + ) return "" else: curr_setting = sql.welcome_mutes(chat.id) reply = ( f"\n Give me a setting!\nChoose one out of: `off`/`no` or `soft` or `strong` only! \n" - f"Current setting: `{curr_setting}`") + f"Current setting: `{curr_setting}`" + ) msg.reply_text(reply, parse_mode=ParseMode.MARKDOWN) return "" @@ -694,31 +817,34 @@ def clean_welcome(update: Update, context: CallbackContext) -> str: clean_pref = sql.get_clean_pref(chat.id) if clean_pref: update.effective_message.reply_text( - "I should be deleting welcome messages up to two days old.") + "I should be deleting welcome messages up to two days old." + ) else: update.effective_message.reply_text( - "I'm currently not deleting old welcome messages!") + "I'm currently not deleting old welcome messages!" + ) return "" if args[0].lower() in ("on", "yes"): sql.set_clean_welcome(str(chat.id), True) - update.effective_message.reply_text( - "I'll try to delete old welcome messages!") - return (f"{html.escape(chat.title)}:\n" - f"#CLEAN_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled clean welcomes to ON.") + update.effective_message.reply_text("I'll try to delete old welcome messages!") + return ( + f"{html.escape(chat.title)}:\n" + f"#CLEAN_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Has toggled clean welcomes to ON." + ) elif args[0].lower() in ("off", "no"): sql.set_clean_welcome(str(chat.id), False) - update.effective_message.reply_text( - "I won't delete old welcome messages.") - return (f"{html.escape(chat.title)}:\n" - f"#CLEAN_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled clean welcomes to OFF.") + update.effective_message.reply_text("I won't delete old welcome messages.") + return ( + f"{html.escape(chat.title)}:\n" + f"#CLEAN_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Has toggled clean welcomes to OFF." + ) else: - update.effective_message.reply_text( - "I understand 'on/yes' or 'off/no' only!") + update.effective_message.reply_text("I understand 'on/yes' or 'off/no' only!") return "" @@ -730,28 +856,30 @@ def cleanservice(update: Update, context: CallbackContext) -> str: if chat.type != chat.PRIVATE: if len(args) >= 1: var = args[0] - if var in ('no', 'off'): + if var in ("no", "off"): sql.set_clean_service(chat.id, False) - update.effective_message.reply_text( - 'Welcome clean service is : off') - elif var in ('yes', 'on'): + update.effective_message.reply_text("Welcome clean service is : off") + elif var in ("yes", "on"): sql.set_clean_service(chat.id, True) - update.effective_message.reply_text( - 'Welcome clean service is : on') + update.effective_message.reply_text("Welcome clean service is : on") else: update.effective_message.reply_text( - "Invalid option", parse_mode=ParseMode.MARKDOWN) + "Invalid option", parse_mode=ParseMode.MARKDOWN + ) else: update.effective_message.reply_text( - "Usage is on/yes or off/no", parse_mode=ParseMode.MARKDOWN) + "Usage is on/yes or off/no", parse_mode=ParseMode.MARKDOWN + ) else: curr = sql.clean_service(chat.id) if curr: update.effective_message.reply_text( - 'Welcome clean service is : on', parse_mode=ParseMode.MARKDOWN) + "Welcome clean service is : on", parse_mode=ParseMode.MARKDOWN + ) else: update.effective_message.reply_text( - 'Welcome clean service is : off', parse_mode=ParseMode.MARKDOWN) + "Welcome clean service is : off", parse_mode=ParseMode.MARKDOWN + ) @run_async @@ -780,11 +908,26 @@ def user_button(update: Update, context: CallbackContext): can_change_info=True, can_send_media_messages=True, can_send_other_messages=True, - can_add_web_page_previews=True)) + can_add_web_page_previews=True, + ), + ) bot.deleteMessage(chat.id, message.message_id) if member_dict["should_welc"]: - sent = send(member_dict["update"], member_dict["res"], - member_dict["keyboard"], member_dict["backup_message"]) + if member_dict["media_wel"]: + sent = ENUM_FUNC_MAP[member_dict["welc_type"]]( + member_dict["chat_id"], + member_dict["cust_content"], + caption=member_dict["res"], + reply_markup=member_dict["keyboard"], + parse_mode="markdown", + ) + else: + sent = send( + member_dict["update"], + member_dict["res"], + member_dict["keyboard"], + member_dict["backup_message"], + ) prev_welc = sql.get_clean_pref(chat.id) if prev_welc: @@ -823,7 +966,8 @@ def user_button(update: Update, context: CallbackContext): "go. Note that group ids are usually preceded by a `-` sign; this is required, so please don't " "remove it.\n" "You can even set images/gifs/videos/voice messages as the welcome message by " - "replying to the desired media, and calling `/setwelcome`.") + "replying to the desired media, and calling `/setwelcome`." +) WELC_MUTE_HELP_TXT = ( "You can get the bot to mute new people who join your group and hence prevent spambots from flooding your group. " @@ -838,15 +982,15 @@ def user_button(update: Update, context: CallbackContext): @run_async @user_admin def welcome_help(update: Update, context: CallbackContext): - update.effective_message.reply_text( - WELC_HELP_TXT, parse_mode=ParseMode.MARKDOWN) + update.effective_message.reply_text(WELC_HELP_TXT, parse_mode=ParseMode.MARKDOWN) @run_async @user_admin def welcome_mute_help(update: Update, context: CallbackContext): update.effective_message.reply_text( - WELC_MUTE_HELP_TXT, parse_mode=ParseMode.MARKDOWN) + WELC_MUTE_HELP_TXT, parse_mode=ParseMode.MARKDOWN + ) # TODO: get welcome data from group butler snap @@ -868,8 +1012,10 @@ def __migrate__(old_chat_id, new_chat_id): def __chat_settings__(chat_id, user_id): welcome_pref, _, _ = sql.get_welc_pref(chat_id) goodbye_pref, _, _ = sql.get_gdbye_pref(chat_id) - return "This chat has it's welcome preference set to `{}`.\n" \ - "It's goodbye preference is `{}`.".format(welcome_pref, goodbye_pref) + return ( + "This chat has it's welcome preference set to `{}`.\n" + "It's goodbye preference is `{}`.".format(welcome_pref, goodbye_pref) + ) __help__ = """ @@ -889,26 +1035,23 @@ def __chat_settings__(chat_id, user_id): • `/welcomehelp`*:* view more formatting information for custom welcome/goodbye messages. • `/cleanservice Date: Thu, 27 Aug 2020 19:31:45 +0530 Subject: [PATCH 07/11] Bring markdown support to echo command --- SaitamaRobot/modules/misc.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SaitamaRobot/modules/misc.py b/SaitamaRobot/modules/misc.py index 3b982f9f14..159886d648 100644 --- a/SaitamaRobot/modules/misc.py +++ b/SaitamaRobot/modules/misc.py @@ -185,10 +185,9 @@ def echo(update: Update, context: CallbackContext): message = update.effective_message if message.reply_to_message: - message.reply_to_message.reply_text(args[1]) + message.reply_to_message.reply_text(args[1], parse_mode="MARKDOWN", disable_web_page_preview=True) else: - message.reply_text(args[1], quote=False) - + message.reply_text(args[1], quote=False, parse_mode="MARKDOWN", disable_web_page_preview=True) message.delete() From 3bc713360f19506640eb1a931c1d8a5b5d9e6338 Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 19:34:26 +0530 Subject: [PATCH 08/11] Beautification to /stats --- SaitamaRobot/modules/blacklist.py | 2 +- SaitamaRobot/modules/blacklist_stickers.py | 2 +- SaitamaRobot/modules/cust_filters.py | 2 +- SaitamaRobot/modules/disable.py | 2 +- SaitamaRobot/modules/feds.py | 2 +- SaitamaRobot/modules/global_bans.py | 2 +- SaitamaRobot/modules/log_channel.py | 2 +- SaitamaRobot/modules/notes.py | 2 +- SaitamaRobot/modules/rules.py | 2 +- SaitamaRobot/modules/users.py | 2 +- SaitamaRobot/modules/warns.py | 4 ++-- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SaitamaRobot/modules/blacklist.py b/SaitamaRobot/modules/blacklist.py index 3c53d166cc..6cb76ab085 100644 --- a/SaitamaRobot/modules/blacklist.py +++ b/SaitamaRobot/modules/blacklist.py @@ -439,7 +439,7 @@ def __chat_settings__(chat_id, user_id): def __stats__(): - return "× {} blacklist triggers, across {} chats.".format( + return "• {} blacklist triggers, across {} chats.".format( sql.num_blacklist_filters(), sql.num_blacklist_filter_chats()) diff --git a/SaitamaRobot/modules/blacklist_stickers.py b/SaitamaRobot/modules/blacklist_stickers.py index d56b7467f6..449c81bc2b 100644 --- a/SaitamaRobot/modules/blacklist_stickers.py +++ b/SaitamaRobot/modules/blacklist_stickers.py @@ -459,7 +459,7 @@ def __chat_settings__(chat_id, user_id): def __stats__(): - return "{} blacklist stickers, across {} chats.".format( + return "• {} blacklist stickers, across {} chats.".format( sql.num_stickers_filters(), sql.num_stickers_filter_chats()) diff --git a/SaitamaRobot/modules/cust_filters.py b/SaitamaRobot/modules/cust_filters.py index dcf5f959c8..5a003cdb46 100644 --- a/SaitamaRobot/modules/cust_filters.py +++ b/SaitamaRobot/modules/cust_filters.py @@ -492,7 +492,7 @@ def get_exception(excp, filt, chat): def __stats__(): - return "× {} filters, across {} chats.".format(sql.num_filters(), + return "• {} filters, across {} chats.".format(sql.num_filters(), sql.num_chats()) diff --git a/SaitamaRobot/modules/disable.py b/SaitamaRobot/modules/disable.py index c090b97a36..1df9027dc2 100644 --- a/SaitamaRobot/modules/disable.py +++ b/SaitamaRobot/modules/disable.py @@ -305,7 +305,7 @@ def commands(update: Update, context: CallbackContext): build_curr_disabled(chat.id), parse_mode=ParseMode.MARKDOWN) def __stats__(): - return f"{sql.num_disabled()} disabled items, across {sql.num_chats()} chats." + return f"• {sql.num_disabled()} disabled items, across {sql.num_chats()} chats." def __migrate__(old_chat_id, new_chat_id): sql.migrate_chat(old_chat_id, new_chat_id) diff --git a/SaitamaRobot/modules/feds.py b/SaitamaRobot/modules/feds.py index ce45d61afa..3b84759400 100644 --- a/SaitamaRobot/modules/feds.py +++ b/SaitamaRobot/modules/feds.py @@ -1996,7 +1996,7 @@ def welcome_fed(update: Update, context: CallbackContext): def __stats__(): all_fbanned = sql.get_all_fban_users_global() all_feds = sql.get_all_feds_users_global() - return "{} banned users across {} Federations".format( + return "• {} banned users across {} Federations".format( len(all_fbanned), len(all_feds)) diff --git a/SaitamaRobot/modules/global_bans.py b/SaitamaRobot/modules/global_bans.py index 6560201089..f8a8d8dd3a 100644 --- a/SaitamaRobot/modules/global_bans.py +++ b/SaitamaRobot/modules/global_bans.py @@ -460,7 +460,7 @@ def gbanstat(update: Update, context: CallbackContext): def __stats__(): - return f"{sql.num_gbanned_users()} gbanned users." + return f"• {sql.num_gbanned_users()} gbanned users." def __user_info__(user_id): diff --git a/SaitamaRobot/modules/log_channel.py b/SaitamaRobot/modules/log_channel.py index 0afc1bda4a..3864724a96 100644 --- a/SaitamaRobot/modules/log_channel.py +++ b/SaitamaRobot/modules/log_channel.py @@ -183,7 +183,7 @@ def unsetlog(update: Update, context: CallbackContext): message.reply_text("No log channel has been set yet!") def __stats__(): - return f"{sql.num_logchannels()} log channels set." + return f"• {sql.num_logchannels()} log channels set." def __migrate__(old_chat_id, new_chat_id): sql.migrate_chat(old_chat_id, new_chat_id) diff --git a/SaitamaRobot/modules/notes.py b/SaitamaRobot/modules/notes.py index cad9ecc537..a08cc2d418 100644 --- a/SaitamaRobot/modules/notes.py +++ b/SaitamaRobot/modules/notes.py @@ -406,7 +406,7 @@ def __import_data__(chat_id, data): def __stats__(): - return f"{sql.num_notes()} notes, across {sql.num_chats()} chats." + return f"• {sql.num_notes()} notes, across {sql.num_chats()} chats." def __migrate__(old_chat_id, new_chat_id): diff --git a/SaitamaRobot/modules/rules.py b/SaitamaRobot/modules/rules.py index 7b3773d97e..214a9acb55 100644 --- a/SaitamaRobot/modules/rules.py +++ b/SaitamaRobot/modules/rules.py @@ -89,7 +89,7 @@ def clear_rules(update: Update, context: CallbackContext): def __stats__(): - return f"{sql.num_chats()} chats have rules set." + return f"• {sql.num_chats()} chats have rules set." def __import_data__(chat_id, data): diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index 683493e7cb..0e144d677a 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -141,7 +141,7 @@ def __user_info__(user_id): def __stats__(): - return f"{sql.num_users()} users, across {sql.num_chats()} chats" + return f"• {sql.num_users()} users, across {sql.num_chats()} chats" def __migrate__(old_chat_id, new_chat_id): diff --git a/SaitamaRobot/modules/warns.py b/SaitamaRobot/modules/warns.py index a1841add08..ad39a29a2e 100644 --- a/SaitamaRobot/modules/warns.py +++ b/SaitamaRobot/modules/warns.py @@ -426,8 +426,8 @@ def set_warn_strength(update: Update, context: CallbackContext): def __stats__(): return ( - f"{sql.num_warns()} overall warns, across {sql.num_warn_chats()} chats.\n" - f"{sql.num_warn_filters()} warn filters, across {sql.num_warn_filter_chats()} chats." + f"• {sql.num_warns()} overall warns, across {sql.num_warn_chats()} chats.\n" + f"• {sql.num_warn_filters()} warn filters, across {sql.num_warn_filter_chats()} chats." ) From 93e47f03f02191b2c5250b59d30329613e5ec0a2 Mon Sep 17 00:00:00 2001 From: starry69 Date: Thu, 27 Aug 2020 20:10:21 +0530 Subject: [PATCH 09/11] Welcome: fix UnboundLocalError Signed-off-by: starry69 --- SaitamaRobot/modules/welcome.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SaitamaRobot/modules/welcome.py b/SaitamaRobot/modules/welcome.py index ba24d74415..7805f29eca 100644 --- a/SaitamaRobot/modules/welcome.py +++ b/SaitamaRobot/modules/welcome.py @@ -186,6 +186,7 @@ def new_member(update: Update, context: CallbackContext): f"#USER_JOINED\n" f"Bot Owner just joined the chat" ) + continue # Welcome Devs elif new_mem.id in DEV_USERS: @@ -193,6 +194,7 @@ def new_member(update: Update, context: CallbackContext): "Whoa! A member of the Heroes Association just joined!", reply_to_message_id=reply, ) + continue # Welcome Sudos elif new_mem.id in SUDO_USERS: @@ -200,6 +202,7 @@ def new_member(update: Update, context: CallbackContext): "Huh! A Dragon disaster just joined! Stay Alert!", reply_to_message_id=reply, ) + continue # Welcome Support elif new_mem.id in SUPPORT_USERS: @@ -207,24 +210,28 @@ def new_member(update: Update, context: CallbackContext): "Huh! Someone with a Demon disaster level just joined!", reply_to_message_id=reply, ) + continue # Welcome Whitelisted elif new_mem.id in TIGER_USERS: update.effective_message.reply_text( "Oof! A Tiger disaster just joined!", reply_to_message_id=reply ) + continue # Welcome Tigers elif new_mem.id in WHITELIST_USERS: update.effective_message.reply_text( "Oof! A Wolf disaster just joined!", reply_to_message_id=reply ) + continue # Welcome yourself elif new_mem.id == bot.id: update.effective_message.reply_text( "Watashi ga kita!", reply_to_message_id=reply ) + continue else: buttons = sql.get_welc_buttons(chat.id) From cc35fef3f497c7b1b2bf4ac52cff6b5a7c1948b3 Mon Sep 17 00:00:00 2001 From: Sawada Tsunayoshi Date: Thu, 27 Aug 2020 20:21:35 +0530 Subject: [PATCH 10/11] =?UTF-8?q?Replace=20the=20x=20with=20=E2=80=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SaitamaRobot/modules/backups.py | 4 ++-- SaitamaRobot/modules/connection.py | 10 +++++----- SaitamaRobot/modules/cust_filters.py | 2 +- SaitamaRobot/modules/locks.py | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SaitamaRobot/modules/backups.py b/SaitamaRobot/modules/backups.py index 7df1854e10..fedbb4e596 100644 --- a/SaitamaRobot/modules/backups.py +++ b/SaitamaRobot/modules/backups.py @@ -368,10 +368,10 @@ def get_chat(chat_id, chat_data): __help__ = """ *Only for group owner:* - × /import: Reply to the backup file for the butler / emilia group to import as much as possible, making transfers very easy! \ + • /import: Reply to the backup file for the butler / emilia group to import as much as possible, making transfers very easy! \ Note that files / photos cannot be imported due to telegram restrictions. - × /export: Export group data, which will be exported are: rules, notes (documents, images, music, video, audio, voice, text, text buttons) \ + • /export: Export group data, which will be exported are: rules, notes (documents, images, music, video, audio, voice, text, text buttons) \ """ diff --git a/SaitamaRobot/modules/connection.py b/SaitamaRobot/modules/connection.py index 6838adcde9..64045c8ef3 100644 --- a/SaitamaRobot/modules/connection.py +++ b/SaitamaRobot/modules/connection.py @@ -374,13 +374,13 @@ def connect_button(update, context): Sometimes, you just want to add some notes and filters to a group chat, but you don't want everyone to see; This is where connections come in... This allows you to connect to a chat's database, and add things to it without the commands appearing in chat! For obvious reasons, you need to be an admin to add things; but any member in the group can view your data. - × /connect: Connects to chat (Can be done in a group by /connect or /connect in PM) - × /connection: List connected chats - × /disconnect: Disconnect from a chat - × /helpconnect: List available commands that can be used remotely + • /connect: Connects to chat (Can be done in a group by /connect or /connect in PM) + • /connection: List connected chats + • /disconnect: Disconnect from a chat + • /helpconnect: List available commands that can be used remotely *Admin only:* - × /allowconnect : allow a user to connect to a chat + • /allowconnect : allow a user to connect to a chat """ CONNECT_CHAT_HANDLER = CommandHandler("connect", connect_chat, pass_args=True) diff --git a/SaitamaRobot/modules/cust_filters.py b/SaitamaRobot/modules/cust_filters.py index 5a003cdb46..c879c7c84a 100644 --- a/SaitamaRobot/modules/cust_filters.py +++ b/SaitamaRobot/modules/cust_filters.py @@ -75,7 +75,7 @@ def list_handlers(update, context): return for keyword in all_handlers: - entry = " × `{}`\n".format(escape_markdown(keyword)) + entry = " • `{}`\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message( update.effective_message, diff --git a/SaitamaRobot/modules/locks.py b/SaitamaRobot/modules/locks.py index ff9ad75b27..1b2aa1788f 100644 --- a/SaitamaRobot/modules/locks.py +++ b/SaitamaRobot/modules/locks.py @@ -541,10 +541,10 @@ def build_lock_message(chat_id): locklist.sort() # Building lock list string for x in locklist: - res += "\n × {}".format(x) + res += "\n • {}".format(x) res += "\n\n*" + "These are the current chat permissions:" + "*" for x in permslist: - res += "\n × {}".format(x) + res += "\n • {}".format(x) return res From f20b3d34fae48e8c5f23d56c3c296d0aac1c9079 Mon Sep 17 00:00:00 2001 From: TsunayoshiSawada Date: Thu, 27 Aug 2020 14:53:17 +0000 Subject: [PATCH 11/11] Automated code formatting. --- .../modules/helper_funcs/msg_types.py | 14 +- SaitamaRobot/modules/misc.py | 9 +- SaitamaRobot/modules/sql/welcome_sql.py | 6 +- SaitamaRobot/modules/users.py | 12 +- SaitamaRobot/modules/welcome.py | 364 ++++++++---------- 5 files changed, 194 insertions(+), 211 deletions(-) diff --git a/SaitamaRobot/modules/helper_funcs/msg_types.py b/SaitamaRobot/modules/helper_funcs/msg_types.py index 59cab36c60..d6af1c380d 100644 --- a/SaitamaRobot/modules/helper_funcs/msg_types.py +++ b/SaitamaRobot/modules/helper_funcs/msg_types.py @@ -96,7 +96,8 @@ def get_welcome_type(msg: Message): else: args = msg.reply_to_message.caption else: - args = msg.text.split(None, 1) # use python's maxsplit to separate cmd and args + args = msg.text.split( + None, 1) # use python's maxsplit to separate cmd and args except AttributeError: args = False @@ -111,7 +112,8 @@ def get_welcome_type(msg: Message): data_type = Types.DOCUMENT elif msg.reply_to_message and msg.reply_to_message.photo: - content = msg.reply_to_message.photo[-1].file_id # last elem = best quality + content = msg.reply_to_message.photo[ + -1].file_id # last elem = best quality text = msg.reply_to_message.caption data_type = Types.PHOTO @@ -140,13 +142,15 @@ def get_welcome_type(msg: Message): if args: if msg.reply_to_message: argumen = msg.reply_to_message.caption if msg.reply_to_message.caption else "" - offset = 0 # offset is no need since target was in reply + offset = 0 # offset is no need since target was in reply entities = msg.reply_to_message.parse_entities() else: argumen = args[1] - offset = len(argumen) - len(msg.text) # set correct offset relative to command + notename + offset = len(argumen) - len( + msg.text) # set correct offset relative to command + notename entities = msg.parse_entities() - text, buttons = button_markdown_parser(argumen, entities=entities, offset=offset) + text, buttons = button_markdown_parser( + argumen, entities=entities, offset=offset) if not data_type: if text and buttons: diff --git a/SaitamaRobot/modules/misc.py b/SaitamaRobot/modules/misc.py index 159886d648..fd46840880 100644 --- a/SaitamaRobot/modules/misc.py +++ b/SaitamaRobot/modules/misc.py @@ -185,9 +185,14 @@ def echo(update: Update, context: CallbackContext): message = update.effective_message if message.reply_to_message: - message.reply_to_message.reply_text(args[1], parse_mode="MARKDOWN", disable_web_page_preview=True) + message.reply_to_message.reply_text( + args[1], parse_mode="MARKDOWN", disable_web_page_preview=True) else: - message.reply_text(args[1], quote=False, parse_mode="MARKDOWN", disable_web_page_preview=True) + message.reply_text( + args[1], + quote=False, + parse_mode="MARKDOWN", + disable_web_page_preview=True) message.delete() diff --git a/SaitamaRobot/modules/sql/welcome_sql.py b/SaitamaRobot/modules/sql/welcome_sql.py index a52976e6a0..91b7018e10 100644 --- a/SaitamaRobot/modules/sql/welcome_sql.py +++ b/SaitamaRobot/modules/sql/welcome_sql.py @@ -425,7 +425,11 @@ def set_gdbye_preference(chat_id, should_goodbye): SESSION.commit() -def set_custom_welcome(chat_id, custom_content, custom_welcome, welcome_type, buttons=None): +def set_custom_welcome(chat_id, + custom_content, + custom_welcome, + welcome_type, + buttons=None): if buttons is None: buttons = [] diff --git a/SaitamaRobot/modules/users.py b/SaitamaRobot/modules/users.py index 0e144d677a..f06d6fd646 100644 --- a/SaitamaRobot/modules/users.py +++ b/SaitamaRobot/modules/users.py @@ -67,14 +67,22 @@ def broadcast(update: Update, context: CallbackContext): if to_group: for chat in chats: try: - context.bot.sendMessage(int(chat.chat_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) + context.bot.sendMessage( + int(chat.chat_id), + to_send[1], + parse_mode="MARKDOWN", + disable_web_page_preview=True) sleep(0.1) except TelegramError: failed += 1 if to_user: for user in users: try: - context.bot.sendMessage(int(user.user_id), to_send[1], parse_mode="MARKDOWN", disable_web_page_preview=True) + context.bot.sendMessage( + int(user.user_id), + to_send[1], + parse_mode="MARKDOWN", + disable_web_page_preview=True) sleep(0.1) except TelegramError: failed_user += 1 diff --git a/SaitamaRobot/modules/welcome.py b/SaitamaRobot/modules/welcome.py index 7805f29eca..e0e223ad16 100644 --- a/SaitamaRobot/modules/welcome.py +++ b/SaitamaRobot/modules/welcome.py @@ -94,28 +94,27 @@ def send(update, message, keyboard, backup_message): if excp.message == "Button_url_invalid": msg = update.effective_message.reply_text( markdown_parser( - backup_message + "\nNote: the current message has an invalid url " - "in one of its buttons. Please update." - ), + backup_message + + "\nNote: the current message has an invalid url " + "in one of its buttons. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Unsupported url protocol": msg = update.effective_message.reply_text( - markdown_parser( - backup_message + "\nNote: the current message has buttons which " - "use url protocols that are unsupported by " - "telegram. Please update." - ), + markdown_parser(backup_message + + "\nNote: the current message has buttons which " + "use url protocols that are unsupported by " + "telegram. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) elif excp.message == "Wrong url host": msg = update.effective_message.reply_text( markdown_parser( - backup_message + "\nNote: the current message has some bad urls. " - "Please update." - ), + backup_message + + "\nNote: the current message has some bad urls. " + "Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) @@ -124,10 +123,9 @@ def send(update, message, keyboard, backup_message): LOGGER.exception("Could not parse! got invalid url host errors") else: msg = update.effective_message.reply_text( - markdown_parser( - backup_message + "\nNote: An error occured when sending the " - "custom message. Please update." - ), + markdown_parser(backup_message + + "\nNote: An error occured when sending the " + "custom message. Please update."), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) @@ -144,7 +142,8 @@ def new_member(update: Update, context: CallbackContext): user = update.effective_user msg = update.effective_message - should_welc, cust_welcome, cust_content, welc_type = sql.get_welc_pref(chat.id) + should_welc, cust_welcome, cust_content, welc_type = sql.get_welc_pref( + chat.id) welc_mutes = sql.welcome_mutes(chat.id) human_checks = sql.get_human_checks(user.id, chat.id) @@ -171,7 +170,8 @@ def new_member(update: Update, context: CallbackContext): # Clean service welcome if cleanserv: try: - dispatcher.bot.delete_message(chat.id, update.message.message_id) + dispatcher.bot.delete_message(chat.id, + update.message.message_id) except BadRequest: pass reply = False @@ -179,13 +179,11 @@ def new_member(update: Update, context: CallbackContext): # Give the owner a special welcome if new_mem.id == OWNER_ID: update.effective_message.reply_text( - "Oh, Genos? Let's get this moving.", reply_to_message_id=reply - ) - welcome_log = ( - f"{html.escape(chat.title)}\n" - f"#USER_JOINED\n" - f"Bot Owner just joined the chat" - ) + "Oh, Genos? Let's get this moving.", + reply_to_message_id=reply) + welcome_log = (f"{html.escape(chat.title)}\n" + f"#USER_JOINED\n" + f"Bot Owner just joined the chat") continue # Welcome Devs @@ -215,22 +213,21 @@ def new_member(update: Update, context: CallbackContext): # Welcome Whitelisted elif new_mem.id in TIGER_USERS: update.effective_message.reply_text( - "Oof! A Tiger disaster just joined!", reply_to_message_id=reply - ) + "Oof! A Tiger disaster just joined!", + reply_to_message_id=reply) continue # Welcome Tigers elif new_mem.id in WHITELIST_USERS: update.effective_message.reply_text( - "Oof! A Wolf disaster just joined!", reply_to_message_id=reply - ) + "Oof! A Wolf disaster just joined!", + reply_to_message_id=reply) continue # Welcome yourself elif new_mem.id == bot.id: update.effective_message.reply_text( - "Watashi ga kita!", reply_to_message_id=reply - ) + "Watashi ga kita!", reply_to_message_id=reply) continue else: @@ -247,23 +244,24 @@ def new_member(update: Update, context: CallbackContext): if cust_welcome: if cust_welcome == sql.DEFAULT_WELCOME: cust_welcome = random.choice( - sql.DEFAULT_WELCOME_MESSAGES - ).format(first=escape_markdown(first_name)) + sql.DEFAULT_WELCOME_MESSAGES).format( + first=escape_markdown(first_name)) if new_mem.last_name: - fullname = escape_markdown(f"{first_name} {new_mem.last_name}") + fullname = escape_markdown( + f"{first_name} {new_mem.last_name}") else: fullname = escape_markdown(first_name) count = chat.get_members_count() - mention = mention_markdown(new_mem.id, escape_markdown(first_name)) + mention = mention_markdown(new_mem.id, + escape_markdown(first_name)) if new_mem.username: username = "@" + escape_markdown(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets( - cust_welcome, VALID_WELCOME_FORMATTERS - ) + cust_welcome, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(new_mem.last_name or first_name), @@ -277,13 +275,12 @@ def new_member(update: Update, context: CallbackContext): else: res = random.choice(sql.DEFAULT_WELCOME_MESSAGES).format( - first=escape_markdown(first_name) - ) + first=escape_markdown(first_name)) keyb = [] - backup_message = random.choice(sql.DEFAULT_WELCOME_MESSAGES).format( - first=escape_markdown(first_name) - ) + backup_message = random.choice( + sql.DEFAULT_WELCOME_MESSAGES).format( + first=escape_markdown(first_name)) keyboard = InlineKeyboardMarkup(keyb) else: @@ -294,10 +291,8 @@ def new_member(update: Update, context: CallbackContext): reply = None # User exceptions from welcomemutes - if ( - is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)) - or human_checks - ): + if (is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)) + or human_checks): should_mute = False # Join welcome: soft mute if new_mem.is_bot: @@ -324,47 +319,39 @@ def new_member(update: Update, context: CallbackContext): if welc_mutes == "strong": welcome_bool = False if not media_wel: - VERIFIED_USER_WAITLIST.update( - { - new_mem.id: { - "should_welc": should_welc, - "media_wel": False, - "status": False, - "update": update, - "res": res, - "keyboard": keyboard, - "backup_message": backup_message, - } + VERIFIED_USER_WAITLIST.update({ + new_mem.id: { + "should_welc": should_welc, + "media_wel": False, + "status": False, + "update": update, + "res": res, + "keyboard": keyboard, + "backup_message": backup_message, } - ) + }) else: - VERIFIED_USER_WAITLIST.update( - { - new_mem.id: { - "should_welc": should_welc, - "chat_id": chat.id, - "status": False, - "media_wel": True, - "cust_content": cust_content, - "welc_type": welc_type, - "res": res, - "keyboard": keyboard, - } + VERIFIED_USER_WAITLIST.update({ + new_mem.id: { + "should_welc": should_welc, + "chat_id": chat.id, + "status": False, + "media_wel": True, + "cust_content": cust_content, + "welc_type": welc_type, + "res": res, + "keyboard": keyboard, } - ) + }) new_join_mem = f"[{escape_markdown(new_mem.first_name)}](tg://user?id={user.id})" message = msg.reply_text( f"{new_join_mem}, click the button below to prove you're human.\nYou have 120 seconds.", - reply_markup=InlineKeyboardMarkup( - [ - { - InlineKeyboardButton( - text="Yes, I'm human.", - callback_data=f"user_join_({new_mem.id})", - ) - } - ] - ), + reply_markup=InlineKeyboardMarkup([{ + InlineKeyboardButton( + text="Yes, I'm human.", + callback_data=f"user_join_({new_mem.id})", + ) + }]), parse_mode=ParseMode.MARKDOWN, reply_to_message_id=reply, ) @@ -383,7 +370,8 @@ def new_member(update: Update, context: CallbackContext): ), ) job_queue.run_once( - partial(check_not_bot, new_mem, chat.id, message.message_id), + partial(check_not_bot, new_mem, chat.id, + message.message_id), 120, name="welcomemute", ) @@ -413,12 +401,10 @@ def new_member(update: Update, context: CallbackContext): if welcome_log: return welcome_log - return ( - f"{html.escape(chat.title)}\n" - f"#USER_JOINED\n" - f"User: {mention_html(user.id, user.first_name)}\n" - f"ID: {user.id}" - ) + return (f"{html.escape(chat.title)}\n" + f"#USER_JOINED\n" + f"User: {mention_html(user.id, user.first_name)}\n" + f"ID: {user.id}") return "" @@ -459,7 +445,8 @@ def left_member(update: Update, context: CallbackContext): # Clean service welcome if cleanserv: try: - dispatcher.bot.delete_message(chat.id, update.message.message_id) + dispatcher.bot.delete_message(chat.id, + update.message.message_id) except BadRequest: pass reply = False @@ -484,8 +471,7 @@ def left_member(update: Update, context: CallbackContext): # Give the owner a special goodbye if left_mem.id == OWNER_ID: update.effective_message.reply_text( - "Oi! Genos! He left..", reply_to_message_id=reply - ) + "Oi! Genos! He left..", reply_to_message_id=reply) return # Give the devs a special goodbye @@ -501,16 +487,16 @@ def left_member(update: Update, context: CallbackContext): ENUM_FUNC_MAP[goodbye_type](chat.id, cust_goodbye) return - first_name = ( - left_mem.first_name or "PersonWithNoName" - ) # edge case of empty name - occurs for some bugs. + first_name = (left_mem.first_name or "PersonWithNoName" + ) # edge case of empty name - occurs for some bugs. if cust_goodbye: if cust_goodbye == sql.DEFAULT_GOODBYE: - cust_goodbye = random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format( - first=escape_markdown(first_name) - ) + cust_goodbye = random.choice( + sql.DEFAULT_GOODBYE_MESSAGES).format( + first=escape_markdown(first_name)) if left_mem.last_name: - fullname = escape_markdown(f"{first_name} {left_mem.last_name}") + fullname = escape_markdown( + f"{first_name} {left_mem.last_name}") else: fullname = escape_markdown(first_name) count = chat.get_members_count() @@ -521,8 +507,7 @@ def left_member(update: Update, context: CallbackContext): username = mention valid_format = escape_invalid_curly_brackets( - cust_goodbye, VALID_WELCOME_FORMATTERS - ) + cust_goodbye, VALID_WELCOME_FORMATTERS) res = valid_format.format( first=escape_markdown(first_name), last=escape_markdown(left_mem.last_name or first_name), @@ -537,9 +522,8 @@ def left_member(update: Update, context: CallbackContext): keyb = build_keyboard(buttons) else: - res = random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format( - first=first_name - ) + res = random.choice( + sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name) keyb = [] keyboard = InlineKeyboardMarkup(keyb) @@ -548,7 +532,8 @@ def left_member(update: Update, context: CallbackContext): update, res, keyboard, - random.choice(sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name), + random.choice( + sql.DEFAULT_GOODBYE_MESSAGES).format(first=first_name), ) @@ -582,7 +567,8 @@ def welcome(update: Update, context: CallbackContext): 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) + ENUM_FUNC_MAP[welcome_type]( + chat.id, cust_content, caption=welcome_m) else: keyb = build_keyboard(buttons) @@ -600,19 +586,16 @@ def welcome(update: Update, context: CallbackContext): 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." - ) + "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." - ) + "I'll go loaf around and not welcome anyone then.") else: update.effective_message.reply_text( - "I understand 'on/yes' or 'off/no' only!" - ) + "I understand 'on/yes' or 'off/no' only!") @run_async @@ -648,8 +631,7 @@ def goodbye(update: Update, context: CallbackContext): else: ENUM_FUNC_MAP[goodbye_type]( - chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN - ) + chat.id, goodbye_m, parse_mode=ParseMode.MARKDOWN) elif len(args) >= 1: if args[0].lower() in ("on", "yes"): @@ -663,8 +645,7 @@ def goodbye(update: Update, context: CallbackContext): else: # idek what you're writing, say yes or no update.effective_message.reply_text( - "I understand 'on/yes' or 'off/no' only!" - ) + "I understand 'on/yes' or 'off/no' only!") @run_async @@ -684,12 +665,10 @@ def set_welcome(update: Update, context: CallbackContext) -> str: sql.set_custom_welcome(chat.id, content, text, data_type, buttons) msg.reply_text("Successfully set custom welcome message!") - return ( - f"{html.escape(chat.title)}:\n" - f"#SET_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Set the welcome message." - ) + return (f"{html.escape(chat.title)}:\n" + f"#SET_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Set the welcome message.") @run_async @@ -701,15 +680,12 @@ def reset_welcome(update: Update, context: CallbackContext) -> str: sql.set_custom_welcome(chat.id, None, sql.DEFAULT_WELCOME, sql.Types.TEXT) update.effective_message.reply_text( - "Successfully reset welcome message to default!" - ) + "Successfully reset welcome message to default!") - return ( - f"{html.escape(chat.title)}:\n" - f"#RESET_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Reset the welcome message to default." - ) + return (f"{html.escape(chat.title)}:\n" + f"#RESET_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Reset the welcome message to default.") @run_async @@ -727,12 +703,10 @@ def set_goodbye(update: Update, context: CallbackContext) -> str: sql.set_custom_gdbye(chat.id, content or text, data_type, buttons) msg.reply_text("Successfully set custom goodbye message!") - return ( - f"{html.escape(chat.title)}:\n" - f"#SET_GOODBYE\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Set the goodbye message." - ) + return (f"{html.escape(chat.title)}:\n" + f"#SET_GOODBYE\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Set the goodbye message.") @run_async @@ -744,15 +718,12 @@ def reset_goodbye(update: Update, context: CallbackContext) -> str: sql.set_custom_gdbye(chat.id, sql.DEFAULT_GOODBYE, sql.Types.TEXT) update.effective_message.reply_text( - "Successfully reset goodbye message to default!" - ) + "Successfully reset goodbye message to default!") - return ( - f"{html.escape(chat.title)}:\n" - f"#RESET_GOODBYE\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Reset the goodbye message." - ) + return (f"{html.escape(chat.title)}:\n" + f"#RESET_GOODBYE\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Reset the goodbye message.") @run_async @@ -772,19 +743,16 @@ def welcomemute(update: Update, context: CallbackContext) -> str: f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to OFF." - ) + f"Has toggled welcome mute to OFF.") elif args[0].lower() in ["soft"]: sql.set_welcome_mutes(chat.id, "soft") msg.reply_text( - "I will restrict users' permission to send media for 24 hours." - ) + "I will restrict users' permission to send media for 24 hours.") return ( f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to SOFT." - ) + f"Has toggled welcome mute to SOFT.") elif args[0].lower() in ["strong"]: sql.set_welcome_mutes(chat.id, "strong") msg.reply_text( @@ -794,8 +762,7 @@ def welcomemute(update: Update, context: CallbackContext) -> str: f"{html.escape(chat.title)}:\n" f"#WELCOME_MUTE\n" f"• Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled welcome mute to STRONG." - ) + f"Has toggled welcome mute to STRONG.") else: msg.reply_text( "Please enter `off`/`no`/`soft`/`strong`!", @@ -806,8 +773,7 @@ def welcomemute(update: Update, context: CallbackContext) -> str: curr_setting = sql.welcome_mutes(chat.id) reply = ( f"\n Give me a setting!\nChoose one out of: `off`/`no` or `soft` or `strong` only! \n" - f"Current setting: `{curr_setting}`" - ) + f"Current setting: `{curr_setting}`") msg.reply_text(reply, parse_mode=ParseMode.MARKDOWN) return "" @@ -824,34 +790,31 @@ def clean_welcome(update: Update, context: CallbackContext) -> str: clean_pref = sql.get_clean_pref(chat.id) if clean_pref: update.effective_message.reply_text( - "I should be deleting welcome messages up to two days old." - ) + "I should be deleting welcome messages up to two days old.") else: update.effective_message.reply_text( - "I'm currently not deleting old welcome messages!" - ) + "I'm currently not deleting old welcome messages!") return "" if args[0].lower() in ("on", "yes"): sql.set_clean_welcome(str(chat.id), True) - update.effective_message.reply_text("I'll try to delete old welcome messages!") - return ( - f"{html.escape(chat.title)}:\n" - f"#CLEAN_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled clean welcomes to ON." - ) + update.effective_message.reply_text( + "I'll try to delete old welcome messages!") + return (f"{html.escape(chat.title)}:\n" + f"#CLEAN_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Has toggled clean welcomes to ON.") elif args[0].lower() in ("off", "no"): sql.set_clean_welcome(str(chat.id), False) - update.effective_message.reply_text("I won't delete old welcome messages.") - return ( - f"{html.escape(chat.title)}:\n" - f"#CLEAN_WELCOME\n" - f"Admin: {mention_html(user.id, user.first_name)}\n" - f"Has toggled clean welcomes to OFF." - ) + update.effective_message.reply_text( + "I won't delete old welcome messages.") + return (f"{html.escape(chat.title)}:\n" + f"#CLEAN_WELCOME\n" + f"Admin: {mention_html(user.id, user.first_name)}\n" + f"Has toggled clean welcomes to OFF.") else: - update.effective_message.reply_text("I understand 'on/yes' or 'off/no' only!") + update.effective_message.reply_text( + "I understand 'on/yes' or 'off/no' only!") return "" @@ -865,28 +828,26 @@ def cleanservice(update: Update, context: CallbackContext) -> str: var = args[0] if var in ("no", "off"): sql.set_clean_service(chat.id, False) - update.effective_message.reply_text("Welcome clean service is : off") + update.effective_message.reply_text( + "Welcome clean service is : off") elif var in ("yes", "on"): sql.set_clean_service(chat.id, True) - update.effective_message.reply_text("Welcome clean service is : on") + update.effective_message.reply_text( + "Welcome clean service is : on") else: update.effective_message.reply_text( - "Invalid option", parse_mode=ParseMode.MARKDOWN - ) + "Invalid option", parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( - "Usage is on/yes or off/no", parse_mode=ParseMode.MARKDOWN - ) + "Usage is on/yes or off/no", parse_mode=ParseMode.MARKDOWN) else: curr = sql.clean_service(chat.id) if curr: update.effective_message.reply_text( - "Welcome clean service is : on", parse_mode=ParseMode.MARKDOWN - ) + "Welcome clean service is : on", parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( - "Welcome clean service is : off", parse_mode=ParseMode.MARKDOWN - ) + "Welcome clean service is : off", parse_mode=ParseMode.MARKDOWN) @run_async @@ -973,8 +934,7 @@ def user_button(update: Update, context: CallbackContext): "go. Note that group ids are usually preceded by a `-` sign; this is required, so please don't " "remove it.\n" "You can even set images/gifs/videos/voice messages as the welcome message by " - "replying to the desired media, and calling `/setwelcome`." -) + "replying to the desired media, and calling `/setwelcome`.") WELC_MUTE_HELP_TXT = ( "You can get the bot to mute new people who join your group and hence prevent spambots from flooding your group. " @@ -989,15 +949,15 @@ def user_button(update: Update, context: CallbackContext): @run_async @user_admin def welcome_help(update: Update, context: CallbackContext): - update.effective_message.reply_text(WELC_HELP_TXT, parse_mode=ParseMode.MARKDOWN) + update.effective_message.reply_text( + WELC_HELP_TXT, parse_mode=ParseMode.MARKDOWN) @run_async @user_admin def welcome_mute_help(update: Update, context: CallbackContext): update.effective_message.reply_text( - WELC_MUTE_HELP_TXT, parse_mode=ParseMode.MARKDOWN - ) + WELC_MUTE_HELP_TXT, parse_mode=ParseMode.MARKDOWN) # TODO: get welcome data from group butler snap @@ -1019,10 +979,9 @@ def __migrate__(old_chat_id, new_chat_id): def __chat_settings__(chat_id, user_id): welcome_pref, _, _ = sql.get_welc_pref(chat_id) goodbye_pref, _, _ = sql.get_gdbye_pref(chat_id) - return ( - "This chat has it's welcome preference set to `{}`.\n" - "It's goodbye preference is `{}`.".format(welcome_pref, goodbye_pref) - ) + return ("This chat has it's welcome preference set to `{}`.\n" + "It's goodbye preference is `{}`.".format(welcome_pref, + goodbye_pref)) __help__ = """ @@ -1042,23 +1001,26 @@ def __chat_settings__(chat_id, user_id): • `/welcomehelp`*:* view more formatting information for custom welcome/goodbye messages. • `/cleanservice