mirror of
https://github.com/skoobasteeve/useful-scripts.git
synced 2026-03-19 23:28:55 +00:00
all example functions
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user