コード例 #1
0
ファイル: routes.py プロジェクト: luchnck/tlg_bot
    def do(self):
        user = User(self._app.db, self._template)
        user.chat_id = ''.join(filter(str.isdigit,str(self.message['message']['chat']['id'])))
        conterQuery = { 
                        'chat_id' : self.message['message']['chat']['id'],
                        'text'    : ''
                      }

        yield user.selectThis()
        logging.debug("startAction.do():gotted user from db is %s " % str(user.chat_id))
        if user.game_id != '':
            conterQuery['text'] = 'You are already registered!!! Then task'
        else:
            
            user.game_id = 3

            yield user.insertThis()
            conterQuery['text'] = 'You will be registered in system, task will be sended in seconds!!!'
        
        game = Game(self._app.db, self._template)
        game.id = user.game_id
        yield game.selectThis()
        
        task = Task(self._app.db,self._template)
        task.id = user.getTask()
        if task.id is False:
            conterQuery['text'] = "Task list is empty, may be game over???"
            raise tornado.gen.Return(conterQuery)

        yield task.selectThis() 
        
        conterQuery['text'] = task.text
        
        raise tornado.gen.Return(conterQuery)
コード例 #2
0
    def do(self):
        user = User(self._app.db, self._template)
        user.chat_id = ''.join(
            filter(str.isdigit, str(self.message['message']['chat']['id'])))
        conterQuery = {
            'chat_id': self.message['message']['chat']['id'],
            'text': ''
        }

        yield user.selectThis()
        logging.debug("startAction.do():gotted user from db is %s " %
                      str(user.chat_id))
        if user.game_id != '':
            conterQuery['text'] = 'You are already registered!!! Then task'
        else:

            user.game_id = 3

            yield user.insertThis()
            conterQuery[
                'text'] = 'You will be registered in system, task will be sended in seconds!!!'

        game = Game(self._app.db, self._template)
        game.id = user.game_id
        yield game.selectThis()

        task = Task(self._app.db, self._template)
        task.id = user.getTask()
        if task.id is False:
            conterQuery['text'] = "Task list is empty, may be game over???"
            raise tornado.gen.Return(conterQuery)

        yield task.selectThis()

        conterQuery['text'] = task.text

        raise tornado.gen.Return(conterQuery)
コード例 #3
0
ファイル: routes.py プロジェクト: luchnck/tlg_bot
    def do(self):
        user = User(self._app.db,self._template)
        user.chat_id = ''.join(filter(str.isdigit,str(self.message['message']['chat']['id'])))
        find = re.match("/answer[ ]*(.+)", str(self.message['message']['text']), re.IGNORECASE)
        
        conterQuery = {
                        'chat_id' : self.message['message']['chat']['id'],
                        'text'    : ''
                      }

        if find is None:
            conterQuery['text'] = "There is no answer!"
            logging.warning("answerAction.do(): User's answer don't contain text: \n %s", (self.message['message']['text']))
            raise tornado.gen.Return(conterQuery)
        answer = find.groups()[0]

        yield user.selectThis()
        logging.debug("answerAction.do(): gotted user from db is %s " % str(user.chat_id))
        

        if (user.game_id == ''):
            conterQuery['text'] = 'You not take a competition in game, please register by typing "/start" or "/help" for help'
            logging.warning("answerAction.do(): user dont have permissions to game \n user - %s " % str(user.chat_id))
            raise tornado.gen.Return(conterQuery)

        game = Game(self._app.db,self._template)
        game.id = user.game_id
        yield game.selectThis()

        task = Task(self._app.db,self._template)
        task.id = user.getTask()
        if not (task.id):
            logging.error("answerAction.do(): task id is not defined for user %s " % str(user.chat_id))
            conterQuery['text'] = "we don't have any tasks for you, please send /start or /help"
            raise tornado.gen.Return(conterQuery)

        yield task.selectThis()
        if not (task.compareAnswer(answer)):
            logging.info("answerAction.do(): User sended wrong answer: \n user %s, task.answer %s, answer %s", (user.chat_id, task.answer, answer))
            conterQuery['text'] = "This is wrong answer! Try another"
            raise tornado.gen.Return(conterQuery)
        
        currentTask = yield user.changeTask()
        
 
        if not currentTask is False:
            if currentTask is True:
                self._message['message']['text'] = "/finish"
                logging.info("answerAction.do(): User will be redirrected to /finish\n changeTask returned %s" % currentTask)
            else:
                self._message['message']['text'] = "/start"
                logging.info("answerAction.do(): User will be redirrected to /start\n changeTask returned %s" % currentTask)
            
            logging.info("answerAction.do(): User sended right answer and will take new task \n user %s, task.answer %s, answer %s" % (user.chat_id, task.answer, answer))
            conterQuery['text'] = "Thats right!!"
            tornado.gen.Task(self._app.sendLocalMessage,self._message,2)
                
        else:
            conterQuery['text'] = "Something wrong, please contact administrator"
            
        raise tornado.gen.Return(conterQuery)
