Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
feat: remove all links if user blocked the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Filipovsky committed Oct 14, 2022
1 parent abc2554 commit c3f2572
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from telegram.error import Unauthorized
import parser
import storage

Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c3f2572

Please sign in to comment.