From e39bd0b127250b4b836f957e26b5e56ac7955d8d Mon Sep 17 00:00:00 2001 From: Yasir-siddiqui Date: Thu, 7 Feb 2019 05:00:39 +0000 Subject: [PATCH] Every Command is Now DisableAble! && Cleanup! Signed-off-by: Yasir-siddiqui --- Procfile | 2 +- tg_bot/__main__.py | 9 +-- tg_bot/modules/admin.py | 10 +-- tg_bot/modules/antiflood.py | 5 +- tg_bot/modules/bans.py | 15 +++-- tg_bot/modules/blacklist.py | 4 +- tg_bot/modules/cust_filters.py | 4 +- tg_bot/modules/global_bans.py | 3 +- tg_bot/modules/global_mutes.py | 3 +- tg_bot/modules/locks.py | 6 +- tg_bot/modules/log_channel.py | 7 +- tg_bot/modules/msg_deleting.py | 6 +- tg_bot/modules/muting.py | 16 ++--- tg_bot/modules/reporting.py | 7 +- tg_bot/modules/rules.py | 6 +- tg_bot/modules/sed.py | 117 --------------------------------- tg_bot/modules/translation.py | 59 ----------------- tg_bot/modules/welcome.py | 9 +-- 18 files changed, 57 insertions(+), 231 deletions(-) delete mode 100644 tg_bot/modules/sed.py delete mode 100644 tg_bot/modules/translation.py diff --git a/Procfile b/Procfile index ad65e5a..c539110 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ web: python3 -m tg_bot -worker python3 -m tg_bot +worker: python3 -m tg_bot diff --git a/tg_bot/__main__.py b/tg_bot/__main__.py index 3f2fa7c..00f7804 100644 --- a/tg_bot/__main__.py +++ b/tg_bot/__main__.py @@ -17,6 +17,7 @@ from tg_bot.modules import ALL_MODULES from tg_bot.modules.helper_funcs.chat_status import is_user_admin from tg_bot.modules.helper_funcs.misc import paginate_modules +from tg_bot.modules.disable import DisableAbleCommandHandler PM_START_TEXT = """ Hi {}, My name is {}. @@ -405,15 +406,15 @@ def migrate_chats(bot: Bot, update: Update): def main(): test_handler = CommandHandler("test", test) - start_handler = CommandHandler("start", start, pass_args=True) + start_handler = DisableAbleCommandHandler("start", start, pass_args=True) - help_handler = CommandHandler("help", get_help) + help_handler = DisableAbleCommandHandler("help", get_help) help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_") - settings_handler = CommandHandler("settings", get_settings) + settings_handler = DisableAbleCommandHandler("settings", get_settings) settings_callback_handler = CallbackQueryHandler(settings_button, pattern=r"stngs_") - donate_handler = CommandHandler("donate", donate) + donate_handler = DisableAbleCommandHandler("donate", donate) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) diff --git a/tg_bot/modules/admin.py b/tg_bot/modules/admin.py index d601651..fbe7e23 100644 --- a/tg_bot/modules/admin.py +++ b/tg_bot/modules/admin.py @@ -230,13 +230,13 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "Admin" -PIN_HANDLER = CommandHandler("pin", pin, pass_args=True, filters=Filters.group) -UNPIN_HANDLER = CommandHandler("unpin", unpin, filters=Filters.group) +PIN_HANDLER = DisableAbleCommandHandler("pin", pin, pass_args=True, filters=Filters.group) +UNPIN_HANDLER = DisableAbleCommandHandler("unpin", unpin, filters=Filters.group) -INVITE_HANDLER = CommandHandler("invitelink", invite, filters=Filters.group) +INVITE_HANDLER = DisableAbleCommandHandler("invitelink", invite, filters=Filters.group) -PROMOTE_HANDLER = CommandHandler("promote", promote, pass_args=True, filters=Filters.group) -DEMOTE_HANDLER = CommandHandler("demote", demote, pass_args=True, filters=Filters.group) +PROMOTE_HANDLER = DisableAbleCommandHandler("promote", promote, pass_args=True, filters=Filters.group) +DEMOTE_HANDLER = DisableAbleCommandHandler("demote", demote, pass_args=True, filters=Filters.group) ADMINLIST_HANDLER = DisableAbleCommandHandler("adminlist", adminlist, filters=Filters.group) diff --git a/tg_bot/modules/antiflood.py b/tg_bot/modules/antiflood.py index ba760f7..307bd71 100644 --- a/tg_bot/modules/antiflood.py +++ b/tg_bot/modules/antiflood.py @@ -10,6 +10,7 @@ from tg_bot.modules.helper_funcs.chat_status import is_user_admin, user_admin, can_restrict from tg_bot.modules.log_channel import loggable from tg_bot.modules.sql import antiflood_sql as sql +from tg_bot.modules.disable import DisableAbleCommandHandler FLOOD_GROUP = 3 @@ -130,8 +131,8 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "AntiFlood" FLOOD_BAN_HANDLER = MessageHandler(Filters.all & ~Filters.status_update & Filters.group, check_flood) -SET_FLOOD_HANDLER = CommandHandler("setflood", set_flood, pass_args=True, filters=Filters.group) -FLOOD_HANDLER = CommandHandler("flood", flood, filters=Filters.group) +SET_FLOOD_HANDLER = DisableAbleCommandHandler("setflood", set_flood, pass_args=True, filters=Filters.group) +FLOOD_HANDLER = DisableAbleCommandHandler("flood", flood, filters=Filters.group) dispatcher.add_handler(FLOOD_BAN_HANDLER, FLOOD_GROUP) dispatcher.add_handler(SET_FLOOD_HANDLER) diff --git a/tg_bot/modules/bans.py b/tg_bot/modules/bans.py index 2043ebc..9626e53 100644 --- a/tg_bot/modules/bans.py +++ b/tg_bot/modules/bans.py @@ -288,19 +288,22 @@ def unban(bot: Bot, update: Update, args: List[str]) -> str: __help__ = """ - /kickme: kicks the user who issued the command. -*Admin only:* +*Admins only:* - /ban : bans a user. (via handle, or reply) - /tban x(m/h/d): bans a user for x time. (via handle, or reply). m = minutes, h = hours, d = days. - /unban : unbans a user. (via handle, or reply) - /kick : kicks a user, (via handle, or reply) + - /mute : silences a user. Can also be used as a reply, muting the replied to user. + - /tmute x(m/h/d): mutes a user for x time. (via handle, or reply). m = minutes, h = hours, d = days. + - /unmute : unmutes a user. Can also be used as a reply, muting the replied to user. """ -__mod_name__ = "Bans" +__mod_name__ = "Bans/Mutes" -BAN_HANDLER = CommandHandler("ban", ban, pass_args=True, filters=Filters.group) -TEMPBAN_HANDLER = CommandHandler(["tban", "tempban"], temp_ban, pass_args=True, filters=Filters.group) -KICK_HANDLER = CommandHandler("kick", kick, pass_args=True, filters=Filters.group) -UNBAN_HANDLER = CommandHandler("unban", unban, pass_args=True, filters=Filters.group) +BAN_HANDLER = DisableAbleCommandHandler("ban", ban, pass_args=True, filters=Filters.group) +TEMPBAN_HANDLER = DisableAbleCommandHandler(["tban", "tempban"], temp_ban, pass_args=True, filters=Filters.group) +KICK_HANDLER = DisableAbleCommandHandler("kick", kick, pass_args=True, filters=Filters.group) +UNBAN_HANDLER = DisableAbleCommandHandler("unban", unban, pass_args=True, filters=Filters.group) KICKME_HANDLER = DisableAbleCommandHandler("kickme", kickme, filters=Filters.group) dispatcher.add_handler(BAN_HANDLER) diff --git a/tg_bot/modules/blacklist.py b/tg_bot/modules/blacklist.py index dc912ce..10d2622 100644 --- a/tg_bot/modules/blacklist.py +++ b/tg_bot/modules/blacklist.py @@ -164,8 +164,8 @@ def __stats__(): BLACKLIST_HANDLER = DisableAbleCommandHandler("blacklist", blacklist, filters=Filters.group, pass_args=True, admin_ok=True) -ADD_BLACKLIST_HANDLER = CommandHandler("addblacklist", add_blacklist, filters=Filters.group) -UNBLACKLIST_HANDLER = CommandHandler(["unblacklist", "rmblacklist"], unblacklist, filters=Filters.group) +ADD_BLACKLIST_HANDLER = DisableAbleCommandHandler("addblacklist", add_blacklist, filters=Filters.group) +UNBLACKLIST_HANDLER = DisableAbleCommandHandler(["unblacklist", "rmblacklist"], unblacklist, filters=Filters.group) BLACKLIST_DEL_HANDLER = MessageHandler( (Filters.text | Filters.command | Filters.sticker | Filters.photo) & Filters.group, del_blacklist, edited_updates=True) diff --git a/tg_bot/modules/cust_filters.py b/tg_bot/modules/cust_filters.py index edc0e09..ded1119 100644 --- a/tg_bot/modules/cust_filters.py +++ b/tg_bot/modules/cust_filters.py @@ -222,8 +222,8 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "Filters" -FILTER_HANDLER = CommandHandler("filter", filters) -STOP_HANDLER = CommandHandler("stop", stop_filter) +FILTER_HANDLER = DisableAbleCommandHandler("filter", filters) +STOP_HANDLER = DisableAbleCommandHandler("stop", stop_filter) LIST_HANDLER = DisableAbleCommandHandler("filters", list_handlers, admin_ok=True) CUST_FILTER_HANDLER = MessageHandler(CustomFilters.has_text, reply_filter) diff --git a/tg_bot/modules/global_bans.py b/tg_bot/modules/global_bans.py index e0c5063..bdb2cdb 100644 --- a/tg_bot/modules/global_bans.py +++ b/tg_bot/modules/global_bans.py @@ -14,6 +14,7 @@ from tg_bot.modules.helper_funcs.filters import CustomFilters from tg_bot.modules.helper_funcs.misc import send_to_list from tg_bot.modules.sql.users_sql import get_all_chats +from tg_bot.modules.disable import DisableAbleCommandHandler GBAN_ENFORCE_GROUP = 6 @@ -314,7 +315,7 @@ def __chat_settings__(chat_id, user_id): GBAN_LIST = CommandHandler("gbanlist", gbanlist, filters=CustomFilters.sudo_filter | CustomFilters.support_filter) -GBAN_STATUS = CommandHandler("gbanstat", gbanstat, pass_args=True, filters=Filters.group) +GBAN_STATUS = DisableAbleCommandHandler("gbanstat", gbanstat, pass_args=True, filters=Filters.group) GBAN_ENFORCER = MessageHandler(Filters.all & Filters.group, enforce_gban) diff --git a/tg_bot/modules/global_mutes.py b/tg_bot/modules/global_mutes.py index 99e3539..5c2e80f 100644 --- a/tg_bot/modules/global_mutes.py +++ b/tg_bot/modules/global_mutes.py @@ -14,6 +14,7 @@ from tg_bot.modules.helper_funcs.filters import CustomFilters from tg_bot.modules.helper_funcs.misc import send_to_list from tg_bot.modules.sql.users_sql import get_all_chats +from tg_bot.modules.disable import DisableAbleCommandHandler GMUTE_ENFORCE_GROUP = 6 @@ -309,7 +310,7 @@ def __chat_settings__(chat_id, user_id): GMUTE_LIST = CommandHandler("gmutelist", gmutelist, filters=CustomFilters.sudo_filter | CustomFilters.support_filter) -GMUTE_STATUS = CommandHandler("gmutestat", gmutestat, pass_args=True, filters=Filters.group) +GMUTE_STATUS = DisableAbleCommandHandler("gmutestat", gmutestat, pass_args=True, filters=Filters.group) GMUTE_ENFORCER = MessageHandler(Filters.all & Filters.group, enforce_gmute) diff --git a/tg_bot/modules/locks.py b/tg_bot/modules/locks.py index a01d534..1158531 100644 --- a/tg_bot/modules/locks.py +++ b/tg_bot/modules/locks.py @@ -307,9 +307,9 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "Locks" LOCKTYPES_HANDLER = DisableAbleCommandHandler("locktypes", locktypes) -LOCK_HANDLER = CommandHandler("lock", lock, pass_args=True, filters=Filters.group) -UNLOCK_HANDLER = CommandHandler("unlock", unlock, pass_args=True, filters=Filters.group) -LOCKED_HANDLER = CommandHandler("locks", list_locks, filters=Filters.group) +LOCK_HANDLER = DisableAbleCommandHandler("lock", lock, pass_args=True, filters=Filters.group) +UNLOCK_HANDLER = DisableAbleCommandHandler("unlock", unlock, pass_args=True, filters=Filters.group) +LOCKED_HANDLER = DisableAbleCommandHandler("locks", list_locks, filters=Filters.group) dispatcher.add_handler(LOCK_HANDLER) dispatcher.add_handler(UNLOCK_HANDLER) diff --git a/tg_bot/modules/log_channel.py b/tg_bot/modules/log_channel.py index 0be89d7..35f9184 100644 --- a/tg_bot/modules/log_channel.py +++ b/tg_bot/modules/log_channel.py @@ -2,6 +2,7 @@ from typing import Optional from tg_bot.modules.helper_funcs.misc import is_module_loaded +from tg_bot.modules.disable import DisableAbleCommandHandler FILENAME = __name__.rsplit(".", 1)[-1] @@ -156,9 +157,9 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "Log Channels" - LOG_HANDLER = CommandHandler("logchannel", logging) - SET_LOG_HANDLER = CommandHandler("setlog", setlog) - UNSET_LOG_HANDLER = CommandHandler("unsetlog", unsetlog) + LOG_HANDLER = DisableAbleCommandHandler("logchannel", logging) + SET_LOG_HANDLER = DisableAbleCommandHandler("setlog", setlog) + UNSET_LOG_HANDLER = DisableAbleCommandHandler("unsetlog", unsetlog) dispatcher.add_handler(LOG_HANDLER) dispatcher.add_handler(SET_LOG_HANDLER) diff --git a/tg_bot/modules/msg_deleting.py b/tg_bot/modules/msg_deleting.py index 0fcfce4..777ddaa 100644 --- a/tg_bot/modules/msg_deleting.py +++ b/tg_bot/modules/msg_deleting.py @@ -10,7 +10,7 @@ from tg_bot import dispatcher, LOGGER from tg_bot.modules.helper_funcs.chat_status import user_admin, can_delete from tg_bot.modules.log_channel import loggable - +from tg_bot.modules.disable import DisableAbleCommandHandler @run_async @user_admin @@ -90,8 +90,8 @@ def del_message(bot: Bot, update: Update) -> str: __mod_name__ = "Purges" -DELETE_HANDLER = CommandHandler("del", del_message, filters=Filters.group) -PURGE_HANDLER = CommandHandler("purge", purge, filters=Filters.group, pass_args=True) +DELETE_HANDLER = DisableAbleCommandHandler("del", del_message, filters=Filters.group) +PURGE_HANDLER = DisableAbleCommandHandler("purge", purge, filters=Filters.group, pass_args=True) dispatcher.add_handler(DELETE_HANDLER) dispatcher.add_handler(PURGE_HANDLER) diff --git a/tg_bot/modules/muting.py b/tg_bot/modules/muting.py index c460f39..a51933f 100644 --- a/tg_bot/modules/muting.py +++ b/tg_bot/modules/muting.py @@ -12,6 +12,7 @@ from tg_bot.modules.helper_funcs.extraction import extract_user, extract_user_and_text from tg_bot.modules.helper_funcs.string_handling import extract_time from tg_bot.modules.log_channel import loggable +from tg_bot.modules.disable import DisableAbleCommandHandler @run_async @@ -183,18 +184,9 @@ def temp_mute(bot: Bot, update: Update, args: List[str]) -> str: return "" -__help__ = """ -*Admin only:* - - /mute : silences a user. Can also be used as a reply, muting the replied to user. - - /tmute x(m/h/d): mutes a user for x time. (via handle, or reply). m = minutes, h = hours, d = days. - - /unmute : unmutes a user. Can also be used as a reply, muting the replied to user. -""" - -__mod_name__ = "Muting" - -MUTE_HANDLER = CommandHandler("mute", mute, pass_args=True, filters=Filters.group) -UNMUTE_HANDLER = CommandHandler("unmute", unmute, pass_args=True, filters=Filters.group) -TEMPMUTE_HANDLER = CommandHandler(["tmute", "tempmute"], temp_mute, pass_args=True, filters=Filters.group) +MUTE_HANDLER = DisableAbleCommandHandler("mute", mute, pass_args=True, filters=Filters.group) +UNMUTE_HANDLER = DisableAbleCommandHandler("unmute", unmute, pass_args=True, filters=Filters.group) +TEMPMUTE_HANDLER = DisableAbleCommandHandler(["tmute", "tempmute"], temp_mute, pass_args=True, filters=Filters.group) dispatcher.add_handler(MUTE_HANDLER) dispatcher.add_handler(UNMUTE_HANDLER) diff --git a/tg_bot/modules/reporting.py b/tg_bot/modules/reporting.py index 94ee362..2bfb702 100644 --- a/tg_bot/modules/reporting.py +++ b/tg_bot/modules/reporting.py @@ -10,6 +10,7 @@ from tg_bot.modules.helper_funcs.chat_status import user_not_admin, user_admin from tg_bot.modules.log_channel import loggable from tg_bot.modules.sql import reporting_sql as sql +from tg_bot.modules.disable import DisableAbleCommandHandler REPORT_GROUP = 5 @@ -20,7 +21,7 @@ def report_setting(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] - if chat.type == chat.PRIVATE: + if chat.type == chat.PRIVlATE: if len(args) >= 1: if args[0] in ("yes", "on"): sql.set_user_setting(chat.id, True) @@ -133,8 +134,8 @@ def __user_settings__(user_id): - If in chat, toggles that chat's status. """ -REPORT_HANDLER = CommandHandler("report", report, filters=Filters.group) -SETTING_HANDLER = CommandHandler("reports", report_setting, pass_args=True) +REPORT_HANDLER = DisableAbleCommandHandler("report", report, filters=Filters.group) +SETTING_HANDLER = DisableAbleCommandHandler("reports", report_setting, pass_args=True) ADMIN_REPORT_HANDLER = RegexHandler("(?i)@admin(s)?", report) dispatcher.add_handler(REPORT_HANDLER, REPORT_GROUP) diff --git a/tg_bot/modules/rules.py b/tg_bot/modules/rules.py index 9dd1061..ae39a23 100644 --- a/tg_bot/modules/rules.py +++ b/tg_bot/modules/rules.py @@ -10,7 +10,7 @@ from tg_bot import dispatcher from tg_bot.modules.helper_funcs.chat_status import user_admin from tg_bot.modules.helper_funcs.string_handling import markdown_parser - +from tg_bot.modules.disable import DisableAbleCommandHandler @run_async def get_rules(bot: Bot, update: Update): @@ -103,8 +103,8 @@ def __chat_settings__(chat_id, user_id): __mod_name__ = "Rules" -GET_RULES_HANDLER = CommandHandler("rules", get_rules, filters=Filters.group) -SET_RULES_HANDLER = CommandHandler("setrules", set_rules, filters=Filters.group) +GET_RULES_HANDLER = DisableAbleCommandHandler("rules", get_rules, filters=Filters.group) +SET_RULES_HANDLER = DisableAbleCommandHandler("setrules", set_rules, filters=Filters.group) RESET_RULES_HANDLER = CommandHandler("clearrules", clear_rules, filters=Filters.group) dispatcher.add_handler(GET_RULES_HANDLER) diff --git a/tg_bot/modules/sed.py b/tg_bot/modules/sed.py deleted file mode 100644 index 3758c90..0000000 --- a/tg_bot/modules/sed.py +++ /dev/null @@ -1,117 +0,0 @@ -import re -import sre_constants - -import telegram -from telegram import Update, Bot -from telegram.ext import run_async - -from tg_bot import dispatcher, LOGGER -from tg_bot.modules.disable import DisableAbleRegexHandler - -DELIMITERS = ("/", ":", "|", "_") - - -def separate_sed(sed_string): - if len(sed_string) >= 3 and sed_string[1] in DELIMITERS and sed_string.count(sed_string[1]) >= 2: - delim = sed_string[1] - start = counter = 2 - while counter < len(sed_string): - if sed_string[counter] == "\\": - counter += 1 - - elif sed_string[counter] == delim: - replace = sed_string[start:counter] - counter += 1 - start = counter - break - - counter += 1 - - else: - return None - - while counter < len(sed_string): - if sed_string[counter] == "\\" and counter + 1 < len(sed_string) and sed_string[counter + 1] == delim: - sed_string = sed_string[:counter] + sed_string[counter + 1:] - - elif sed_string[counter] == delim: - replace_with = sed_string[start:counter] - counter += 1 - break - - counter += 1 - else: - return replace, sed_string[start:], "" - - flags = "" - if counter < len(sed_string): - flags = sed_string[counter:] - return replace, replace_with, flags.lower() - - -@run_async -def sed(bot: Bot, update: Update): - sed_result = separate_sed(update.effective_message.text) - if sed_result and update.effective_message.reply_to_message: - if update.effective_message.reply_to_message.text: - to_fix = update.effective_message.reply_to_message.text - elif update.effective_message.reply_to_message.caption: - to_fix = update.effective_message.reply_to_message.caption - else: - return - - repl, repl_with, flags = sed_result - - if not repl: - update.effective_message.reply_to_message.reply_text("You're trying to replace... " - "nothing with something?") - return - - try: - check = re.match(repl, to_fix, flags=re.IGNORECASE) - - if check and check.group(0).lower() == to_fix.lower(): - update.effective_message.reply_to_message.reply_text("Hey everyone, {} is trying to make " - "me say stuff I don't wanna " - "say!".format(update.effective_user.first_name)) - return - - if 'i' in flags and 'g' in flags: - text = re.sub(repl, repl_with, to_fix, flags=re.I).strip() - elif 'i' in flags: - text = re.sub(repl, repl_with, to_fix, count=1, flags=re.I).strip() - elif 'g' in flags: - text = re.sub(repl, repl_with, to_fix).strip() - else: - text = re.sub(repl, repl_with, to_fix, count=1).strip() - except sre_constants.error: - LOGGER.warning(update.effective_message.text) - LOGGER.exception("SRE constant error") - update.effective_message.reply_text("Do you even sed? Apparently not.") - return - - # empty string errors -_- - if len(text) >= telegram.MAX_MESSAGE_LENGTH: - update.effective_message.reply_text("The result of the sed command was too long for \ - telegram!") - elif text: - update.effective_message.reply_to_message.reply_text(text) - - -__help__ = """ - - s//(/): Reply to a message with this to perform a sed operation on that message, replacing all \ -occurrences of 'text1' with 'text2'. Flags are optional, and currently include 'i' for ignore case, 'g' for global, \ -or nothing. Delimiters include `/`, `_`, `|`, and `:`. Text grouping is supported. The resulting message cannot be \ -larger than {}. - -*Reminder:* Sed uses some special characters to make matching easier, such as these: `+*.?\\` -If you want to use these characters, make sure you escape them! -eg: \\?. -""".format(telegram.MAX_MESSAGE_LENGTH) - -__mod_name__ = "Sed/Regex" - - -SED_HANDLER = DisableAbleRegexHandler(r's([{}]).*?\1.*'.format("".join(DELIMITERS)), sed, friendly="sed") - -dispatcher.add_handler(SED_HANDLER) diff --git a/tg_bot/modules/translation.py b/tg_bot/modules/translation.py deleted file mode 100644 index 8b2a3b8..0000000 --- a/tg_bot/modules/translation.py +++ /dev/null @@ -1,59 +0,0 @@ -import json -from pprint import pprint - -import requests -from telegram import Update, Bot -from telegram.ext import CommandHandler - -from tg_bot import dispatcher - -# Open API key -API_KEY = "6ae0c3a0-afdc-4532-a810-82ded0054236" -URL = "http://services.gingersoftware.com/Ginger/correct/json/GingerTheText" - - -def translate(bot: Bot, update: Update): - if update.effective_message.reply_to_message: - msg = update.effective_message.reply_to_message - - params = dict( - lang="US", - clientVersion="2.0", - apiKey=API_KEY, - text=msg.text - ) - - res = requests.get(URL, params=params) - # print(res) - # print(res.text) - pprint(json.loads(res.text)) - changes = json.loads(res.text).get('LightGingerTheTextResult') - curr_string = "" - - prev_end = 0 - - for change in changes: - start = change.get('From') - end = change.get('To') + 1 - suggestions = change.get('Suggestions') - if suggestions: - sugg_str = suggestions[0].get('Text') # should look at this list more - curr_string += msg.text[prev_end:start] + sugg_str - - prev_end = end - - curr_string += msg.text[prev_end:] - print(curr_string) - update.effective_message.reply_text(curr_string) - - -__help__ = """ - - /t: while replying to a message, will reply with a grammar corrected version -""" - -__mod_name__ = "Translator" - - -TRANSLATE_HANDLER = CommandHandler('t', translate) - -dispatcher.add_handler(TRANSLATE_HANDLER) diff --git a/tg_bot/modules/welcome.py b/tg_bot/modules/welcome.py index 9ee5cc3..e2ececa 100644 --- a/tg_bot/modules/welcome.py +++ b/tg_bot/modules/welcome.py @@ -16,6 +16,7 @@ from tg_bot.modules.helper_funcs.string_handling import markdown_parser, \ escape_invalid_curly_brackets from tg_bot.modules.log_channel import loggable +from tg_bot.modules.disable import DisableAbleCommandHandler VALID_WELCOME_FORMATTERS = ['first', 'last', 'fullname', 'username', 'id', 'count', 'chatname', 'mention'] @@ -556,16 +557,16 @@ def __chat_settings__(bot, update, chat, chatP, user): NEW_MEM_HANDLER = MessageHandler(Filters.status_update.new_chat_members, new_member) LEFT_MEM_HANDLER = MessageHandler(Filters.status_update.left_chat_member, left_member) -WELC_PREF_HANDLER = CommandHandler("welcome", welcome, pass_args=True, filters=Filters.group) -GOODBYE_PREF_HANDLER = CommandHandler("goodbye", goodbye, pass_args=True, filters=Filters.group) +WELC_PREF_HANDLER = DisableAbleCommandHandler("welcome", welcome, pass_args=True, filters=Filters.group) +GOODBYE_PREF_HANDLER = DisableAbleCommandHandler("goodbye", goodbye, pass_args=True, filters=Filters.group) SET_WELCOME = CommandHandler("setwelcome", set_welcome, filters=Filters.group) SET_GOODBYE = CommandHandler("setgoodbye", set_goodbye, filters=Filters.group) RESET_WELCOME = CommandHandler("resetwelcome", reset_welcome, filters=Filters.group) RESET_GOODBYE = CommandHandler("resetgoodbye", reset_goodbye, filters=Filters.group) CLEAN_WELCOME = CommandHandler("cleanwelcome", clean_welcome, pass_args=True, filters=Filters.group) -SECURITY_HANDLER = CommandHandler("welcomesecurity", security, pass_args=True, filters=Filters.group) -CLEAN_SERVICE_HANDLER = CommandHandler("cleanservice", cleanservice, pass_args=True, filters=Filters.group) +SECURITY_HANDLER = DisableAbleCommandHandler("welcomesecurity", security, pass_args=True, filters=Filters.group) +CLEAN_SERVICE_HANDLER = DisableAbleCommandHandler("cleanservice", cleanservice, pass_args=True, filters=Filters.group) help_callback_handler = CallbackQueryHandler(check_bot_button, pattern=r"check_bot_")