Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert bot username into lowercase #45

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading