Files
HeXi/hexi/plugins/nonebot_plugin_bf_bot/handlers/binding.py
T

39 lines
1.3 KiB
Python
Raw Normal View History

"""绑定管理命令:/bfbind(绑定) /unbind(解绑) /update_bind(修改绑定)。"""
from nonebot import on_command
from nonebot.adapters import Event, Message
from nonebot.params import CommandArg
from nonebot.rule import to_me
from nonebot_plugin_alconna import UniMessage
from ..services import binding as binding_service
bind_cmd = on_command("bfbind", rule=to_me(), aliases={"绑定"}, block=True)
unbind_cmd = on_command("unbind", rule=to_me(), aliases={"解绑"}, block=True)
update_bind_cmd = on_command(
"update_bind", rule=to_me(), aliases={"修改绑定"}, block=True
)
async def _reply(event: Event, text: str) -> None:
await UniMessage.at(user_id=event.get_user_id()).text(text).send()
@bind_cmd.handle()
async def handle_bind(event: Event, msg: Message = CommandArg()):
text = await binding_service.bind(event.get_user_id(), msg.extract_plain_text())
await _reply(event, text)
@unbind_cmd.handle()
async def handle_unbind(event: Event):
text = await binding_service.unbind(event.get_user_id())
await _reply(event, text)
@update_bind_cmd.handle()
async def handle_update_bind(event: Event, msg: Message = CommandArg()):
text = await binding_service.update_bind(
event.get_user_id(), msg.extract_plain_text()
)
await _reply(event, text)