Skip to content

Commit d2b6849

Browse files
authored
Merge pull request #22 from MinatoAquaCrews/dev
🔖 v0.2.6.post2: add PluginMetadata
2 parents 2cd5667 + 247e850 commit d2b6849

File tree

9 files changed

+255
-209
lines changed

9 files changed

+255
-209
lines changed

.github/release-drafter.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ version-resolver:
2626
patch:
2727
labels:
2828
- "patch"
29-
default: patch
29+
default: patch
30+
31+
template: |
32+
## What’s Changed
33+
34+
$CHANGES
35+
36+
Changelog: [`$PREVIOUS_TAG...`](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/compare/$PREVIOUS_TAG...)

.github/workflows/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
13+
target-branch: "master"

.github/workflows/poetry-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
python_version: "3.10"
3131
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
3232
build_format: "wheel"
33-
ignore_dev_requirements: "yes"
33+
ignore_dev_requirements: "yes"

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ repos:
3333
- id: check-yaml
3434
- id: check-added-large-files
3535
- id: mixed-line-ending
36-
- id: check-json
36+
- id: check-json

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ _🍗 疯狂星期四 🍗_
77
</div>
88

99
<p align="center">
10-
10+
1111
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/blob/master/LICENSE">
1212
<img src="https://img.shields.io/github/license/MinatoAquaCrews/nonebot_plugin_crazy_thursday?color=blue">
1313
</a>
14-
14+
1515
<a href="https://github.com/nonebot/nonebot2">
1616
<img src="https://img.shields.io/badge/nonebot2-2.0.0rc1+-green">
1717
</a>
18-
19-
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6.post1">
18+
19+
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6.post2">
2020
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_crazy_thursday?color=orange">
2121
</a>
2222

@@ -31,12 +31,12 @@ _🍗 疯狂星期四 🍗_
3131
<a href="https://results.pre-commit.ci/latest/github/MinatoAquaCrews/nonebot_plugin_crazy_thursday/master">
3232
<img src="https://results.pre-commit.ci/badge/github/MinatoAquaCrews/nonebot_plugin_crazy_thursday/master.svg" alt="pre-commit.ci status">
3333
</a>
34-
34+
3535
</p>
3636

3737
## 版本
3838

39-
[v0.2.6.post1](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6.post1)
39+
[v0.2.6.post2](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6.post2)
4040

4141
⚠ 适配nonebot2-2.0.0rc1+
4242

@@ -46,10 +46,10 @@ _🍗 疯狂星期四 🍗_
4646

4747
2. 文案的默认路径位于**插件同级目录**下;也可放置在别处,在 `.env` 下设置即可;`CRAZY_AUTO_UPDATE` 默认关闭,开启则插件将在启动时自动检查资源更新。例如:
4848

49-
```python
50-
CRAZY_PATH="your-path-to-post.json"
51-
CRAZY_AUTO_UPDATE=false
52-
```
49+
```python
50+
CRAZY_PATH="your-path-to-post.json"
51+
CRAZY_AUTO_UPDATE=false
52+
```
5353

5454
## 功能
5555

@@ -65,4 +65,4 @@ _🍗 疯狂星期四 🍗_
6565

6666
## 本插件改自
6767

