Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
0.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Aug 7, 2023
1 parent fe207c8 commit 70ec383
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ plugins = [

## ⚙️ 配置

在 nonebot2 项目的`.env`文件中添加下表中的配置
在 nonebot2 项目的 `.env` 文件中添加下表中的配置

| 配置项 | 必填 | 默认值 | 说明 |
| :---------------------------: | :--: | :-----: | :-------------------------------------------------------: |
Expand All @@ -116,7 +116,7 @@ plugins = [
| `BA_ARONA_API_URL` || ... | Arona Bot 数据源的地址 |
| `BA_ARONA_CDN_URL` || ... | Arona Bot 图片 CDN 地址 |
| `BA_CLEAR_REQ_CACHE_INTERVAL` || `3` | 插件清理请求缓存的间隔,单位小时 |
| `BA_AUTO_CLEAR_ARONA_CACHE` || ... | 是否在插件每次加载时自动清理从 Arona Bot 数据源缓存的图片 |
| `BA_AUTO_CLEAR_ARONA_CACHE` || `False` | 是否在插件每次加载时自动清理从 Arona Bot 数据源缓存的图片 |

由于 CDN 可能并不给力,如果有条件的话本人推荐使用代理直接访问原地址,下面是对应 `.env` 配置:

Expand Down Expand Up @@ -178,6 +178,7 @@ Telegram:[@lgc2333](https://t.me/lgc2333)
### 0.8.5

- 修复 [#41](https://github.com/lgc-NB2Dev/nonebot-plugin-bawiki/issues/41)
- 配置项 `BA_AUTO_CLEAR_ARONA_CACHE` 默认值改为 `False`

### 0.8.4

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_bawiki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .config import Cfg as Cfg # noqa: E402
from .help import extra, register_help_cmd, usage # noqa: E402

__version__ = "0.8.4"
__version__ = "0.8.5"
__plugin_meta__ = PluginMetadata(
name="BAWiki",
description="碧蓝档案Wiki插件",
Expand Down
27 changes: 20 additions & 7 deletions nonebot_plugin_bawiki/command/clear_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import shutil
from pathlib import Path
from typing import TYPE_CHECKING

from nonebot import on_command
Expand Down Expand Up @@ -29,14 +29,27 @@
]


def clear_cache_dir() -> int:
counter = 0

def run(path: Path):
nonlocal counter
for p in path.iterdir():
if p.is_dir():
run(p)
else:
p.unlink()
counter += 1

run(CACHE_PATH)
return counter


cmd_clear_cache = on_command("ba清空缓存", aliases={"ba清除缓存"}, permission=SUPERUSER)


@cmd_clear_cache.handle()
async def _(matcher: Matcher):
clear_req_cache()

for path in CACHE_PATH.iterdir():
path.unlink() if path.is_file() else shutil.rmtree(path)

await matcher.finish("缓存已清空~")
req_count = clear_req_cache()
cache_count = clear_cache_dir()
await matcher.finish(f"已清除 {req_count} 项请求缓存与 {cache_count} 项文件缓存~")
2 changes: 1 addition & 1 deletion nonebot_plugin_bawiki/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Cfg(BaseModel):
ba_arona_cdn_url: str = "https://arona.cdn.diyigemt.com/"

ba_clear_req_cache_interval: int = 3
ba_auto_clear_arona_cache: bool = True
ba_auto_clear_arona_cache: bool = False

@validator(
"ba_gamekee_url",
Expand Down
3 changes: 2 additions & 1 deletion nonebot_plugin_bawiki/data/arona.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
from ..util import async_req

ARONA_CACHE_PATH = CACHE_PATH / "arona"
if ARONA_CACHE_PATH.exists() and config.ba_auto_clear_arona_cache:
if config.ba_auto_clear_arona_cache and ARONA_CACHE_PATH.exists():
shutil.rmtree(ARONA_CACHE_PATH)
if not ARONA_CACHE_PATH.exists():
ARONA_CACHE_PATH.mkdir(parents=True)


IMAGE_TYPE_MAP = {
1: "学生攻略",
2: "主线地图",
Expand Down
4 changes: 3 additions & 1 deletion nonebot_plugin_bawiki/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def get_req_cache(
return None


def clear_req_cache():
def clear_req_cache() -> int:
count = len(req_cache)
req_cache.clear()
return count


if config.ba_clear_req_cache_interval > 0:
Expand Down

0 comments on commit 70ec383

Please sign in to comment.