コード例 #1
0
 def __init__(self, token):
     self.log = get_logging()
     self.updater = Updater(token,
                            request_kwargs=REQUEST_KWARGS,
                            use_context=True)
     self.dispatcher = self.updater.dispatcher
     self.add_controllers()
     self.add_sending_events()
コード例 #2
0
ファイル: main_controller.py プロジェクト: FRiMN/hackaton
from telegram.ext import ConversationHandler, CommandHandler, RegexHandler, MessageHandler, Filters

from chat_bot.constants import Buttons
from chat_bot.utils import get_logging, send_typing_action
from chat_bot.view.main_view import MainView
logger = get_logging()


class MainController:
    name = 'main'

    def __init__(self, dispatcher, controllers=None):
        self.dispatcher = dispatcher
        self.view = MainView(bot=dispatcher.bot)
        # init child controllers
        if controllers:
            for controller in controllers:
                setattr(self, controller.name, controller)

        self.default_handlers = [
            CommandHandler(command="start", callback=self.main_menu),
            CommandHandler(command="help", callback=self.help),
            MessageHandler(Filters.text(Buttons.help), self.help),
            MessageHandler(Filters.text(Buttons.cancel), self.main_menu)
        ]

        self.__process_handlers()

    @send_typing_action
    def help(self, update, context):
        return self.view.help(update.message.chat_id)