Skip to content

Commit

Permalink
v0.2.6a1: fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
KafCoppelia committed Oct 8, 2022
1 parent 889d703 commit 57e90f3
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 465 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- prettier-ignore-start -->
<!-- markdownlint-disable-next-line MD036 -->
_🍗 天天疯狂 🍗_
_🍗 疯狂星期四 🍗_
<!-- prettier-ignore-end -->

</div>
Expand All @@ -16,10 +16,10 @@ _🍗 天天疯狂 🍗_
</a>

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

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.5">
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6a1">
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_crazy_thursday?color=orange">
</a>

Expand All @@ -31,11 +31,11 @@ _🍗 天天疯狂 🍗_

## 版本

v0.2.5
v0.2.6a1

⚠ 适配nonebot2-2.0.0beta.2+
⚠ 适配nonebot2-2.0.0rc1+

[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.5)
[更新日志](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.6a1)

## 安装

Expand Down
37 changes: 14 additions & 23 deletions nonebot_plugin_crazy_thursday/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import random
from typing import Coroutine, Any
from typing import List
from pathlib import Path
from nonebot import on_regex
from nonebot.typing import T_State
from nonebot.matcher import Matcher
from nonebot.params import Depends, RegexMatched
from .config import crazy_config
Expand All @@ -17,39 +16,31 @@
[疯狂星期X] 随机输出KFC疯狂星期四文案
[狂乱X曜日] 随机输出KFC疯狂星期四文案""".strip()

crazy = on_regex(pattern=r"^疯狂星期\S$", priority=15)
crazy_cn = on_regex(pattern=r"^疯狂星期\S$", priority=15)
crazy_jp = on_regex(pattern=r"^狂乱\S曜日$", priority=15)

def get_weekday_cn() -> Coroutine[Any, Any, None]:
async def _get_weekday_cn(matcher: Matcher, arg: str = RegexMatched()) -> None:
matcher.set_arg("weekday", arg[-1].replace("天", "日"))

return _get_weekday_cn
async def get_weekday_cn(arg: str = RegexMatched()) -> str:
return arg[-1].replace("天", "日")

def get_weekday_jp() -> Coroutine[Any, Any, None]:
async def _get_weekday_jp(matcher: Matcher, arg: str = RegexMatched()) -> None:
matcher.set_arg("weekday", arg[2])

return _get_weekday_jp
async def get_weekday_jp(arg: str = RegexMatched()) -> str:
return arg[2]

@crazy.handle()
async def _(matcher: Matcher, state: T_State = Depends(get_weekday_cn)):
weekday = state["weekday"]
@crazy_cn.handle()
async def _(matcher: Matcher, weekday: str = Depends(get_weekday_cn)):
await matcher.finish(rndKfc(weekday))

@crazy_jp.handle()
async def _(matcher: Matcher, state: T_State = Depends(get_weekday_jp)):
weekday = state["weekday"]
async def _(matcher: Matcher, weekday: str = Depends(get_weekday_jp)):
await matcher.finish(rndKfc(weekday))

def rndKfc(day: str):
def rndKfc(day: str) -> str:
# jp en cn
tb = ["月", "Monday", "一", "火", "Tuesday", "二", "水", "Wednesday", "三", "木", "Thursday", "四", "金", "Friday", "五", "土", "Saturday", "六", "日", "Sunday", "日"]
tb: List[str] = ["月", "Monday", "一", "火", "Tuesday", "二", "水", "Wednesday", "三", "木", "Thursday", "四", "金", "Friday", "五", "土", "Saturday", "六", "日", "Sunday", "日"]
if day not in tb:
return "给个准确时间,OK?"

# Get the weekday group index
idx = int(tb.index(day)/3)*3
idx: int = int(tb.index(day)/3)*3

# json数据存放路径
path: Path = crazy_config.crazy_path / "post.json"
Expand All @@ -58,5 +49,5 @@ def rndKfc(day: str):
with open(path, "r", encoding="utf-8") as f:
kfc = json.load(f).get("post")

# 随机选取数组中的一个对象,替换关键字
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])
# 随机选取数组中的一个对象,并替换日期
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])
14 changes: 6 additions & 8 deletions nonebot_plugin_crazy_thursday/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from nonebot import get_driver, logger
from nonebot import get_driver
from nonebot.log import logger
from pydantic import BaseModel, Extra
from pathlib import Path
from typing import Union
from pathlib import Path
from typing import Union, Dict, List
import httpx
try:
import ujson as json
Expand Down Expand Up @@ -41,10 +42,7 @@ async def post_check() -> None:
If failed and post dosen't exists, raise exception
Otherwise just abort downloading
'''
if not crazy_config.crazy_path.exists():
crazy_config.crazy_path.mkdir(parents=True, exist_ok=True)

json_path = crazy_config.crazy_path / "post.json"
json_path: Path = crazy_config.crazy_path / "post.json"

url = "https://raw.fastgit.org/MinatoAquaCrews/nonebot_plugin_crazy_thursday/beta/nonebot_plugin_crazy_thursday/post.json"
response = await download_url(url)
Expand All @@ -53,7 +51,7 @@ async def post_check() -> None:
logger.warning("Crazy Thursday resource missing! Please check!")
raise ResourceError
else:
docs = response.json()
docs: Dict[str, Union[float, List[str]]] = response.json()
version = docs.get("version")

with json_path.open("w", encoding="utf-8") as f:
Expand Down
Loading

0 comments on commit 57e90f3

Please sign in to comment.