Skip to content

Commit 835560b

Browse files
committed
remove users only when error equals unauthorized
Signed-off-by: call-me-matt <[email protected]>
1 parent 3873191 commit 835560b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/telegramHandler.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import os
55
import threading
6-
import time
76
import logging
87
import requests
98
import gettext
@@ -13,14 +12,13 @@
1312
import databaseHandler
1413

1514
from telegram.ext import CallbackContext
16-
1715
from telegram.ext import Updater
1816
from telegram.ext import CommandHandler, ConversationHandler
1917
from telegram.ext import MessageHandler, Filters
20-
from telegram.ext import JobQueue
18+
from telegram import error
2119

2220
TOKEN = os.environ['TELEGRAM_BOT_TOKEN']
23-
WATCHDOG_INTERVAL_MIN = 4*60
21+
WATCHDOG_INTERVAL_MIN = 6*60
2422

2523
STATE_FOLLOWS, STATE_UNFOLLOWS = range(2)
2624

@@ -163,9 +161,13 @@ def sendAlert(self, context, osmUser, number):
163161
alert = (_("🥳 %s has achieved more than %s changes!") % (osmUser, str(number)))
164162
try:
165163
context.bot.send_message(chat_id=chatId, text=alert)
166-
except:
167-
logger.warning("%s blocked chatId %s", telegramUser, chatId)
168-
databaseHandler.removeUser(telegramUser)
164+
except error.Unauthorized as e:
165+
if e.description == "Forbidden: bot was blocked by the user":
166+
logger.warning("%s blocked chatId %s", telegramUser, chatId)
167+
databaseHandler.removeUser(telegramUser)
168+
except Exception as e:
169+
logger.warning("Unexpected error while sending alert: %s", e.description)
170+
logger.debug(e)
169171

170172
def __init__(self):
171173
global TOKEN

0 commit comments

Comments
 (0)