コード例 #4
0
    def do(self):
        user = User(self._app.db, self._template)
        user.chat_id = ''.join(
            filter(str.isdigit, str(self.message['message']['chat']['id'])))
        find = re.match("/answer[ ]*(.+)",
                        str(self.message['message']['text']), re.IGNORECASE)

        conterQuery = {
            'chat_id': self.message['message']['chat']['id'],
            'text': ''
        }

        if find is None:
            conterQuery['text'] = "There is no answer!"
            logging.warning(
                "answerAction.do(): User's answer don't contain text: \n %s",
                (self.message['message']['text']))
            raise tornado.gen.Return(conterQuery)
        answer = find.groups()[0]

        yield user.selectThis()
        logging.debug("answerAction.do(): gotted user from db is %s " %
                      str(user.chat_id))

        if (user.game_id == ''):
            conterQuery[
                'text'] = 'You not take a competition in game, please register by typing "/start" or "/help" for help'
            logging.warning(
                "answerAction.do(): user dont have permissions to game \n user - %s "
                % str(user.chat_id))
            raise tornado.gen.Return(conterQuery)

        game = Game(self._app.db, self._template)
        game.id = user.game_id
        yield game.selectThis()

        task = Task(self._app.db, self._template)
        task.id = user.getTask()
        if not (task.id):
            logging.error(
                "answerAction.do(): task id is not defined for user %s " %
                str(user.chat_id))
            conterQuery[
                'text'] = "we don't have any tasks for you, please send /start or /help"
            raise tornado.gen.Return(conterQuery)

        yield task.selectThis()
        if not (task.compareAnswer(answer)):
            logging.info(
                "answerAction.do(): User sended wrong answer: \n user %s, task.answer %s, answer %s",
                (user.chat_id, task.answer, answer))
            conterQuery['text'] = "This is wrong answer! Try another"
            raise tornado.gen.Return(conterQuery)

        currentTask = yield user.changeTask()

        if not currentTask is False:
            if currentTask is True:
                self._message['message']['text'] = "/finish"
                logging.info(
                    "answerAction.do(): User will be redirrected to /finish\n changeTask returned %s"
                    % currentTask)
            else:
                self._message['message']['text'] = "/start"
                logging.info(
                    "answerAction.do(): User will be redirrected to /start\n changeTask returned %s"
                    % currentTask)

            logging.info(
                "answerAction.do(): User sended right answer and will take new task \n user %s, task.answer %s, answer %s"
                % (user.chat_id, task.answer, answer))
            conterQuery['text'] = "Thats right!!"
            tornado.gen.Task(self._app.sendLocalMessage, self._message, 2)

        else:
            conterQuery[
                'text'] = "Something wrong, please contact administrator"

        raise tornado.gen.Return(conterQuery)