我可以在python3中调用具有修饰函数名称的函数修饰器吗

时间:2020-08-26 22:46:37

标签: python python-3.x telegram telegram-bot

我知道我的问题很奇怪,但是我必须做这样的事情:

def on_update(self, context):
        self.possibleContext=[r"\/file\/",r"\/anyFile\/"]
        def inner(function, *args, **kwargs):
            self.handlers.append(function)
            #i define result, is the dictionary returned by telegram request
            function(result, *args, **kwargs)
            return update
        return inner

在轮询功能下有一个装饰器,应调用每个装饰器

    def polling(self, timeout: int = 0, *args, **kwargs):
        print(f"Started {self.bot['first_name']} on TeleLib V.{self.version}")
        try:
            update_id = self.getUpdates()[0]['update_id']
        except IndexError:
            update_id = None
        while True:
            try:
                for funct in self.handlers:
#Here i should call the decorator, not the function, because the decorator call the function giving it an argument
            except Error1:
                #here some telegram errors exceptions
            except Error2:
                #ecc
        for update in self.getUpdates(offset=update_id, timeout=timeout):
            update_id = update['update_id'] + 1
            self.polling()
            return update

,这里是一个示例函数:

@client.on_update('ciikk')
def funzione(update):
    client.sendMessage(update['message']['chat']['id'],update['message']['text'])

0 个答案:

没有答案