Add nuke code with relevant checks.

This commit is contained in:
Ceda EI 2018-11-09 01:53:34 +05:30
parent e11a0e17aa
commit 16e6f0f720
1 changed files with 21 additions and 1 deletions

22
bot.py
View File

@ -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)