From 88aeaf222edfcd13e7de8d67c901652ab8e26893 Mon Sep 17 00:00:00 2001 From: Mike Shultz Date: Mon, 4 May 2020 18:05:26 -0600 Subject: [PATCH] also delete our own last message if it was a price message --- bot.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 0cb43c2..6f0a16e 100644 --- a/bot.py +++ b/bot.py @@ -263,6 +263,7 @@ class TelegramMonitorBot: # Cached token prices self.cached_prices = {} + self.last_message_out = None @MWT(timeout=60*60) @@ -599,9 +600,27 @@ class TelegramMonitorBot: update.effective_user.username, ) - bot.send_message(chat_id, message, parse_mode=telegram.ParseMode.MARKDOWN) + # If the last message we sent was price, delete it to reduce spam + if ( + self.last_message_out + and self.last_message_out.get('type') == 'price' + and self.last_message_out['message'].message_id + ): + bot.delete_message( + chat_id, + self.last_message_out['message'].message_id + ) - # Delete the command message + self.last_message_out = { + 'type': 'price', + 'message': bot.send_message( + chat_id, + message, + parse_mode=telegram.ParseMode.MARKDOWN + ), + } + + # Delete the command message as well try: bot.delete_message(chat_id, message_id) except Exception: