From 7640568a42493bc5a5e44bc82b1ecfa87e51c5f1 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Tue, 26 Jan 2021 18:43:13 +0800 Subject: [Update] --- ATRI/plugins/utils/__init__.py | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ATRI/plugins/utils/__init__.py (limited to 'ATRI/plugins/utils/__init__.py') diff --git a/ATRI/plugins/utils/__init__.py b/ATRI/plugins/utils/__init__.py new file mode 100644 index 0000000..4204cfb --- /dev/null +++ b/ATRI/plugins/utils/__init__.py @@ -0,0 +1,76 @@ +import re +from nonebot.matcher import Matcher +from nonebot.plugin import on_command +from nonebot.adapters.cqhttp import Bot, Event + +from ATRI.config import UTILS_CONFIG +from ATRI.rule import is_in_ban_list, is_in_dormant, is_in_service + +from .data_source import Function + +# ===========================[Begin Command Processing]=========================== + + +__plugin_name_0__ = 'roll' +roll = on_command(UTILS_CONFIG['utils']['roll']['command'][0], + aliases=set(UTILS_CONFIG['utils']['roll']['command']), + rule=is_in_ban_list() & is_in_dormant() + & is_in_service(__plugin_name_0__)) + +__plugin_name_1__ = 'rcnb' +rcnbEncode = on_command( + UTILS_CONFIG['utils']['rcnb']['encode']['command'][0], + aliases=set( + UTILS_CONFIG['utils']['rcnb']['encode']['command']), + rule=is_in_ban_list() & is_in_dormant() + & is_in_service(__plugin_name_1__)) + +rcnbDecode = on_command( + UTILS_CONFIG['utils']['rcnb']['decode']['command'][0], + aliases=set( + UTILS_CONFIG['utils']['rcnb']['decode']['command']), + rule=is_in_ban_list() & is_in_dormant() + & is_in_service(__plugin_name_1__)) + + +@roll.handle() +async def _(bot, event: Event, state: dict) -> None: + args = str(event.get_message()).strip() + print(args) + if args: + state['result'] = args + +@roll.got('result', prompt='roll参数不能为空!..\ndemo: 1d10 或 2d10+3d10') +async def _(matcher: Matcher, bot: Bot, event: Event, state: dict) -> None: + resu = state['result'] + match = re.match(r'^([\dd+\s]+?)$', resu) + print(match) + if not match: + await matcher.reject('格式不-正-确!\ndemo: 1d10 或 2d10+3d10') + await bot.send(event, Function.roll_dice(par=resu)) + + +@rcnbEncode.handle() +async def _(bot, event: Event, state: dict) -> None: + args = str(event.get_message()).strip() + if args: + state['result'] = args + +@rcnbEncode.got('result', prompt='请告诉咱需要加密的字符~!') +async def _(bot: Bot, event: Event, state: dict) -> None: + print(state['result']) + await bot.send(event, Function.RCNB.encode(state['result'])) + + +@rcnbDecode.handle() +async def _(bot, event: Event, state: dict) -> None: + args = str(event.get_message()).strip() + if args: + state['result'] = args + +@rcnbEncode.got('result', prompt='请告诉咱需要解密的字符~!') +async def _(bot: Bot, event: Event, state: dict) -> None: + await bot.send(event, Function.RCNB.decode(state['result'])) + + +# ===========================[End Command Processing]============================= -- cgit v1.2.3