Skip to content

Commit

Permalink
取消文件下载
Browse files Browse the repository at this point in the history
  • Loading branch information
CM-Edelweiss committed Oct 17, 2024
1 parent 594d1ee commit c88ff09
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 76 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
| 配置项 | 必填 | 默认值 | 说明 |
|:-----:|:----:|:----:|:----:|
| img_cache || True | 图片资源缓存开关 |
| github_proxy || https://gitdl.cn/ | 资源下载代理 |
| pm_version || 11.45.14 | 版本号 |
| pm_text|| 自定义文本 | 自定义文本 |

Expand Down
17 changes: 7 additions & 10 deletions nonebot_plugin_pmhelp/Path.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import nonebot_plugin_localstore as store
from pathlib import Path
from nonebot import require
#先导入(注意格式化移动)
# 先导入(注意格式化移动)
require("nonebot_plugin_localstore")
import nonebot_plugin_localstore as store


# 资源路径
RESOURCE_BASE_PATH = store.get_plugin_cache_file("pmhelp_data")
RESOURCE_BASE_PATH.mkdir(parents=True, exist_ok=True)

RESOURCE_BASE_PATH = Path(__file__).parent / "pmhelp_data"
# 图片路径
IMAGE_PATH = RESOURCE_BASE_PATH / 'general'
IMAGE_PATH.mkdir(parents=True, exist_ok=True)
# 字体路径
FONTS_PATH = RESOURCE_BASE_PATH / 'fonts'


# 数据库路径
DATABASE_PATH = RESOURCE_BASE_PATH / 'database'
DATABASE_PATH = store.get_plugin_cache_file("pmhelp_data") / 'database'
DATABASE_PATH.mkdir(parents=True, exist_ok=True)
MANAGER_DB_PATH = DATABASE_PATH / 'manager.db'

# 字体路径
FONTS_PATH = RESOURCE_BASE_PATH / 'fonts'
FONTS_PATH.mkdir(parents=True, exist_ok=True)

# 插件管理器文件存放目录
# 用户修改
Expand Down
3 changes: 0 additions & 3 deletions nonebot_plugin_pmhelp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from nonebot import on_regex, on_command
from nonebot.adapters.onebot.v11 import (
GroupMessageEvent,
Expand All @@ -14,7 +13,6 @@
DRIVER,
CommandObjectID,
fullmatch_rule,
check_resource,
)
from .plugin.manage import PluginManager
from .models import PluginDisable
Expand Down Expand Up @@ -42,7 +40,6 @@
@DRIVER.on_startup
async def startup():
await PluginManager.init()
asyncio.ensure_future(check_resource())


manage_cmd = on_regex(
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_pmhelp/draw_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def draw_help(plugin_list: List[PluginInfo]):
color=(255, 255, 255, 0), mode='RGBA')
orange_line = await load_image(IMAGE_PATH / 'orange.png')
orange_name_bg = await load_image(IMAGE_PATH / 'orange_card.png')
black_line = await load_image(IMAGE_PATH / 'black2.png')
black_line = await load_image(IMAGE_PATH / 'black.png')
black_name_bg = await load_image(IMAGE_PATH / 'black_card2.png')
orange_bord = await load_image(IMAGE_PATH / 'orange_bord.png')
black_bord = await load_image(IMAGE_PATH / 'black_bord.png')
Expand Down
2 changes: 0 additions & 2 deletions nonebot_plugin_pmhelp/pm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
class Config(BaseModel):
# 图片资源缓存开关
img_cache: bool = True
# 资源下载代理
github_proxy: str = 'https://gitdl.cn/'
# 版本
pm_version: str = "11.45.14"
# 自定义文本
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added nonebot_plugin_pmhelp/pmhelp_data/general/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nonebot_plugin_pmhelp/pmhelp_data/general/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nonebot_plugin_pmhelp/pmhelp_data/general/orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 0 additions & 58 deletions nonebot_plugin_pmhelp/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from io import BytesIO
import httpx
import tqdm.asyncio
from ruamel.yaml import YAML
from ssl import SSLCertVerificationError
from pathlib import Path
Expand All @@ -11,10 +10,6 @@
from nonebot import get_driver
from nonebot.adapters.onebot.v11 import Message

from .logger import logger
from .Path import IMAGE_PATH, FONTS_PATH
from .pm_config import Pm_config

DRIVER = get_driver()
try:
SUPERUSERS: List[int] = [int(s) for s in DRIVER.config.superusers]
Expand Down Expand Up @@ -150,56 +145,3 @@ async def get_img(url: str,
save_path.parent.mkdir(parents=True, exist_ok=True)
img.save(save_path)
return img


async def download(url: str, save_path: Path, exclude_json: bool = False):
"""
下载文件(带进度条)
:param url: url
:param save_path: 保存路径
:param exclude_json: 是否排除json文件
"""
save_path.parent.mkdir(parents=True, exist_ok=True)
async with httpx.AsyncClient().stream(method='GET', url=url, follow_redirects=True) as datas:
if exclude_json and 'application/json' in str(datas.headers['Content-Type']):
raise Exception('file not match type')
size = int(datas.headers['Content-Length'])
f = save_path.open('wb')
async for chunk in tqdm.asyncio.tqdm(iterable=datas.aiter_bytes(1),
desc=url.split('/')[-1],
unit='iB',
unit_scale=True,
unit_divisor=1024,
total=size,
colour='green'):
f.write(chunk)
f.close()


fonts = ["bahnschrift_regular.ttf",
"SourceHanSansCN-Bold.otf", "SourceHanSerifCN-Bold.otf"]
generals = ["bg.png", "black_bord.png", "black_card2.png",
"black2.png", "orange_bord.png", "orange_card.png", "orange.png"]


async def check_resource():
for font in fonts:
if (FONTS_PATH / font).exists() and (FONTS_PATH / font).is_file():
pass
else:
try:
await download(url=f'{Pm_config.github_proxy}https://raw.githubusercontent.com/CM-Edelweiss/help_resources/refs/heads/main/fonts/{font}', save_path=FONTS_PATH / font)
except Exception as e:
logger.warning(
'资源检查', f'下载<m>{font}</m>时<r>出错</r>,请尝试更换<m>github资源地址</m>{e}')

for general in generals:
if (IMAGE_PATH / general).exists() and (IMAGE_PATH / general).is_file():
pass
else:
try:
await download(url=f'{Pm_config.github_proxy}https://raw.githubusercontent.com/CM-Edelweiss/help_resources/refs/heads/main/general/{general}', save_path=IMAGE_PATH / general)
except Exception as e:
logger.warning(
'资源检查', f'下载<m>{general}</m>时<r>出错</r>,请尝试更换<m>github资源地址</m>{e}')
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-pmhelp"
version = "1.1.3"
version = "1.1.4"
description = "提取于LittlePaimon的帮助插件"
authors = ["CM-Edelweiss <2633668472@qq.com>"]
readme = "README.md"
Expand Down

0 comments on commit c88ff09

Please sign in to comment.