From 16e6f0f7209b4ee7508a64e3dc21e9bdf046e6d8 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 9 Nov 2018 01:53:34 +0530 Subject: [PATCH] Add nuke code with relevant checks. --- bot.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index ad69c16..ef5b029 100644 --- a/bot.py +++ b/bot.py @@ -8,7 +8,27 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \ def nuke(bot, update): - pass + if not update.message: + return + m = update.message + if m.chat.type == "private": + text = "This bot does not work in PM." + bot.send_message(chat_id=m.chat_id, text=text) + return + if not m.reply_to_message: + text = "You need to reply to a message." + bot.send_message(chat_id=m.chat_id, text=text) + user = bot.get_chat_member(m.chat.id, m.from_user.id) + if not user.can_delete_messages and user.status != "creator": + text = ('Only admins with "Delete Messages Permission" are allowed ' + 'to /nuke') + bot.send_message(chat_id=m.chat_id, text=text) + return + for i in range(m.reply_to_message.message_id, m.message_id + 1): + try: + bot.delete_message(m.chat_id, i) + except: + continue updater = Updater(token=config.api_key)