diff --git a/command.py b/command.py index 3e12892..991aef6 100644 --- a/command.py +++ b/command.py @@ -1,3 +1,4 @@ +from telegram.error import Unauthorized import parser import storage @@ -81,9 +82,18 @@ def notify_job(context): link['link'], link['last_ad_id'], link['name']) - except Exception as e: - context.bot.send_message(link['chat_id'], text=str(e)) + try: + context.bot.send_message(link['chat_id'], text=str(e)) + except Unauthorized: + remove_all(link['chat_id']) + + +def remove_all(chat_id): + try: + storage.remove_all(chat_id) + except Exception as e: + print(e) def get_user_links(update, context): diff --git a/storage.py b/storage.py index 07aa39f..17ff634 100644 --- a/storage.py +++ b/storage.py @@ -25,6 +25,11 @@ def update_last_ad_id(chat_id, link_name, last_ad_id): ) +def remove_all(chat_id): + query( + f"DELETE FROM settings WHERE chat_id = {chat_id}", True) + + def get_links(chat_id): links = query(f"SELECT * FROM settings WHERE chat_id = {chat_id}") if not any(links):