3
3
import re
4
4
import random
5
5
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
12
8
from .data import atri_text
13
9
from .data import V_PATH
14
- __plugin_name__ = "高性能萝卜子"
15
- __usage__ = "@Bot 想说的话"
16
10
17
- atri = on_message (rule = to_me (), permission = GROUP , priority = 50 )
11
+ __plugin_name__ = "ATRI 语音包"
12
+ __usage__ = "atri"
18
13
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 )
25
15
26
16
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" ]
45
38
text = re .findall ("(.*).mp3" , voice )[0 ]
46
39
await atri .send (MessageSegment .record (f"file:///{ V_PATH } { voice } " ))
47
- await atri .finish (text )
40
+ await atri .finish (text )
0 commit comments