68-
[HoshinoBot-fucking_crazy_thursday](https://github.com/Nicr0n/fucking_crazy_thursday)
68+
[HoshinoBot-fucking_crazy_thursday](https://github.com/Nicr0n/fucking_crazy_thursday)
+32-12
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,67 @@
11
import random
2+
from typing import List
3+
24
from nonebot import on_regex
35
from nonebot.matcher import Matcher
46
from nonebot.params import Depends, RegexMatched
7+
from nonebot.plugin import PluginMetadata
8+
59
from .config import *
610

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"""
913
KFC疯狂星期四 {__crazy_thursday_version__}
1014
[疯狂星期X] 随机输出KFC疯狂星期四文案
1115
[狂乱X曜日] 随机输出KFC疯狂星期四文案""".strip()
1216

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+
1327
crazy_cn = on_regex(pattern=r"^疯狂星期\S$", priority=15, block=False)
1428
crazy_jp = on_regex(pattern=r"^狂乱\S曜日$", priority=15, block=False)
1529

30+
1631
async def get_weekday_cn(arg: str = RegexMatched()) -> str:
1732
return arg[-1].replace("天", "日")
1833

34+
1935
async def get_weekday_jp(arg: str = RegexMatched()) -> str:
2036
return arg[2]
21-
37+
38+
2239
@crazy_cn.handle()
2340
async def _(matcher: Matcher, weekday: str = Depends(get_weekday_cn)):
24-
await matcher.finish(rndKfc(weekday))
41+
await matcher.finish(randomKFC(weekday))
42+
2543

2644
@crazy_jp.handle()
2745
async def _(matcher: Matcher, weekday: str = Depends(get_weekday_jp)):
28-
await matcher.finish(rndKfc(weekday))
46+
await matcher.finish(randomKFC(weekday))
47+
2948

30-
def rndKfc(day: str) -> str:
49+
def randomKFC(day: str) -> str:
3150
# 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", "日"]
3353
if day not in tb:
3454
return "给个准确时间,OK?"
35-
55+
3656
# Get the weekday group index
3757
idx: int = int(tb.index(day)/3)*3
38-
58+
3959
# json数据存放路径
4060
path: Path = crazy_config.crazy_path / "post.json"
41-
61+
4262
# 将json对象加载到数组
4363
with open(path, "r", encoding="utf-8") as f:
4464
kfc = json.load(f).get("post")
45-
65+
4666
# 随机选取数组中的一个对象,并替换日期
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])

nonebot_plugin_crazy_thursday/config.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from pathlib import Path
2+
from typing import Any, Dict, Union
3+
4+
import httpx
15
from nonebot import get_driver
26
from nonebot.log import logger
37
from pydantic import BaseModel, Extra
4-
from pathlib import Path
5-
from typing import Union, Dict, Any
6-
import httpx
8+
79
try:
810
import ujson as json
911
except ModuleNotFoundError:
@@ -29,7 +31,7 @@ class ResourceError(Exception):
2931

3032
async def download_url() -> Union[Dict[str, Any], None]:
3133
url: str = "https://raw.fgit.ml/MinatoAquaCrews/nonebot_plugin_crazy_thursday/master/nonebot_plugin_crazy_thursday/post.json"
32-
34+
3335
async with httpx.AsyncClient() as client:
3436
for i in range(3):
3537
try:
@@ -40,7 +42,8 @@ async def download_url() -> Union[Dict[str, Any], None]:
4042
return response.json()
4143

4244
except Exception:
43-
logger.warning(f"Error occured when downloading {url}, {i+1}/3")
45+
logger.warning(
46+
f"Error occured when downloading {url}, {i+1}/3")
4447

4548
logger.warning("Abort downloading")
4649
return None
@@ -54,7 +57,7 @@ async def kfc_post_check() -> None:
5457
Otherwise just abort it.
5558
'''
5659
json_path: Path = crazy_config.crazy_path / "post.json"
57-
60+
5861
cur_version: float = 0
5962
if json_path.exists():
6063
with json_path.open("r", encoding="utf-8") as f:
@@ -74,11 +77,14 @@ async def kfc_post_check() -> None:
7477
try:
7578
version: float = response.get("version", 0)
7679
except KeyError:
77-
logger.warning("KFC post text resource downloaded incompletely! Please check!")
80+
logger.warning(
81+
"KFC post text resource downloaded incompletely! Please check!")
7882
raise DownloadError
7983

8084
# Update when there is a newer version
8185
if version > cur_version:
8286
with json_path.open("w", encoding="utf-8") as f:
8387
json.dump(response, f, ensure_ascii=False, indent=4)
84-
logger.info(f"Updated post.json, version: {cur_version} -> {version}")
88+
89+
logger.info(
90+
f"Updated post.json, version: {cur_version} -> {version}")

0 commit comments

Comments
 (0)