Ejemplo n.º 1
0
    def handle_commands(self, commands):
        def _is_user(name):
            return User.query.filter_by(name=name).count() > 0

        def _auto_reply(content):
            s = content.split('@3bugs')[-1]
            for k, v in a.items():
                if k in s or s in k:
                    return v
            return None

        for command in commands:
            if not waitings.in_queue(command['id']) and \
                    _is_user(command['name']) and \
                    not unknown.in_queue(command['id']):

                auto_reply = _auto_reply(command['content'])
                if auto_reply:
                    self.repost(auto_reply(), command['id'])
                    unknown.enqueue(command['id'], command['content'])
                    continue

                new_job = waitings.enqueue(command['content'],
                        command['id'], command['name'])
                if new_job:
                    logger.info('found new job <%d %s>' % (
                            new_job.id, new_job.action))
                else:
                    unknown.enqueue(command['id'], command['content'])
                    self.repost(s['unknowncommand'](), command['id'])
Ejemplo n.º 2
0
def handle_commands(commands):
    def _is_user(name):
        return db.session.query(User).filter(User.name == name).count() > 0

    for command in commands:
        if not waitings.in_queue(command.id) and _is_user(command.name) and not unknown.in_queue(command.id):
            new_job = waitings.enqueue(command.text, command.id, command.name)
            if new_job:
                logger.info("found new job <%d %s>" % (new_job.id, new_job.action))
            else:
                unknown.enqueue(command.id, command.text)