1
1
import random
2
+ from typing import List
3
+
2
4
from nonebot import on_regex
3
5
from nonebot .matcher import Matcher
4
6
from nonebot .params import Depends , RegexMatched
7
+ from nonebot .plugin import PluginMetadata
8
+
5
9
from .config import *
6
10
7
- __crazy_thursday_version__ = "v0.2.6.post1 "
8
- __crazy_thursday_notes__ = f"""
11
+ __crazy_thursday_version__ = "v0.2.6.post2 "
12
+ __crazy_thursday_usages__ = f"""
9
13
KFC疯狂星期四 { __crazy_thursday_version__ }
10
14
[疯狂星期X] 随机输出KFC疯狂星期四文案
11
15
[狂乱X曜日] 随机输出KFC疯狂星期四文案""" .strip ()
12
16
17
+ __plugin_meta__ = PluginMetadata (
18
+ name = "疯狂星期四" ,
19
+ description = "持续疯狂!KFC疯狂星期四🍗" ,
20
+ usage = __crazy_thursday_usages__ ,
21
+ extra = {
22
+ "author" : "KafCoppelia <k740677208@gmail.com>" ,
23
+ "version" : __crazy_thursday_version__
24
+ }
25
+ )
26
+
13
27
crazy_cn = on_regex (pattern = r"^疯狂星期\S$" , priority = 15 , block = False )
14
28
crazy_jp = on_regex (pattern = r"^狂乱\S曜日$" , priority = 15 , block = False )
15
29
30
+
16
31
async def get_weekday_cn (arg : str = RegexMatched ()) -> str :
17
32
return arg [- 1 ].replace ("天" , "日" )
18
33
34
+
19
35
async def get_weekday_jp (arg : str = RegexMatched ()) -> str :
20
36
return arg [2 ]
21
-
37
+
38
+
22
39
@crazy_cn .handle ()
23
40
async def _ (matcher : Matcher , weekday : str = Depends (get_weekday_cn )):
24
- await matcher .finish (rndKfc (weekday ))
41
+ await matcher .finish (randomKFC (weekday ))
42
+
25
43
26
44
@crazy_jp .handle ()
27
45
async def _ (matcher : Matcher , weekday : str = Depends (get_weekday_jp )):
28
- await matcher .finish (rndKfc (weekday ))
46
+ await matcher .finish (randomKFC (weekday ))
47
+
29
48
30
- def rndKfc (day : str ) -> str :
49
+ def randomKFC (day : str ) -> str :
31
50
# jp en cn
32
- tb : List [str ] = ["月" , "Monday" , "一" , "火" , "Tuesday" , "二" , "水" , "Wednesday" , "三" , "木" , "Thursday" , "四" , "金" , "Friday" , "五" , "土" , "Saturday" , "六" , "日" , "Sunday" , "日" ]
51
+ tb : List [str ] = ["月" , "Monday" , "一" , "火" , "Tuesday" , "二" , "水" , "Wednesday" , "三" ,
52
+ "木" , "Thursday" , "四" , "金" , "Friday" , "五" , "土" , "Saturday" , "六" , "日" , "Sunday" , "日" ]
33
53
if day not in tb :
34
54
return "给个准确时间,OK?"
35
-
55
+
36
56
# Get the weekday group index
37
57
idx : int = int (tb .index (day )/ 3 )* 3
38
-
58
+
39
59
# json数据存放路径
40
60
path : Path = crazy_config .crazy_path / "post.json"
41
-
61
+
42
62
# 将json对象加载到数组
43
63
with open (path , "r" , encoding = "utf-8" ) as f :
44
64
kfc = json .load (f ).get ("post" )
45
-
65
+
46
66
# 随机选取数组中的一个对象,并替换日期
47
- return random .choice (kfc ).replace ("木曜日" , tb [idx ] + "曜日" ).replace ("Thursday" , tb [idx + 1 ]).replace ("thursday" , tb [idx + 1 ]).replace ("星期四" , "星期" + tb [idx + 2 ]).replace ("周四" , "周" + tb [idx + 2 ]).replace ("礼拜四" , "礼拜" + tb [idx + 2 ])
67
+ return random .choice (kfc ).replace ("木曜日" , tb [idx ] + "曜日" ).replace ("Thursday" , tb [idx + 1 ]).replace ("thursday" , tb [idx + 1 ]).replace ("星期四" , "星期" + tb [idx + 2 ]).replace ("周四" , "周" + tb [idx + 2 ]).replace ("礼拜四" , "礼拜" + tb [idx + 2 ])
0 commit comments