decorators.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:telegram-autoposter 作者: vaniakosmos 项目源码 文件源码
def admin_access():
    def access(func):
        @wraps(func)
        def wrapped(self, bot: Bot, update: Update, *args, **kwargs):
            user = update.effective_user
            admins = getattr(self, 'admins', None)

            if admins is None:
                self.logger.warning('Specify self.admins (list of users ids) parameter in '
                                    'manager or channel classes in order to restrict access to bot.')
                return func(self, bot, update, *args, **kwargs)

            if user.id not in admins:
                self.logger.info(f"Unauthorized access denied for {user}.")
                return

            return func(self, bot, update, *args, **kwargs)
        return wrapped
    return access
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号