Archived
1
0
Fork 0

Add cancel command for edit

This commit is contained in:
Ethanell 2020-11-07 16:09:41 +01:00
parent 4f9841cc16
commit b0e64a571e
2 changed files with 19 additions and 0 deletions

View file

@ -1,5 +1,7 @@
from commands.cancel import cancel_handler
from commands.start import start_handler
from main import updater
updater.dispatcher.add_handler(start_handler)
updater.dispatcher.add_handler(cancel_handler)

17
commands/cancel.py Normal file
View file

@ -0,0 +1,17 @@
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import CallbackContext, CommandHandler
from main import messages
def cancel(update: Update, context: CallbackContext):
if update.effective_chat.id in messages and\
update["_effective_user"]["id"] in messages[update.effective_chat.id]:
del messages[update.effective_chat.id][update["_effective_user"]["id"]]
context.bot.send_message(chat_id=update.effective_chat.id,
text="Action canceled",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🏘 Home",
callback_data="home")]]))
cancel_handler = CommandHandler("cancel", cancel)