コード例 #1
0
ファイル: start.py プロジェクト: Divirad/pokemonadventurebot
    def start(self, bot: Bot, update: Update, trainer: Trainer,
              database: Database):
        """Start cmd"""
        id = update.message.from_user.id

        name = update.message.from_user.first_name
        data = update.message.text
        invcode = data[7:]

        if trainer.does_exist(database):
            if data.find("fancycode") != -1:
                self.daily_code(bot, update, trainer, database)
            else:
                self.already_registered(bot, update, trainer)

        else:
            if invcode != None and invcode != " " and invcode != "" and int(
                    invcode) != id:
                inviter = Trainer(int(invcode))
                if inviter.does_exist(database):
                    self.invite_code(bot, update, trainer, inviter, database)
                else:
                    self.invalid_invitation(bot, update, trainer, database)
            else:
                Trainer.create_new(database, id, name, 800)

            self.register_user(bot, update, trainer, database)
コード例 #2
0
 def handle(bot_p: Bot, update: Update, _cmd_handlers):
     with Database() as database:
         trainer = Trainer(update.message.from_user.id)
         menu_id = None
         if trainer.does_exist(database):
             trainer.load_values(values="menu_id", database=database)
             menu_id = trainer.menu_id
         if menu_id not in _cmd_handlers:
             return
         func = _cmd_handlers[menu_id]
         use_db = self.uses_db(func)
         if use_db:
             func(bot_p, update, trainer, database)
     if not use_db:
         func(bot_p, update, trainer)
コード例 #3
0
        def button_handle(bot_p: Bot, update: Update):
            id = ButtonId.from_string(update.callback_query.data)
            if id not in self.buttonHandlers:
                return
            bttn_handlers = self.buttonHandlers[id]
            with Database() as database:
                trainer = Trainer(update.callback_query.from_user.id)

                menu_id = None
                if trainer.does_exist(database):
                    trainer.load_values(values="menu_id", database=database)
                    menu_id = trainer.menu_id
                if menu_id not in bttn_handlers:
                    return
                func = bttn_handlers[menu_id]
                use_db = self.uses_db(func)
                if use_db:
                    func(bot_p, update, trainer, database)
            if not use_db:
                func(bot_p, update, trainer)