summaryrefslogtreecommitdiff
path: root/ATRI/plugins/funny
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/funny')
-rw-r--r--ATRI/plugins/funny/__init__.py42
-rw-r--r--ATRI/plugins/funny/data_source.py6
2 files changed, 23 insertions, 25 deletions
diff --git a/ATRI/plugins/funny/__init__.py b/ATRI/plugins/funny/__init__.py
index ea60375..8173f3b 100644
--- a/ATRI/plugins/funny/__init__.py
+++ b/ATRI/plugins/funny/__init__.py
@@ -1,8 +1,8 @@
from random import choice, randint
-from nonebot.typing import T_State
-from nonebot.adapters.cqhttp import Bot, MessageEvent, GroupMessageEvent
-from nonebot.adapters.cqhttp.message import Message
+from nonebot.matcher import Matcher
+from nonebot.params import ArgPlainText, CommandArg
+from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, Message
from ATRI.utils.limit import FreqLimiter, DailyLimiter
from .data_source import Funny
@@ -39,38 +39,36 @@ _fake_flmt = FreqLimiter(60)
_fake_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~"])
-@fake_msg.args_parser # type: ignore
-async def _perp_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
- msg = str(event.message).strip()
- quit_list = ["算了", "罢了"]
- if msg in quit_list:
- await fake_msg.finish("好吧...")
- if not msg:
- await fake_msg.reject("内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开")
- else:
- state["content"] = msg
-
-
@fake_msg.handle()
-async def _ready_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
+async def _ready_fake(
+ matcher: Matcher, event: GroupMessageEvent, args: Message = CommandArg()
+):
user_id = event.get_user_id()
if not _fake_daliy_max.check(user_id):
await fake_msg.finish(_fake_max_notice)
if not _fake_flmt.check(user_id):
await fake_msg.finish(_fake_flmt_notice)
- msg = str(event.message).strip()
+ msg = args.extract_plain_text()
if msg:
- state["content"] = msg
+ matcher.set_arg("content", args)
@fake_msg.got("content", "内容呢?格式:qq-name-content\n可构造多条,以上仅为一条,使用空格隔开")
-async def _deal_fake(bot: Bot, event: GroupMessageEvent, state: T_State):
- content = state["content"]
+async def _deal_fake(
+ bot: Bot, event: GroupMessageEvent, content: str = ArgPlainText("content")
+):
group_id = event.group_id
user_id = event.get_user_id()
- node = Funny().fake_msg(content)
- await bot.send_group_forward_msg(group_id=group_id, messages=node)
+ try:
+ node = Funny().fake_msg(content)
+ except Exception:
+ await fake_msg.finish("内容格式错误,请检查(")
+
+ try:
+ await bot.send_group_forward_msg(group_id=group_id, messages=node)
+ except Exception:
+ await fake_msg.finish("构造失败惹...可能是被制裁了(")
_fake_flmt.start_cd(user_id)
_fake_daliy_max.increase(user_id)
diff --git a/ATRI/plugins/funny/data_source.py b/ATRI/plugins/funny/data_source.py
index a1fce64..8edc88a 100644
--- a/ATRI/plugins/funny/data_source.py
+++ b/ATRI/plugins/funny/data_source.py
@@ -3,7 +3,7 @@ import os
from pathlib import Path
from random import choice, randint
-from nonebot.adapters.cqhttp.utils import unescape
+from nonebot.adapters.onebot.v11 import unescape
from ATRI.service import Service
from ATRI.log import logger
@@ -77,9 +77,9 @@ class Funny(Service):
EAT_URL = "https://wtf.hiigara.net/api/run/"
params = {"event": "ManualRun"}
pattern_0 = r"大?[今明后]天(.*?)吃[什啥]么?"
- pattern_1 = r"(今|明|后|大后)天"
+ pattern_1 = r"[今|明|后|大后]天"
arg = re.findall(pattern_0, msg)[0]
- day = re.match(pattern_1, msg).group(0) # type: ignore
+ day = re.findall(pattern_1, msg)[0]
if arg == "中午":
a = f"LdS4K6/{randint(0, 1145141919810)}"