2022-07-26 10:07:31 +00:00
|
|
|
from functools import wraps
|
|
|
|
from typing import Callable
|
|
|
|
|
2022-08-05 11:14:29 +00:00
|
|
|
from apps.admin.services import BotAdminService
|
|
|
|
from utils.apps.inject import inject
|
2022-07-26 10:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def bot_admins_rights_check(func: Callable) -> Callable:
|
|
|
|
"""BOT ADMIN 权限检查"""
|
|
|
|
|
|
|
|
@inject
|
2022-08-06 09:02:01 +00:00
|
|
|
def get_bot_admin_service(bot_admin_service: BotAdminService = None):
|
|
|
|
return bot_admin_service
|
|
|
|
|
|
|
|
@wraps(func)
|
|
|
|
async def decorator(*args, **kwargs):
|
2022-07-26 10:07:31 +00:00
|
|
|
if len(args) == 3:
|
|
|
|
# self update context
|
|
|
|
_, update, context = args
|
|
|
|
elif len(args) == 2:
|
|
|
|
# update context
|
|
|
|
update, context = args
|
|
|
|
else:
|
|
|
|
return await func(*args, **kwargs)
|
2022-08-06 09:02:01 +00:00
|
|
|
bot_admin_service = get_bot_admin_service()
|
2022-07-26 10:07:31 +00:00
|
|
|
if bot_admin_service is None:
|
|
|
|
raise RuntimeError("bot_admin_service is None")
|
|
|
|
admin_list = await bot_admin_service.get_admin_list()
|
|
|
|
if update.message.from_user.id in admin_list:
|
|
|
|
return await func(*args, **kwargs)
|
|
|
|
else:
|
|
|
|
await update.message.reply_text("权限不足")
|
|
|
|
return None
|
|
|
|
|
|
|
|
return decorator
|