Files
HeXi/hexi/plugins/nonebot_plugin_group_tools/utils/permissions.py
T
sansenhoshiandClaude b61d09f09f Add HeXi bot codebase: custom plugins, web frontends, tests
- hexi core: message handling, rate limiting, cooldown, plugin manager
- Custom plugins: BF stats, daily check-in, quotes, persona cards, etc.
- Community plugins vendored under hexi/plugins with local fixes
- Web admin frontends (learning-chat, persona-admin), unified hexi/web
- Tests for rate_limit/cooldown/memes/persona; poetry.lock

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-01 13:13:40 +08:00

50 lines
1.6 KiB
Python

from nonebot import logger
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
from nonebot_plugin_alconna import UniMessage
from hexi.plugins.nonebot_plugin_hexi_core.custom_utils import (
check_bot_admin,
check_manage,
)
async def group_member_info(bot: Bot, gid: int, uid: int):
"""获取指定群成员信息,失败返回 None"""
try:
return await bot.get_group_member_info(group_id=gid, user_id=uid, no_cache=True)
except Exception as e:
logger.exception(e)
return None
async def self_member_info(bot: Bot, gid: int):
"""获取 bot 自身的群成员信息"""
return await group_member_info(bot, gid, bot.self_id)
async def honor_info(bot: Bot, gid: int, honor_type: str):
"""获取群荣誉信息,失败返回 None"""
try:
return await bot.get_group_honor_info(group_id=gid, type=honor_type)
except Exception as e:
logger.exception(e)
return None
def is_bot_manage(self_info) -> bool:
"""bot 是否为该群的管理/群主"""
return bool(self_info) and self_info["role"] in ("owner", "admin")
async def check_perm(bot: Bot, ev: GroupMessageEvent, silent: bool = False) -> bool:
"""检查 bot 为群管理 且 用户为管理以上权限;不通过时按需回复"""
if not await check_bot_admin(bot, ev.group_id):
await UniMessage.text("咱又不是管理,你找错人了").send()
return False
if not await check_manage(bot, ev):
if not silent:
await UniMessage.text("才不听你的呢").send()
return False
return True