From 6686833ab59591084094d09e0ddf0475b104bcd1 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 9 Aug 2019 12:24:09 +0200 Subject: [PATCH 1/3] ... sending text reports should of course be allowed. --- active_bots/telegrambot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 90bf906..6b1fd5b 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -38,11 +38,11 @@ class TelegramBot(Bot): "Sending Photos is not supported for privacy reasons. Can " "you describe it as text instead?") continue - if hasattr(update.message, 'text'): + if not hasattr(update.message, 'text'): tb.send_message( update.message.sender.id, - "We only support text only reporting for privacy reasons." - "Can you describe it as text instead?") + "We only support text reporting for privacy reasons. Can " + "you describe it as text instead?") continue if update.message.text.lower() == "/start": user.add_telegram_subscribers(update.message.sender.id) From 4f5f63b20fb97e902c5b2a2e9a973e0ed505d393 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 9 Aug 2019 14:35:01 +0200 Subject: [PATCH 2/3] logging telegram messages for debug purposes --- active_bots/telegrambot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index 6b1fd5b..cce5304 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -23,6 +23,7 @@ class TelegramBot(Bot): # return when telegram returns an error code if update in [303, 404, 420, 500, 502]: return reports + # log unusual telegram error messages if isinstance(update, int): try: logger.error("City " + str(user.uid) + @@ -44,6 +45,7 @@ class TelegramBot(Bot): "We only support text reporting for privacy reasons. Can " "you describe it as text instead?") continue + logger.error("TG Message has Text attribute: " + update.message.text) if update.message.text.lower() == "/start": user.add_telegram_subscribers(update.message.sender.id) tb.send_message( From e1d1bd91f868be84dc1fa4475e6bb4829ae70889 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 9 Aug 2019 14:41:14 +0200 Subject: [PATCH 3/3] fixing None TypeError --- active_bots/telegrambot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/active_bots/telegrambot.py b/active_bots/telegrambot.py index cce5304..c690b29 100644 --- a/active_bots/telegrambot.py +++ b/active_bots/telegrambot.py @@ -32,20 +32,22 @@ class TelegramBot(Bot): except TypeError: logger.error("Unknown Telegram error code: " + str(update)) return reports + # save the last message, so it doesn't get crawled again user.save_seen_tg(update.update_id) + # complain if message is a photo if update.message.photo: tb.send_message( update.message.sender.id, "Sending Photos is not supported for privacy reasons. Can " "you describe it as text instead?") continue - if not hasattr(update.message, 'text'): + # complain if message is a media file + if update.message.text is None: tb.send_message( update.message.sender.id, "We only support text reporting for privacy reasons. Can " "you describe it as text instead?") continue - logger.error("TG Message has Text attribute: " + update.message.text) if update.message.text.lower() == "/start": user.add_telegram_subscribers(update.message.sender.id) tb.send_message(