Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Commit 79038a1

Browse files
committed
🎉 v2.0.0 适配B1
修改调用方式
1 parent ab95586 commit 79038a1

File tree

5 files changed

+713
-75
lines changed

5 files changed

+713
-75
lines changed

Diff for: nonebot_plugin_atri/__init__.py

+27-34
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,38 @@
33
import re
44
import random
55
from difflib import SequenceMatcher
6-
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, GROUP
7-
from nonebot.typing import T_State
8-
from nonebot.plugin import on_message
9-
from nonebot.rule import to_me
10-
from nonebot.log import logger
11-
from nonebot.adapters.cqhttp.message import MessageSegment
6+
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, GROUP, MessageSegment
7+
from nonebot.plugin import on_command
128
from .data import atri_text
139
from .data import V_PATH
14-
__plugin_name__ = "高性能萝卜子"
15-
__usage__ = "@Bot 想说的话"
1610

17-
atri = on_message(rule=to_me(), permission=GROUP, priority=50)
11+
__plugin_name__ = "ATRI 语音包"
12+
__usage__ = "atri"
1813

19-
20-
@atri.handle()
21-
async def _h(bot: Bot, event: GroupMessageEvent, state: T_State):
22-
args = str(event.get_message()).strip()
23-
if args:
24-
state["words"] = args
14+
atri = on_command("atri", permission=GROUP, priority=50)
2515

2616

27-
@atri.got("words", prompt="想对萝卜子说什么话呢?")
28-
async def _g(bot: Bot, event: GroupMessageEvent, state: T_State):
29-
words = state["words"]
30-
diff: dict[str, float] = {}
31-
for text in atri_text:
32-
r1 = SequenceMatcher(None, words, text["s"]).ratio()
33-
r2 = SequenceMatcher(None, words, text["s_f"]).ratio()
34-
r3 = SequenceMatcher(None, words, text["s_k"]).ratio()
35-
diff.update({text["o"]: r1 * r2 + r3}) # 完全瞎想的计算方式,没啥特殊的意义
36-
diff_sorted = dict(
37-
sorted(diff.items(), key=lambda item: item[1], reverse=True))
38-
voice = random.choice(
39-
[
40-
list(diff_sorted.keys())[0],
41-
list(diff_sorted.keys())[1],
42-
list(diff_sorted.keys())[2],
43-
]
44-
)
17+
@atri.handle()
18+
async def _h(bot: Bot, event: GroupMessageEvent):
19+
words = str(event.message).strip()
20+
if words:
21+
diff: dict[str, float] = {}
22+
for text in atri_text:
23+
r1 = SequenceMatcher(None, words, text["s"]).ratio()
24+
r2 = SequenceMatcher(None, words, text["s_f"]).ratio()
25+
r3 = SequenceMatcher(None, words, text["s_k"]).ratio()
26+
diff.update({text["o"]: r1 * r2 + r3}) # 完全瞎想的计算方式,没啥特殊的意义
27+
diff_sorted = dict(
28+
sorted(diff.items(), key=lambda item: item[1], reverse=True))
29+
voice = random.choice(
30+
[
31+
list(diff_sorted.keys())[0],
32+
list(diff_sorted.keys())[1],
33+
list(diff_sorted.keys())[2],
34+
]
35+
)
36+
else:
37+
voice = random.choice(atri_text)["o"]
4538
text = re.findall("(.*).mp3", voice)[0]
4639
await atri.send(MessageSegment.record(f"file:///{V_PATH}{voice}"))
47-
await atri.finish(text)
40+
await atri.finish(text)

Diff for: nonebot_plugin_atri/data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding: utf-8
33
import os
44
import json
5+
from typing import Dict, List
56
from pathlib import Path
67

78
current_path = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + os.path.sep + ".") + "/"
@@ -11,7 +12,7 @@
1112

1213

1314
with open(f"{T_PATH}atri.json", "r", encoding="utf-8") as file:
14-
atri_text = json.load(file)
15+
atri_text: List[Dict[str, str]] = json.load(file)
1516

1617

1718
if __name__ == "__main__":

0 commit comments

Comments
 (0)