Skip to content

Commit

Permalink
Merge pull request #34 from MinatoAquaCrews/dev
Browse files Browse the repository at this point in the history
fix: logic of auto update check at startup
  • Loading branch information
KafCoppelia authored Mar 28, 2023
2 parents 0e49713 + 8e3c445 commit 92e99bf
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ version-resolver:
default: patch

template: |
适配b3+
## What’s Changed
Update Log 23/
$CHANGES
Changelog: [`$PREVIOUS_TAG...`](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/compare/$PREVIOUS_TAG...)
6 changes: 6 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- master

pull_request:
types: [opened, reopened, synchronize]

permissions:
contents: read

Expand All @@ -23,6 +26,9 @@ jobs:
- name: Setup Poetry
uses: Gr1N/setup-poetry@v8

- name: Update poetry.lock
run: poetry update --lock

- run: echo "TAG_NAME=v$(poetry version -s)" >> $GITHUB_ENV

- uses: release-drafter/release-drafter@v5
Expand Down
2 changes: 1 addition & 1 deletion How-to-add-new-tarot-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
将其放入 `TAROT_PATH` 目录下即可。例如,以上示例,**所有的塔罗牌资源**均在 `MyTarotResource` 目录下,则设置:

```
TAROT_PATH="your/path/to/MyTarotResource"
TAROT_PATH="your-path-to-MyTarotResource"
```

Enjoy!🥳
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _🔮 塔罗牌 🔮_
<img src="https://img.shields.io/badge/nonebot2-2.0.0b3+-green">
</a>

<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post2">
<a href="https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post3">
<img src="https://img.shields.io/github/v/release/MinatoAquaCrews/nonebot_plugin_tarot?color=orange">
</a>

Expand All @@ -40,7 +40,7 @@ _“许多傻瓜对千奇百怪的迷信说法深信不疑:象牙、护身符

## 版本

💥 [v0.4.0.post2](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post2)
🧰 [v0.4.0.post3](https://github.com/MinatoAquaCrews/nonebot_plugin_tarot/releases/tag/v0.4.0.post3)

⚠ 适配nonebot2-2.0.0b3+

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tarot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .data_source import tarot_manager

__tarot_version__ = "v0.4.0.post2"
__tarot_version__ = "v0.4.0.post3"
__tarot_usages__ = f'''
塔罗牌 {__tarot_version__}
[占卜] 随机选取牌阵进行占卜
Expand Down
54 changes: 28 additions & 26 deletions nonebot_plugin_tarot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,36 @@ async def tarot_version_check() -> None:

tarot_json_path: Path = Path(__file__).parent / "tarot.json"

# Auto update check on startup when tarot_auto_update is True
if tarot_config.tarot_auto_update:
cur_version: float = 0
if tarot_json_path.exists():
with tarot_json_path.open("r", encoding="utf-8") as f:
data = json.load(f)
cur_version = data.get("version", 0)
cur_version: float = 0
if tarot_json_path.exists():
with tarot_json_path.open("r", encoding="utf-8") as f:
data = json.load(f)
cur_version = data.get("version", 0)

# Auto update check on startup if TAROT_AUTO_UPDATE
if tarot_config.tarot_auto_update:
response: Dict[str, Any] = await download_url("tarot.json", is_json=True)

if response is None:
if not tarot_json_path.exists():
logger.warning("Tarot text resource missing! Please check!")
raise ResourceError("Missing necessary resource: tarot.json!")
else:
try:
version: float = response.get("version", 0)
except KeyError:
logger.warning(
"Tarot text resource downloaded incompletely! Please check!")
raise DownloadError

# Update when there is a newer version
if version > cur_version:
with tarot_json_path.open("w", encoding="utf-8") as f:
json.dump(response, f, ensure_ascii=False, indent=4)
logger.info(
f"Updated tarot.json, version: {cur_version} -> {version}")
else:
response = None

if response is None:
if not tarot_json_path.exists():
logger.warning("Tarot text resource missing! Please check!")
raise ResourceError("Missing necessary resource: tarot.json!")
else:
try:
version: float = response.get("version", 0)
except KeyError:
logger.warning(
"Tarot text resource downloaded incompletely! Please check!")
raise DownloadError

# Update when there is a newer version
if version > cur_version:
with tarot_json_path.open("w", encoding="utf-8") as f:
json.dump(response, f, ensure_ascii=False, indent=4)
logger.info(
f"Updated tarot.json, version: {cur_version} -> {version}")


@cached(ttl=180)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot_plugin_tarot"
version = "0.4.0.post2"
version = "0.4.0.post3"
description = "Tarot divination!"
authors = ["KafCoppelia <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 92e99bf

Please sign in to comment.