Exemplo n.º 1
0
    def check_update(self, update: telegram.Update):
        logger.debug("checking this update")

        try:
            text = update.message.text if update.message != None else update.callback_query.data
            if text is None:
                return False

            match = self.rgx_parts.search(text)
            if not match:
                return False

            cmd_prefix = match.group(1)
            command = match.group(2)
            rest = match.group(4)
            if rest is None:
                rest = ""

            update.message.rest = rest
            tags = rgx_tags.findall(rest)
            args = rgx_args.findall(rest)
            users = rgx_users.findall(rest)

            update.message.tags = tags
            update.message.args = args
            update.message.users = users

            update.type = "command"
            update.message.command = command

            try:
                update.message.text = '%s%s %s' % (cmd_prefix, command,
                                                   update.message.rest)
            except:
                update.message.text = command

            return True
        except:
            import traceback
            traceback.print_exc()
            return False