Skip to content

Commit 64b521a

Browse files
committed
refactor: code and update posts
1 parent 69ab955 commit 64b521a

File tree

4 files changed

+67
-35
lines changed

4 files changed

+67
-35
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,34 @@ _🍗 天天疯狂 🍗_
1212
<p align="center">
1313

1414
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/blob/main/LICENSE">
15-
<img src="https://img.shields.io/badge/license-MIT-informational">
15+
<img src="https://img.shields.io/github/license/MinatoAquaCrews/nonebot_plugin_crazy_thursday?color=blue">
1616
</a>
1717

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

22-
<a href="">
23-
<img src="https://img.shields.io/badge/release-v0.2.2-orange">
22+
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.3">
23+
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_crazy_thursday?color=orange">
2424
</a>
25+
26+
<a href="https://www.codefactor.io/repository/github/MinatoAquaCrews/nonebot_plugin_crazy_thursday">
27+
<img src="https://img.shields.io/codefactor/grade/github/MinatoAquaCrews/nonebot_plugin_crazy_thursday/beta?color=red">
28+
</a>
29+
2530

2631
</p>
2732
</p>
2833

2934
## 版本
3035

31-
v0.2.2
36+
v0.2.3
3237

3338
⚠ 适配nonebot2-2.0.0beta.2;
3439

3540
👉 适配alpha.16版本参见[alpha.16分支](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/tree/alpha.16)
3641

37-
[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.2)
42+
[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.3)
3843

3944
## 安装
4045

@@ -50,7 +55,7 @@ CRAZY_PATH="your-path-to-post.json"
5055

5156
天天疯狂!随机输出KFC疯狂星期四文案。
5257

53-
**重磅新增** 三十余条文案!~~更新假面骑士国配文案~~
58+
**新增** 三十余条文案!
5459

5560
## 命令
5661

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
from random import choice
2-
import os
32
from pathlib import Path
43
from re import match
5-
import nonebot
6-
from nonebot import on_command, on_regex
7-
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, GROUP
4+
from typing import Optional
5+
from nonebot.matcher import Matcher
6+
from nonebot import get_driver, on_regex
7+
from nonebot.adapters.onebot.v11 import MessageEvent
88
try:
99
import ujson as json
1010
except ModuleNotFoundError:
1111
import json
1212

13-
global_config = nonebot.get_driver().config
13+
global_config = get_driver().config
1414
if not hasattr(global_config, 'crazy_path'):
15-
CRAZY_PATH = os.path.join(os.path.dirname(__file__), 'resource')
15+
CRAZY_PATH = Path(__file__).parent / "resource"
1616
else:
1717
CRAZY_PATH = global_config.crazy_path
1818

19-
__crazy_vsrsion__ = 'v0.2.2'
20-
plugin_notes = f'''
21-
KFC疯狂星期四 {__crazy_vsrsion__}
19+
# 插件用法简单,无需帮助
20+
__crazy_thursday_vsrsion__ = 'v0.2.3'
21+
__crazy_thursday_notes__ = f'''
22+
KFC疯狂星期四 {__crazy_thursday_vsrsion__}
2223
[疯狂星期X] 随机输出KFC疯狂星期四文案
2324
[狂乱X曜日] 随机输出KFC疯狂星期四文案'''.strip()
2425

25-
plugin_help = on_command('疯狂星期四帮助', permission=GROUP, priority=15, block=True)
26-
crazy = on_regex(r'疯狂星期\S', permission=GROUP, priority=15, block=True)
27-
crazy_jp = on_regex(r'狂乱\S曜日', permission=GROUP, priority=15, block=True)
26+
crazy = on_regex(r'疯狂星期\S', priority=15)
27+
crazy_jp = on_regex(r'狂乱\S曜日', priority=15)
2828

29-
@plugin_help.handle()
30-
async def _(bot: Bot, event: GroupMessageEvent):
31-
await plugin_help.finish(plugin_notes)
29+
@crazy.handle()
30+
async def _(matcher: Matcher, event: MessageEvent):
31+
await matcher.finish(rndKfc(event.get_plaintext()))
32+
33+
@crazy_jp.handle()
34+
async def _(matcher: Matcher, event: MessageEvent):
35+
await matcher.finish(rndKfc(event.get_plaintext(), True))
3236

33-
def rndKfc(msg, jp = False):
37+
def rndKfc(msg: str, jp: Optional[bool] = False):
3438
day = (match(r'狂乱(\S)曜日', msg) if jp else match(r'疯狂星期(\S)', msg.replace('天', '日'))).group(1)
3539
tb = ['月', '一', '火', '二', '水', '三', '木', '四', '金', '五', '土', '六', '日', '日']
3640
if day not in tb:
@@ -42,12 +46,4 @@ def rndKfc(msg, jp = False):
4246
with open(path, 'r', encoding='utf-8') as f:
4347
kfc = json.load(f).get('post')
4448
# 随机选取数组中的一个对象
45-
return choice(kfc).replace('星期四', '星期' + tb[idx+1]).replace('周四', '周' + tb[idx+1]).replace('木曜日', tb[idx] + '曜日')
46-
47-
@crazy.handle()
48-
async def _(bot: Bot, event: GroupMessageEvent):
49-
await crazy.finish(rndKfc(event.get_plaintext()))
50-
51-
@crazy_jp.handle()
52-
async def _(bot: Bot, event: GroupMessageEvent):
53-
await crazy_jp.finish(rndKfc(event.get_plaintext(), True))
49+
return choice(kfc).replace('星期四', '星期' + tb[idx+1]).replace('周四', '周' + tb[idx+1]).replace('木曜日', tb[idx] + '曜日')

0 commit comments

Comments
 (0)