检查当前事件是否是消息事件且属于超级管理员
| 89 | |
| 90 | |
| 91 | class SuperUser: |
| 92 | """检查当前事件是否是消息事件且属于超级管理员""" |
| 93 | |
| 94 | __slots__ = () |
| 95 | |
| 96 | def __repr__(self) -> str: |
| 97 | return "Superuser()" |
| 98 | |
| 99 | async def __call__(self, bot: Bot, event: Event) -> bool: |
| 100 | try: |
| 101 | user_id = event.get_user_id() |
| 102 | except Exception: |
| 103 | return False |
| 104 | return ( |
| 105 | f"{bot.adapter.get_name().split(maxsplit=1)[0].lower()}:{user_id}" |
| 106 | in bot.config.superusers |
| 107 | or user_id in bot.config.superusers # 兼容旧配置 |
| 108 | ) |
| 109 | |
| 110 | |
| 111 | SUPERUSER: Permission = Permission(SuperUser()) |