refactor major
This commit is contained in:
82
_archiv/bot.py
Normal file
82
_archiv/bot.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import logging
|
||||
|
||||
from telegram.ext import CommandHandler, CallbackQueryHandler
|
||||
from telegram.ext import Updater
|
||||
from telegram import InlineKeyboardButton,InlineKeyboardMarkup
|
||||
from telegram.ext import MessageHandler, Filters
|
||||
from key import API_KEY
|
||||
from bot.states import CreatePostWorkflow
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello_world():
|
||||
return 'Hello, World!'
|
||||
|
||||
# Bot Updater that will poll
|
||||
updater = Updater(token=API_KEY, use_context=True)
|
||||
# The Dispatcher that get all the Handlers
|
||||
dispatcher = updater.dispatcher
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
logger.addHandler(ch)
|
||||
|
||||
workflows = {}
|
||||
|
||||
logger.info('initializing')
|
||||
def start(update, context):
|
||||
workflows[update.effective_chat.id]=CreatePostWorkflow(chat_id=update.effective_chat.id,context=context)
|
||||
logger.info("Start")
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
||||
|
||||
start_handler = CommandHandler('start', start)
|
||||
dispatcher.add_handler(start_handler)
|
||||
|
||||
def test(update, context):
|
||||
# workflows[update.effective_chat.id]=CreatePostWorkflow(chat_id=update.effective_chat.id,context=context)
|
||||
logger.info("Test")
|
||||
keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
|
||||
InlineKeyboardButton("Option 2", callback_data='2')],
|
||||
[InlineKeyboardButton("Option 3", callback_data='3')]]
|
||||
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text,reply_markup=InlineKeyboardMarkup(keyboard))
|
||||
|
||||
|
||||
dispatcher.add_handler( CommandHandler('test', test))
|
||||
|
||||
def echo(update,context):
|
||||
logger = logging.getLogger()
|
||||
# logger.info("echo")
|
||||
if update.effective_chat.id in workflows:
|
||||
# text= "Current State is: %s" % workflows[update.effective_chat.id].current_state
|
||||
# context.bot.send_message(chat_id=update.effective_chat.id, text=text)
|
||||
workflows[update.effective_chat.id].message_handler(update,context)
|
||||
|
||||
def command(update,context):
|
||||
if update.effective_chat.id in workflows:
|
||||
workflows[update.effective_chat.id].command_handler(update,context)
|
||||
|
||||
|
||||
def button(update, context):
|
||||
if update.effective_chat.id in workflows:
|
||||
workflows[update.effective_chat.id].button_handler(update,context)
|
||||
|
||||
#query = update.callback_query
|
||||
#query.edit_message_text(text="Selected option: {}".format(que#ry.data))
|
||||
|
||||
|
||||
dispatcher.add_handler(CallbackQueryHandler(button))
|
||||
|
||||
|
||||
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
|
||||
dispatcher.add_handler(echo_handler)
|
||||
|
||||
command_handler = MessageHandler(Filters.command, command)
|
||||
dispatcher.add_handler(command_handler)
|
||||
|
||||
|
||||
print("Added Echo")
|
||||
|
||||
updater.start_polling()
|
||||
#app.run()
|
||||
Reference in New Issue
Block a user