"""群管理工具 —— 管理员与公告。""" from __future__ import annotations from nonebot import on_startswith, require from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent from nonebot_plugin_alconna import UniMessage from ...utils.permissions import check_perm require("nonebot_plugin_alconna") set_admin = on_startswith("设置管理员") unset_admin = on_startswith("取消管理员") set_group_notice = on_startswith("设置群公告") @set_admin.handle() async def set_admin_handle(bot: Bot, ev: GroupMessageEvent): if not await check_perm(bot, ev): return for seg in ev.message: if seg.type == "at" and seg.data.get("qq") != "all": await bot.set_group_admin( group_id=ev.group_id, user_id=int(seg.data["qq"]), enable=True ) await UniMessage.text("我好了").send() @unset_admin.handle() async def unset_admin_handle(bot: Bot, ev: GroupMessageEvent): if not await check_perm(bot, ev): return for seg in ev.message: if seg.type == "at" and seg.data.get("qq") != "all": await bot.set_group_admin( group_id=ev.group_id, user_id=int(seg.data["qq"]), enable=False ) await UniMessage.text("我好了").send() @set_group_notice.handle() async def set_group_notice_handle(bot: Bot, ev: GroupMessageEvent): content = ev.message.extract_plain_text().removeprefix("设置群公告").strip() if not content: return if not await check_perm(bot, ev): return await bot.call_api("_send_group_notice", group_id=ev.group_id, content=content) await UniMessage.text("我好了").send()