Add cancel command for edit
This commit is contained in:
parent
4f9841cc16
commit
b0e64a571e
2 changed files with 19 additions and 0 deletions
|
@ -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
17
commands/cancel.py
Normal 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)
|
Reference in a new issue