diff --git a/movie-bot/moviebot.py b/movie-bot/moviebot.py index 19c5aef..1c44bfa 100644 --- a/movie-bot/moviebot.py +++ b/movie-bot/moviebot.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from telegram.ext import Updater, CommandHandler, CallbackContext +from telegram.ext import Updater, CommandHandler, CallbackContext, MessageHandler, Filters import logging from telegram import Update import os @@ -13,12 +13,36 @@ dispatcher = updater.dispatcher logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) + def start(update: Update, context: CallbackContext): context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!") + +def echo(update: Update, context: CallbackContext): + context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text) + + +def caps(update: Update, context: CallbackContext): + text_caps = ' '.join(context.args).upper() + context.bot.send_message(chat_id=update.effective_chat.id, text=text_caps) + + +def unknown(update: Update, context: CallbackContext): + context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.") + + start_handler = CommandHandler('start', start) dispatcher.add_handler(start_handler) +echo_handler = MessageHandler(Filters.text & (~Filters.command), echo) +dispatcher.add_handler(echo_handler) + +caps_handler = CommandHandler('caps', caps) +dispatcher.add_handler(caps_handler) + +unknown_handler = MessageHandler(Filters.command, unknown) +dispatcher.add_handler(unknown_handler) + updater.start_polling()