-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from MinatoAquaCrews/dev
🔖 v0.2.8
- Loading branch information
Showing
10 changed files
with
341 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
import json | ||
import random | ||
from typing import Annotated, List | ||
from pathlib import Path | ||
from typing import Annotated | ||
|
||
from nonebot import on_regex | ||
from nonebot.matcher import Matcher | ||
from nonebot.params import Depends, RegexStr | ||
from nonebot.plugin import PluginMetadata | ||
|
||
from .config import * | ||
|
||
__crazy_thursday_version__ = "v0.2.7" | ||
__crazy_thursday_usages__ = f""" | ||
KFC疯狂星期四 {__crazy_thursday_version__} | ||
__plugin_version__ = "v0.2.8" | ||
__plugin_usages__ = f""" | ||
KFC疯狂星期四 {__plugin_version__} | ||
[疯狂星期X] 随机输出KFC疯狂星期四文案 | ||
[狂乱X曜日] 随机输出KFC疯狂星期四文案""".strip() | ||
|
||
__plugin_meta__ = PluginMetadata( | ||
name="疯狂星期四", | ||
description="持续疯狂!KFC疯狂星期四🍗", | ||
usage=__crazy_thursday_usages__, | ||
usage=__plugin_usages__, | ||
type="application", | ||
homepage="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday", | ||
extra={ | ||
"author": "KafCoppelia <[email protected]>", | ||
"version": __crazy_thursday_version__, | ||
"version": __plugin_version__, | ||
}, | ||
) | ||
|
||
crazy_cn = on_regex(pattern=r"^疯狂星期\S$", priority=15, block=False) | ||
crazy_jp = on_regex(pattern=r"^狂乱\S曜日$", priority=15, block=False) | ||
crazy_cn = on_regex(pattern=r"^疯狂星期\S$", priority=15) | ||
crazy_jp = on_regex(pattern=r"^狂乱\S曜日$", priority=15) | ||
|
||
|
||
async def get_weekday_cn(arg: Annotated[str, RegexStr()]) -> str: | ||
|
@@ -46,51 +48,52 @@ async def _(matcher: Matcher, weekday: Annotated[str, Depends(get_weekday_jp)]): | |
await matcher.finish(randomKFC(weekday)) | ||
|
||
|
||
# jp en cn | ||
weekday_table = [ | ||
"月", | ||
"Monday", | ||
"一", | ||
"火", | ||
"Tuesday", | ||
"二", | ||
"水", | ||
"Wednesday", | ||
"三", | ||
"木", | ||
"Thursday", | ||
"四", | ||
"金", | ||
"Friday", | ||
"五", | ||
"土", | ||
"Saturday", | ||
"六", | ||
"日", | ||
"Sunday", | ||
"日", | ||
] | ||
|
||
|
||
def randomKFC(day: str) -> str: | ||
# jp en cn | ||
tb: List[str] = [ | ||
"月", | ||
"Monday", | ||
"一", | ||
"火", | ||
"Tuesday", | ||
"二", | ||
"水", | ||
"Wednesday", | ||
"三", | ||
"木", | ||
"Thursday", | ||
"四", | ||
"金", | ||
"Friday", | ||
"五", | ||
"土", | ||
"Saturday", | ||
"六", | ||
"日", | ||
"Sunday", | ||
"日", | ||
] | ||
if day not in tb: | ||
if day not in weekday_table: | ||
return "给个准确时间,OK?" | ||
|
||
# Get the weekday group index | ||
idx: int = int(tb.index(day) / 3) * 3 | ||
|
||
# json数据存放路径 | ||
path: Path = crazy_config.crazy_path / "post.json" | ||
idx = int(weekday_table.index(day) / 3) * 3 | ||
|
||
# 将json对象加载到数组 | ||
with open(path, "r", encoding="utf-8") as f: | ||
kfc = json.load(f).get("post") | ||
with open(Path(__file__).parent / "post.json", "r", encoding="utf-8") as f: | ||
kfc = json.load(f).get("post", None) | ||
if kfc is None: | ||
raise KeyError("Key 'post' is missing.") | ||
|
||
# 随机选取数组中的一个对象,并替换日期 | ||
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]) | ||
.replace("木曜日", weekday_table[idx] + "曜日") | ||
.replace("Thursday", weekday_table[idx + 1]) | ||
.replace("thursday", weekday_table[idx + 1]) | ||
.replace("星期四", "星期" + weekday_table[idx + 2]) | ||
.replace("周四", "周" + weekday_table[idx + 2]) | ||
.replace("礼拜四", "礼拜" + weekday_table[idx + 2]) | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.