From 2182f5d02c2d242fc9eb17607adf24ce6597a445 Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Tue, 2 Apr 2024 22:30:01 +0300 Subject: [PATCH 1/9] Compat taghint by regex --- components/callbacks.py | 30 ++++++++++++++++++++++++++++++ components/const.py | 6 ++++++ rules_bot.py | 9 +++++++++ 3 files changed, 45 insertions(+) diff --git a/components/callbacks.py b/components/callbacks.py index f82ecad..a521152 100644 --- a/components/callbacks.py +++ b/components/callbacks.py @@ -507,3 +507,33 @@ async def command_token_warning(update: Update, context: ContextTypes.DEFAULT_TY if message.reply_to_message: await _token_warning(message.reply_to_message, context) + +async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """When someone posts an error message indicative of a compatibility issue: + Reply with the /compat taghint + """ + message = cast(Message, update.effective_message) + reply_to = message.reply_to_message + first_match = cast(int, MessageLimit.MAX_TEXT_LENGTH) + + # Get the compat hint + hint = TAG_HINTS["compat"] + + # Store the message + messages = hint.html_markup("compat") + # Store the keyboard + buttons = [ + [deepcopy(button) for button in row] for row in hint.inline_keyboard + ] + + keyboard = InlineKeyboardMarkup(buttons) + + effective_text = "\n➖\n".join(messages) + await message.reply_text( + effective_text, + reply_markup=keyboard, + reply_to_message_id=get_reply_id(update), + ) + + if reply_to and first_match == 0: + await try_to_delete(message) \ No newline at end of file diff --git a/components/const.py b/components/const.py index 8712d1e..78d4788 100644 --- a/components/const.py +++ b/components/const.py @@ -230,3 +230,9 @@ "associated with." ) TOKEN_TEXT = "⚠️ You posted a token, go revoke it with @BotFather.\n\n" + +COMPAT_ERRORS = re.compile( + r""" + (Updater\._{0,2}init_{0,2}\(\) got an )?unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* + """ +) \ No newline at end of file diff --git a/rules_bot.py b/rules_bot.py index ddce5b9..861e0ef 100644 --- a/rules_bot.py +++ b/rules_bot.py @@ -40,6 +40,7 @@ say_potato_command, start, tag_hint, + compat_warning, ) from components.const import ( ALLOWED_CHAT_IDS, @@ -49,6 +50,7 @@ OFFTOPIC_USERNAME, ONTOPIC_CHAT_ID, ONTOPIC_USERNAME, + COMPAT_ERRORS, ) from components.errorhandler import error_handler from components.joinrequests import join_request_buttons, join_request_callback @@ -169,6 +171,13 @@ def main() -> None: # Tag hints - works with regex application.add_handler(MessageHandler(TagHintFilter(), tag_hint)) + # Compat tag hint via regex + application.add_handler( + MessageHandler( + filters.Regex(COMPAT_ERRORS), compat_warning + ) + ) + # We need several matches so filters.REGEX is basically useless # therefore we catch everything and do regex ourselves application.add_handler( From c9eaed05eaa79d28b496497bf411f0e31d58b278 Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Tue, 2 Apr 2024 22:39:22 +0300 Subject: [PATCH 2/9] black fixes --- components/callbacks.py | 3 ++- components/const.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/callbacks.py b/components/callbacks.py index a521152..4795548 100644 --- a/components/callbacks.py +++ b/components/callbacks.py @@ -508,6 +508,7 @@ async def command_token_warning(update: Update, context: ContextTypes.DEFAULT_TY if message.reply_to_message: await _token_warning(message.reply_to_message, context) + async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """When someone posts an error message indicative of a compatibility issue: Reply with the /compat taghint @@ -536,4 +537,4 @@ async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> ) if reply_to and first_match == 0: - await try_to_delete(message) \ No newline at end of file + await try_to_delete(message) diff --git a/components/const.py b/components/const.py index 78d4788..ec2557c 100644 --- a/components/const.py +++ b/components/const.py @@ -233,6 +233,7 @@ COMPAT_ERRORS = re.compile( r""" - (Updater\._{0,2}init_{0,2}\(\) got an )?unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* + (Updater\._{0,2}init_{0,2}\(\) got an )? + unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* """ -) \ No newline at end of file +) From 29a7382e92fa80b07c6913db25b0562a59ab037b Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Tue, 2 Apr 2024 22:39:22 +0300 Subject: [PATCH 3/9] CI fixes --- components/callbacks.py | 10 ++++------ components/const.py | 5 +++-- rules_bot.py | 10 +++------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/components/callbacks.py b/components/callbacks.py index a521152..aa30e4a 100644 --- a/components/callbacks.py +++ b/components/callbacks.py @@ -508,7 +508,8 @@ async def command_token_warning(update: Update, context: ContextTypes.DEFAULT_TY if message.reply_to_message: await _token_warning(message.reply_to_message, context) -async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + +async def compat_warning(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: """When someone posts an error message indicative of a compatibility issue: Reply with the /compat taghint """ @@ -522,10 +523,7 @@ async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> # Store the message messages = hint.html_markup("compat") # Store the keyboard - buttons = [ - [deepcopy(button) for button in row] for row in hint.inline_keyboard - ] - + buttons = [[deepcopy(button) for button in row] for row in cast(InlineKeyboardMarkup, hint.inline_keyboard)] keyboard = InlineKeyboardMarkup(buttons) effective_text = "\n➖\n".join(messages) @@ -536,4 +534,4 @@ async def compat_warning(update: Update, context: ContextTypes.DEFAULT_TYPE) -> ) if reply_to and first_match == 0: - await try_to_delete(message) \ No newline at end of file + await try_to_delete(message) diff --git a/components/const.py b/components/const.py index 78d4788..ec2557c 100644 --- a/components/const.py +++ b/components/const.py @@ -233,6 +233,7 @@ COMPAT_ERRORS = re.compile( r""" - (Updater\._{0,2}init_{0,2}\(\) got an )?unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* + (Updater\._{0,2}init_{0,2}\(\) got an )? + unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* """ -) \ No newline at end of file +) diff --git a/rules_bot.py b/rules_bot.py index 861e0ef..385bb60 100644 --- a/rules_bot.py +++ b/rules_bot.py @@ -28,6 +28,7 @@ ban_sender_channels, buy, command_token_warning, + compat_warning, delete_message, leave_chat, off_on_topic, @@ -40,17 +41,16 @@ say_potato_command, start, tag_hint, - compat_warning, ) from components.const import ( ALLOWED_CHAT_IDS, ALLOWED_USERNAMES, + COMPAT_ERRORS, ERROR_CHANNEL_CHAT_ID, OFFTOPIC_CHAT_ID, OFFTOPIC_USERNAME, ONTOPIC_CHAT_ID, ONTOPIC_USERNAME, - COMPAT_ERRORS, ) from components.errorhandler import error_handler from components.joinrequests import join_request_buttons, join_request_callback @@ -172,11 +172,7 @@ def main() -> None: application.add_handler(MessageHandler(TagHintFilter(), tag_hint)) # Compat tag hint via regex - application.add_handler( - MessageHandler( - filters.Regex(COMPAT_ERRORS), compat_warning - ) - ) + application.add_handler(MessageHandler(filters.Regex(COMPAT_ERRORS), compat_warning)) # We need several matches so filters.REGEX is basically useless # therefore we catch everything and do regex ourselves From d715398c5c30fe29cc054a41c6cfcbec8b6e131a Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:27:30 +0200 Subject: [PATCH 4/9] Fix a bit --- components/callbacks.py | 18 ++---------------- components/const.py | 7 ++++--- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/components/callbacks.py b/components/callbacks.py index 810e7ce..f411cc0 100644 --- a/components/callbacks.py +++ b/components/callbacks.py @@ -514,25 +514,11 @@ async def compat_warning(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None: Reply with the /compat taghint """ message = cast(Message, update.effective_message) - reply_to = message.reply_to_message - first_match = cast(int, MessageLimit.MAX_TEXT_LENGTH) # Get the compat hint hint = TAG_HINTS["compat"] - # Store the message - messages = hint.html_markup("compat") - # Store the keyboard - buttons = [[deepcopy(button) for button in row] for row in cast(InlineKeyboardMarkup, hint.inline_keyboard)] - keyboard = InlineKeyboardMarkup(buttons) - - effective_text = "\n➖\n".join(messages) await message.reply_text( - effective_text, - reply_markup=keyboard, - reply_to_message_id=get_reply_id(update), + hint.html_markup(), + reply_markup=hint.inline_keyboard, ) - - if reply_to and first_match == 0: - await try_to_delete(message) - diff --git a/components/const.py b/components/const.py index ec2557c..790c57d 100644 --- a/components/const.py +++ b/components/const.py @@ -233,7 +233,8 @@ COMPAT_ERRORS = re.compile( r""" - (Updater\._{0,2}init_{0,2}\(\) got an )? - unexpected keyword argument ['"]*(use_context|token|use_controls|dispatcher)['"]* - """ + (Updater\._{0,2}init_{0,2}\(\)\ got\ an\ )? + unexpected\ keyword\ argument\ ['"]*(use_context|token|use_controls|dispatcher)['"]* + """, + flags=re.VERBOSE, ) From ff5bf5f250ba265ee445f9fd7d25494162735d9c Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Thu, 16 May 2024 22:59:16 +0300 Subject: [PATCH 5/9] update_queue compat error --- components/const.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/const.py b/components/const.py index 91ebf9c..968eff1 100644 --- a/components/const.py +++ b/components/const.py @@ -238,8 +238,9 @@ COMPAT_ERRORS = re.compile( r""" ( - (Updater\._{0,2}init_{0,2}\(\)\ got\ an\ )? - unexpected\ keyword\ argument\ ['"]*(use_context|token|use_controls|dispatcher)['"]* + (Updater\._{0,2}init_{0,2}\(\))? + (\ got\ an\ unexpected\ keyword\ argument\ ['"]*(use_context|token|use_controls|dispatcher)['"]*| + \ missing\ 1\ required\ positional\ argument:\ ['"]*update_queue['"]*) )|( updater\.(idle\(\)|dispatcher) )|( From 3131350a10b2993d947dd84782f05343b25a1b98 Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Sat, 18 May 2024 13:14:45 +0300 Subject: [PATCH 6/9] Fix line length, add the Filters error --- components/const.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/const.py b/components/const.py index 968eff1..9fd0e42 100644 --- a/components/const.py +++ b/components/const.py @@ -239,12 +239,18 @@ r""" ( (Updater\._{0,2}init_{0,2}\(\))? - (\ got\ an\ unexpected\ keyword\ argument\ ['"]*(use_context|token|use_controls|dispatcher)['"]*| - \ missing\ 1\ required\ positional\ argument:\ ['"]*update_queue['"]*) + ( + \ got\ an\ unexpected\ keyword\ argument\ + ['"]*(use_context|token|use_controls|dispatcher)['"]* + | + \ missing\ 1\ required\ positional\ argument:\ ['"]*update_queue['"]* + ) )|( updater\.(idle\(\)|dispatcher) )|( dispatcher.add_handler\( + )|( + cannot\ import\ name\ ['"]*Filters['"]* ) """, flags=re.VERBOSE, From c3af540df9e551c27c36d4947e04c389dd38ef09 Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Fri, 24 May 2024 17:15:03 +0300 Subject: [PATCH 7/9] Trailing whitespace fix --- components/const.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/const.py b/components/const.py index 9fd0e42..2195b06 100644 --- a/components/const.py +++ b/components/const.py @@ -240,8 +240,8 @@ ( (Updater\._{0,2}init_{0,2}\(\))? ( - \ got\ an\ unexpected\ keyword\ argument\ - ['"]*(use_context|token|use_controls|dispatcher)['"]* + \ got\ an\ unexpected\ keyword\ argument + \ ['"]*(use_context|token|use_controls|dispatcher)['"]* | \ missing\ 1\ required\ positional\ argument:\ ['"]*update_queue['"]* ) From fe8dae3e3c07e972f8e80dcce48e797d7fbb29f4 Mon Sep 17 00:00:00 2001 From: Mike WInfield Date: Fri, 24 May 2024 19:01:06 +0300 Subject: [PATCH 8/9] Bump python-Levenshtein version to 0.25.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f05947b..dceaf57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # pre-commit hooks for pylint & mypy beautifulsoup4~=4.11.0 thefuzz~=0.19.0 -python-Levenshtein~=0.12.0 +python-Levenshtein~=0.25.0 python-telegram-bot[job-queue]==20.2 Sphinx~=5.0.2 httpx~=0.23.0 From 4bbb4ca27dcc1668ad9b2069e7b6cb423b2d75c0 Mon Sep 17 00:00:00 2001 From: Mike Winfield Date: Fri, 24 May 2024 19:01:46 +0300 Subject: [PATCH 9/9] Revert "Bump python-Levenshtein version to 0.25.0" --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index dceaf57..f05947b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # pre-commit hooks for pylint & mypy beautifulsoup4~=4.11.0 thefuzz~=0.19.0 -python-Levenshtein~=0.25.0 +python-Levenshtein~=0.12.0 python-telegram-bot[job-queue]==20.2 Sphinx~=5.0.2 httpx~=0.23.0