diff options
Diffstat (limited to 'ATRI/plugins')
-rw-r--r-- | ATRI/plugins/essential.py | 17 | ||||
-rw-r--r-- | ATRI/plugins/funny.py | 69 |
2 files changed, 73 insertions, 13 deletions
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py index 0fbed92..833ce01 100644 --- a/ATRI/plugins/essential.py +++ b/ATRI/plugins/essential.py @@ -56,15 +56,14 @@ async def shutdown() -> None: try: shutil.rmtree(PLUGIN_INFO_DIR) logger.debug("成功!") - except: + except Exception: repo = ( '清理插件信息失败', '请前往 ATRI/data/service/services 下', '将 services 整个文件夹删除' ) - logger.error(repo) time.sleep(10) - pass + raise Exception(repo) @driver.on_bot_connect @@ -342,8 +341,12 @@ recall_event = sv.on_notice() @recall_event.handle() async def _recall_event(bot: Bot, event: GroupRecallNoticeEvent) -> None: + try: + repo = await bot.get_msg(message_id=event.message_id) + except: + return + group = event.group_id - repo = await bot.get_msg(message_id=event.message_id) repo = str(repo["message"]) check = await coolq_code_check(repo, group=group) if not check: @@ -364,8 +367,12 @@ async def _recall_event(bot: Bot, event: GroupRecallNoticeEvent) -> None: @recall_event.handle() async def _rec(bot: Bot, event: FriendRecallNoticeEvent) -> None: + try: + repo = await bot.get_msg(message_id=event.message_id) + except: + return + user = event.user_id - repo = await bot.get_msg(message_id=event.message_id) repo = str(repo["message"]) check = await coolq_code_check(repo, user) if not check: diff --git a/ATRI/plugins/funny.py b/ATRI/plugins/funny.py index 3d7becd..d630092 100644 --- a/ATRI/plugins/funny.py +++ b/ATRI/plugins/funny.py @@ -1,12 +1,18 @@ +import json +import re import asyncio from pathlib import Path from random import choice, randint from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent +from nonebot.adapters.cqhttp.message import Message, MessageSegment from ATRI.service import Service as sv from ATRI.utils.limit import is_too_exciting from ATRI.rule import is_in_service +from ATRI.utils.request import post_bytes +from ATRI.utils.translate import to_simple_string +from ATRI.exceptions import RequestTimeOut __doc__ = """ @@ -146,11 +152,58 @@ async def _fake_msg(bot: Bot, event: GroupMessageEvent) -> None: await bot.send_group_forward_msg(group_id=group, messages=node) -__doc__ = """ -不知道吃什么? -权限组:所有人 -用法: - 今天{时段}吃什么 -示例: - 今天中午吃什么 -""" +EAT_URL = "https://wtf.hiigara.net/api/run/{}" + +eat_wat = sv.on_regex(r"[今|明|后|大后]天(.*?)吃什么", rule=is_in_service('今天吃什么')) + +@eat_wat.handle() +async def _eat(bot: Bot, event: MessageEvent) -> None: + msg = str(event.message).strip() + user = event.user_id + user_n = event.sender.nickname + arg = re.findall(r"[今|明|后|大后]天(.*?)吃什么", msg)[0] + nd = re.match(r"[今|明|后|大后][天]", msg)[0] + + if arg == "中午": + a = f"LdS4K6/{randint(0, 999999)}" + url = EAT_URL.format(a) + params = {"event": "ManualRun"} + try: + data = json.loads(await post_bytes(url, params)) + except RequestTimeOut: + raise RequestTimeOut('Request failed!') + + text = to_simple_string(data['text']).replace('今天', nd) + get_a = re.search(r"非常(.*?)的", text)[0] + result = f"> {MessageSegment.at(user)}\n" + text.replace(get_a, '') + + elif arg == "晚上": + a = f"KaTMS/{randint(0, 999999)}" + url = EAT_URL.format(a) + params = {"event": "ManualRun"} + try: + data = json.loads(await post_bytes(url, params)) + except RequestTimeOut: + raise RequestTimeOut('Request failed!') + + text = to_simple_string(data['text']).replace('今天', '') + result = f"> {MessageSegment.at(user)}\n" + text + + else: + rd = randint(1, 10) + if rd == 5: + result = "吃我吧 ❤" + else: + a = f"JJr1hJ/{randint(0, 999999)}" + url = EAT_URL.format(a) + params = {"event": "ManualRun"} + try: + data = json.loads(await post_bytes(url, params)) + except RequestTimeOut: + raise RequestTimeOut('Request failed!') + + text = to_simple_string(data['text']).replace('今天', nd) + get_a = re.match(r"(.*?)的智商", text)[0] + result = f"> {MessageSegment.at(user)}\n" + text.replace(get_a, f'{user_n}的智商') + + await eat_wat.finish(Message(result))
\ No newline at end of file |