Skip to content

Commit

Permalink
Merge pull request #27 from MinatoAquaCrews/dev
Browse files Browse the repository at this point in the history
🔖 v0.2.8
  • Loading branch information
KafCoppelia authored Oct 7, 2023
2 parents 5d73082 + 0c708a5 commit 4734a3a
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 375 deletions.
9 changes: 7 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ categories:
- "bug"
- title: "🧰 Maintenance"
label: "chore"
- title: "📝 Doc"
labels:
- "documentation"

change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
name-template: "v$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
change-template: "- $TITLE [@$AUTHOR](https://github.com/$AUTHOR) ([#$NUMBER]($URL))"
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
Expand All @@ -33,4 +38,4 @@ template: |
$CHANGES
Changelog: [`$PREVIOUS_TAG...`](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/compare/$PREVIOUS_TAG...)
Changelog: [`$PREVIOUS_TAG...`](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION)
4 changes: 2 additions & 2 deletions .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG_NAME }}

- name: Publish python poetry package
uses: JRubics/poetry-publish@v1.16
uses: JRubics/poetry-publish@v1
with:
python_version: "3.10"
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Release Drafter

on:
push:
tags:
- v*
pull_request_target:
branches:
- master

pull_request:
types: [opened, reopened, synchronize]
types:
- closed

permissions:
contents: read
Expand All @@ -19,7 +21,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: master

Expand Down
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ repos:
stages: [commit]

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.9.1
hooks:
- id: black
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.9-for-vscode
rev: v3.0.3
hooks:
- id: prettier
types_or: [markdown, yaml, json]
Expand All @@ -34,3 +34,9 @@ repos:
- id: check-added-large-files
- id: mixed-line-ending
- id: check-json

- repo: https://github.com/python-poetry/poetry
rev: 1.6.1
hooks:
- id: poetry-check
- id: poetry-lock
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

# Crazy Thursday
# KFC Crazy Thursday

_🍗 疯狂星期四 🍗_

Expand All @@ -13,10 +13,10 @@ _🍗 疯狂星期四 🍗_
</a>

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

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

Expand All @@ -36,27 +36,20 @@ _🍗 疯狂星期四 🍗_

## 版本

[v0.2.7](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.7)
[v0.2.8](https://github.com/MinatoAquaCrews/nonebot_plugin_crazy_thursday/releases/tag/v0.2.8)

⚠ 适配nonebot2-2.0.0rc4+
⚠ 适配nonebot2-2.0.0+

## 安装

1. 通过 `pip``nb` 安装;
1. 通过 `pip``nb-cli` 安装;

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

```python
CRAZY_PATH="your-path-to-post.json"
CRAZY_AUTO_UPDATE=false
```
2. 文案资源默认位于**插件同级目录**下;

## 功能

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

⚠ 每次启动插件会自动尝试从repo中下载最新的文案资源!

## 命令

1. 天天疯狂,疯狂星期[一|二|三|四|五|六|日|天],输入**疯狂星期八**等不合法时间将提示;
Expand Down
97 changes: 50 additions & 47 deletions nonebot_plugin_crazy_thursday/__init__.py
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:
Expand All @@ -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])
)
89 changes: 0 additions & 89 deletions nonebot_plugin_crazy_thursday/config.py

This file was deleted.

Loading

0 comments on commit 4734a3a

Please sign in to comment.