From ae7ea2d379ec7fb0edb8e333145bb141106a2fd2 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sat, 20 Feb 2021 08:19:41 +0800 Subject: =?UTF-8?q?=E2=9C=A8=20=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=9F=8B=E4=B8=8Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新插件: - call-owner - code-runner - status - anime-search - tex(待修复) - 埋下bug: - service中limit作为机器人服务中的开关,目前写入文件亟待修复 --- ATRI/plugins/utils/__init__.py | 51 +++++++++++++++++++++++++++++++++++++++ ATRI/plugins/utils/data_source.py | 35 +++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 2 deletions(-) (limited to 'ATRI/plugins/utils') diff --git a/ATRI/plugins/utils/__init__.py b/ATRI/plugins/utils/__init__.py index e69de29..1bf1461 100644 --- a/ATRI/plugins/utils/__init__.py +++ b/ATRI/plugins/utils/__init__.py @@ -0,0 +1,51 @@ +import re + +from nonebot.plugin import on_command +from nonebot.adapters.cqhttp import Bot, MessageEvent + +from ATRI.rule import ( + is_in_banlist, + is_in_dormant, + is_in_service +) +from .data_source import roll_dice + + +__plugin_name__ = "roll" + +roll = on_command( + "/roll", + rule=is_in_banlist() & is_in_dormant() + & is_in_service(__plugin_name__) +) + +@roll.handle() +async def _roll(bot: Bot, event: MessageEvent, state: dict) -> None: + args = str(event.message).strip() + if args: + state['resu'] = args + +@roll.got("resu", prompt="roll 参数不能为空~!\ndemo:1d10 或 2d10+2d10") +async def _(bot: Bot, event: MessageEvent, state: dict) -> None: + resu = state['resu'] + match = re.match(r'^([\dd+\s]+?)$', resu) + + if not match: + await roll.finish("请输入正确的参数!!\ndemo:1d10 或 2d10+2d10") + + await roll.finish(roll_dice(resu)) + + +# __plugin_name__ = "fakemsg" + +# fakemsg = on_command( +# "/fakemsg", +# rule=is_in_banlist() & is_in_dormant() +# & is_in_service(__plugin_name__) +# ) + +# @fakemsg.handle() +# async def _fakemsg(bot: Bot, event: MessageEvent, state: dict) -> None: +# ... + +# @fakemsg.got() \ No newline at end of file diff --git a/ATRI/plugins/utils/data_source.py b/ATRI/plugins/utils/data_source.py index b83cd33..f41a1d1 100644 --- a/ATRI/plugins/utils/data_source.py +++ b/ATRI/plugins/utils/data_source.py @@ -1,3 +1,34 @@ -from nonebot.adapters.cqhttp.message import MessageSegment +import re +import random -MessageSegment. \ No newline at end of file + +def roll_dice(par: str) -> str: + result = 0 + proc = '' + proc_list = [] + p = par.split("+") + + for i in p: + args = re.findall(r"(\d{0,10})(?:(d)(\d{1,10}))", i) + args = list(args[0]) + + args[0] = args[0] or 1 + if int(args[0]) >= 5000 or int(args[2]) >= 5000: + return "阿...好大......" + + for a in range(1, int(args[0]) + 1): + rd = random.randint(1, int(args[2])) + result = result + rd + + if len(proc_list) <= 10: + proc_list.append(rd) + + if len(proc_list) <= 10: + proc += "+".join(map(str, proc_list)) + elif len(proc_list) > 10: + proc += "太长了不展示了就酱w" + else: + proc += str(result) + + result = f"{par}=({proc})={result}" + return result -- cgit v1.2.3