From b0e64a571e590c2fac692703f12a2bd481a7c127 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 7 Nov 2020 16:09:41 +0100 Subject: [PATCH] Add cancel command for edit --- commands/__init__.py | 2 ++ commands/cancel.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 commands/cancel.py diff --git a/commands/__init__.py b/commands/__init__.py index 301f198..ef12f92 100644 --- a/commands/__init__.py +++ b/commands/__init__.py @@ -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) diff --git a/commands/cancel.py b/commands/cancel.py new file mode 100644 index 0000000..0c3ee8b --- /dev/null +++ b/commands/cancel.py @@ -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)