Skip to content

Commit 8261fdb

Browse files
bqbackBibo-Joshi
andauthored
Automatically Trigger /compat TagHint by Regex (#131)
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
1 parent ef12e2c commit 8261fdb

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

components/callbacks.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,18 @@ async def command_token_warning(update: Update, context: ContextTypes.DEFAULT_TY
507507

508508
if message.reply_to_message:
509509
await _token_warning(message.reply_to_message, context)
510+
511+
512+
async def compat_warning(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
513+
"""When someone posts an error message indicative of a compatibility issue:
514+
Reply with the /compat taghint
515+
"""
516+
message = cast(Message, update.effective_message)
517+
518+
# Get the compat hint
519+
hint = TAG_HINTS["compat"]
520+
521+
await message.reply_text(
522+
hint.html_markup(),
523+
reply_markup=hint.inline_keyboard,
524+
)

components/const.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,11 @@
230230
"associated with."
231231
)
232232
TOKEN_TEXT = "⚠️ You posted a token, go revoke it with @BotFather.\n\n"
233+
234+
COMPAT_ERRORS = re.compile(
235+
r"""
236+
(Updater\._{0,2}init_{0,2}\(\)\ got\ an\ )?
237+
unexpected\ keyword\ argument\ ['"]*(use_context|token|use_controls|dispatcher)['"]*
238+
""",
239+
flags=re.VERBOSE,
240+
)

rules_bot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
ban_sender_channels,
2929
buy,
3030
command_token_warning,
31+
compat_warning,
3132
delete_message,
3233
leave_chat,
3334
off_on_topic,
@@ -44,6 +45,7 @@
4445
from components.const import (
4546
ALLOWED_CHAT_IDS,
4647
ALLOWED_USERNAMES,
48+
COMPAT_ERRORS,
4749
ERROR_CHANNEL_CHAT_ID,
4850
OFFTOPIC_CHAT_ID,
4951
OFFTOPIC_USERNAME,
@@ -169,6 +171,9 @@ def main() -> None:
169171
# Tag hints - works with regex
170172
application.add_handler(MessageHandler(TagHintFilter(), tag_hint))
171173

174+
# Compat tag hint via regex
175+
application.add_handler(MessageHandler(filters.Regex(COMPAT_ERRORS), compat_warning))
176+
172177
# We need several matches so filters.REGEX is basically useless
173178
# therefore we catch everything and do regex ourselves
174179
application.add_handler(

0 commit comments

Comments
 (0)