mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-23 00:01:33 +00:00
8f424bf0d4
♻️ 重构插件系统 ⚙️ 重写插件 🎨 改进代码结构 📝 完善文档 Co-authored-by: zhxy-CN <admin@owo.cab> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Li Chuangbo <im@chuangbo.li>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from functools import wraps
|
|
from typing import Callable, cast
|
|
|
|
from telegram import Update
|
|
|
|
from core.admin import BotAdminService
|
|
from core.bot import bot
|
|
from core.error import ServiceNotFoundError
|
|
|
|
bot_admin_service = bot.services.get(BotAdminService)
|
|
|
|
|
|
def bot_admins_rights_check(func: Callable) -> Callable:
|
|
"""BOT ADMIN 权限检查"""
|
|
|
|
@wraps(func)
|
|
async def decorator(*args, **kwargs):
|
|
if len(args) == 3:
|
|
# self update context
|
|
_, update, _ = args
|
|
elif len(args) == 2:
|
|
# update context
|
|
update, _ = args
|
|
else:
|
|
return await func(*args, **kwargs)
|
|
if bot_admin_service is None:
|
|
raise ServiceNotFoundError("BotAdminService")
|
|
admin_list = await bot_admin_service.get_admin_list()
|
|
update = cast(Update, update)
|
|
message = update.effective_message
|
|
user = update.effective_user
|
|
if user.id in admin_list:
|
|
return await func(*args, **kwargs)
|
|
else:
|
|
await message.reply_text("权限不足")
|
|
return None
|
|
|
|
return decorator
|