all example functions

This commit is contained in:
2022-03-29 18:35:21 -04:00
parent 57491f20a6
commit b20e037096

View File

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