Skip to content

Commit a9402ed

Browse files
author
KafCoppelia
committed
v0.2.1 for beta.1+🥳
1 parent a597ba5 commit a9402ed

File tree

5 files changed

+147
-65
lines changed

5 files changed

+147
-65
lines changed

README.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,47 @@ _🍗 天天疯狂 🍗_
1616
</a>
1717

1818
<a href="https://github.com/nonebot/nonebot2">
19-
<img src="https://img.shields.io/badge/nonebot2-2.0.0beta.1-green">
19+
<img src="https://img.shields.io/badge/nonebot2-2.0.0beta.1+-green">
2020
</a>
2121

2222
<a href="">
23-
<img src="https://img.shields.io/badge/release-v0.2.0-orange">
23+
<img src="https://img.shields.io/badge/release-v0.2.1-orange">
2424
</a>
2525

2626
</p>
2727
</p>
2828

2929
## 版本
3030

31-
v0.2.0
31+
v0.2.1
3232

33-
⚠ 适配nonebot2-2.0.0beta.1;适配alpha.16版本参见[alpha.16分支](https://github.com/KafCoppelia/nonebot_plugin_crazy_thursday/tree/alpha.16)
33+
⚠ 适配nonebot2-2.0.0beta.1+;
34+
35+
👉 适配alpha.16版本参见[alpha.16分支](https://github.com/KafCoppelia/nonebot_plugin_crazy_thursday/tree/alpha.16)
36+
37+
[更新日志](https://github.com/KafCoppelia/nonebot_plugin_crazy_thursday/releases/tag/v0.2.1)
3438

3539
## 安装
3640

37-
1. 通过`pip``nb`安装,版本请指定`^0.2.0`
41+
1. 通过`pip``nb`安装,版本请指定`0.2.1`
3842

39-
2. 读取文案的默认路径位于`./resource`下;
43+
2. 读取文案的默认路径位于`./resource`下;可在`.env.*`下设置:
44+
45+
```python
46+
CRAZY_PATH="your-path-to-post.json"
47+
```
4048

4149
## 功能
4250

4351
天天疯狂!随机输出KFC疯狂星期四文案。
4452

53+
**新增** 三十余条文案!
54+
4555
## 命令
4656

47-
1. 天天疯狂,疯狂星期[一|二|三|四|五|六|日]
57+
1. 天天疯狂,疯狂星期[一|二|三|四|五|六|日],输入**疯狂星期八**等不合法时间将提示
4858

49-
2. 输入**疯狂星期八**等不合法时间将提示
59+
2. **新增**:支持狂乱[月|火|水|木|金|土|日]曜日日文触发
5060

5161
## 本插件改自HoshinoBot疯狂星期四插件
5262

+56-15
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,72 @@
11
import random
2-
import json
32
import os
3+
from pathlib import Path
44
import re
55
import nonebot
6-
from nonebot.typing import T_State
7-
from nonebot.params import State
8-
from nonebot import on_regex
6+
from nonebot import on_command, on_regex
97
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, GROUP
8+
try:
9+
import ujson as json
10+
except ModuleNotFoundError:
11+
import json
1012

11-
_CRAZY_PATH = nonebot.get_driver().config.crazy_path
12-
CRAZY_PATH = os.path.join(os.path.dirname(__file__), "resource") if not _CRAZY_PATH else _CRAZY_PATH
13+
global_config = nonebot.get_driver().config
14+
if not hasattr(global_config, "crazy_path"):
15+
CRAZY_PATH = os.path.join(os.path.dirname(__file__), "resource")
16+
else:
17+
CRAZY_PATH = global_config.crazy_path
1318

14-
# V我50
19+
__crazy_vsrsion__ = "v0.2.1"
20+
plugin_notes = f'''
21+
KFC疯狂星期四 {__crazy_vsrsion__}
22+
[疯狂星期X] 随机输出KFC疯狂星期四文案
23+
[狂乱X曜日] 随机输出KFC疯狂星期四文案'''.strip()
24+
25+
plugin_help = on_command("疯狂星期四帮助", permission=GROUP, priority=15, block=True)
1526
crazy = on_regex(r'疯狂星期.', permission=GROUP, priority=15, block=True)
27+
crazy_jp = on_regex(r'狂乱.曜日', permission=GROUP, priority=15, block=True)
28+
29+
@plugin_help.handle()
30+
async def _(bot: Bot, event: GroupMessageEvent):
31+
await plugin_help.finish(plugin_notes)
1632

1733
@crazy.handle()
18-
async def _(bot: Bot, event: GroupMessageEvent, state: T_State=State()):
19-
iscrazy = re.search(r'(.*?)星期[一|二|三|四|五|六|日]', event.get_plaintext())
20-
crazy_day = iscrazy.group(0)[-3:] if iscrazy is not None else None
34+
async def _(bot: Bot, event: GroupMessageEvent):
35+
iscrazy = re.search(r'疯狂星期[一|二|三|四|五|六|日]', event.get_plaintext())
36+
crazy_day = iscrazy.group(0)[-1] if iscrazy is not None else None
2137
if crazy_day is None:
2238
await crazy.finish("给个准确时间,OK?")
2339

2440
# json数据存放路径
25-
filePath = os.path.join(CRAZY_PATH, "post.json")
41+
filePath = Path(CRAZY_PATH) / "post.json"
2642
# 将json对象加载到数组
27-
kfc = json.load(open(filePath, 'r', encoding="UTF-8")).get('post')
43+
with open(filePath, "r", encoding="utf-8") as f:
44+
kfc = json.load(f).get("post")
2845
# 随机选取数组中的一个对象
29-
randomPost = random.choice(kfc)
30-
randomPost = randomPost.replace("星期四", crazy_day)
31-
await bot.send(event=event, message=randomPost)
46+
randomPost = random.choice(kfc).replace("星期四", "星期" + crazy_day).replace("周四", "周" + crazy_day)
47+
await crazy.finish(randomPost)
48+
49+
@crazy_jp.handle()
50+
async def _(bot: Bot, event: GroupMessageEvent):
51+
iscrazy = re.search(r'狂乱[月|火|水|木|金|土|日]曜日', event.get_plaintext())
52+
crazy_day = iscrazy.group(0)[-3] if iscrazy is not None else None
53+
54+
if crazy_day is None:
55+
await crazy_jp.finish("给个准确时间,OK?")
56+
57+
filePath = Path(CRAZY_PATH) / "post.json"
58+
with open(filePath, "r", encoding="utf-8") as f:
59+
kfc = json.load(f).get("post")
60+
61+
randomPost = random.choice(kfc).replace("星期四", "星期" + weekday_table[crazy_day]).replace("周四", "周" + weekday_table[crazy_day])
62+
await crazy_jp.finish(randomPost)
63+
64+
weekday_table = {
65+
"月": "一",
66+
"火": "二",
67+
"水": "三",
68+
"木": "四",
69+
"金": "五",
70+
"土": "六",
71+
"日": "日"
72+
}

0 commit comments

Comments
 (0)