Skip to content

Commit

Permalink
feat: convert bot username into lowercase (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias committed Mar 3, 2024
1 parent 15a308a commit a9cb87f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/telegram_checker.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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


Expand Down Expand Up @@ -50,18 +51,18 @@ 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:
print(f'There was a problem communicating with {bot["username"]}:', e)

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)
await make_request_to_telegram(f'@{bot["username"]}', 'Telegram', user_to_notify)

0 comments on commit a9cb87f

Please sign in to comment.