From f54afc8a249e3b5c192f97bfe0de804e97cc0c3a Mon Sep 17 00:00:00 2001 From: Helias Date: Sun, 3 Mar 2024 23:10:28 +0100 Subject: [PATCH] feat: convert bot username into lowercase --- src/telegram_checker.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/telegram_checker.py b/src/telegram_checker.py index f39d455..e1afef8 100644 --- a/src/telegram_checker.py +++ b/src/telegram_checker.py @@ -1,9 +1,10 @@ +from asyncio import run, sleep +from os.path import exists + from pyrogram import Client, filters -from pyrogram.handlers import MessageHandler from pyrogram.errors import RPCError +from pyrogram.handlers import MessageHandler from pyrogram.types import Message -from os.path import exists -from asyncio import sleep, run config_map = None received_answer = [] @@ -12,9 +13,9 @@ async def check_welcome(_: Client, message: Message) -> None: global received_answer for bots_to_check in config_map['bots_to_check']: - if message.from_user.username == bots_to_check['username']: + if message.from_user.username.lower() == bots_to_check["username"].lower(): if bots_to_check['expected_response'] in message.text: - received_answer.insert(0, message.from_user.username) + received_answer.insert(0, message.from_user.username.lower()) return @@ -50,7 +51,7 @@ async def main(app: Client) -> None: if not all(key in bot for key in ['username', 'command', 'expected_response']): print(f'Skipping {bot["username"] if "id" in bot else "a bot without a specified username c:"}') continue - + try: await app.send_message(chat_id=bot['username'], text=bot['command']) except RPCError as e: @@ -58,10 +59,10 @@ async def main(app: Client) -> None: await sleep(10) # Just to be sure the bot is not busy # To prevent circular imports - # TODO: in a future refactor we could split the main code in another file only for webpages, + # TODO: in a future refactor we could split the main code in another file only for webpages, # would improve modularity and reuse of code with an helper file from .main import make_request_to_telegram for bot in config_map['bots_to_check']: - if bot['username'] not in received_answer: + if bot["username"].lower() not in received_answer: for user_to_notify in config_map['chat_ids']: - await make_request_to_telegram(f'@{bot["username"]}', 'Telegram', user_to_notify) \ No newline at end of file + await make_request_to_telegram(f'@{bot["username"]}', 'Telegram', user_to_notify)