更新米游社截图域名,优化部分代码

This commit is contained in:
CMHopeSunshine 2023-01-04 00:11:51 +08:00
parent 75ea097074
commit d0b6be8946
4 changed files with 32 additions and 39 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
custom: ["https://afdian.net/@cherishmoon"]

View File

@ -17,7 +17,7 @@ __plugin_meta__ = PluginMetadata(
}
)
post_screenshot = on_regex(r'(https://)?(m\.)?bbs.mihoyo.com/.+/article/\d+', priority=20, block=False, state={
post_screenshot = on_regex(r'(https://)?((m\.)?bbs.mihoyo|www.miyoushe).com/.+/article/\d+', priority=20, block=False, state={
'pm_name': '米游社帖子截图',
'pm_description': '(被动技能)自动对消息中的米游社帖子链接内容进行截图发送',
'pm_usage': '米游社帖子截图',

View File

@ -4,14 +4,16 @@ from nonebot import get_driver
from .logger import logger
from .scheduler import scheduler
__version__ = '3.0.0'
__version__ = '3.0.1'
DRIVER = get_driver()
try:
SUPERUSERS: List[int] = [int(s) for s in DRIVER.config.superusers]
except Exception:
SUPERUSERS = []
logger.warning('请在.env.prod文件中中配置超级用户SUPERUSERS')
if not SUPERUSERS or SUPERUSERS == ['123456']:
logger.warning('请在.env.prod文件中配置超级用户SUPERUSERS')
try:
NICKNAME: str = list(DRIVER.config.nickname)[0]

View File

@ -2,7 +2,6 @@ try:
import ujson as json
except ImportError:
import json
import hashlib
from pathlib import Path
from ssl import SSLCertVerificationError
from typing import Union, Optional, Tuple, Dict
@ -12,17 +11,12 @@ import tqdm.asyncio
from PIL import Image
from ruamel import yaml
from .path import RESOURCE_BASE_PATH
from .requests import aiorequests
# 删除从安柏计划下载的问号图标
if (temp_path := RESOURCE_BASE_PATH / 'avatar' / 'UI_AvatarIcon_Wanderer.png').exists() and hashlib.md5(temp_path.read_bytes()).hexdigest() == 'a8827dfecb36640e59b319d1dd6190f4':
temp_path.unlink()
if (temp_path := RESOURCE_BASE_PATH / 'avatar' / 'UI_AvatarIcon_Faruzan.png').exists() and hashlib.md5(temp_path.read_bytes()).hexdigest() == 'a8827dfecb36640e59b319d1dd6190f4':
temp_path.unlink()
cache_image: Dict[str, any] = {}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'}
async def load_image(
@ -33,9 +27,7 @@ async def load_image(
mode: Optional[str] = None,
) -> Image.Image:
"""
说明
读取图像并预处理
参数
读取图像并预处理
:param path: 图片路径
:param size: 预处理尺寸
:param crop: 预处理裁剪大小
@ -68,21 +60,19 @@ async def load_image(
def load_json(path: Union[Path, str], encoding: str = 'utf-8'):
"""
说明
读取本地json文件返回文件数据
参数
读取本地json文件返回文件数据
:param path: 文件路径
:param encoding: 编码默认为utf-8
:return: 数据
"""
if isinstance(path, str):
path = Path(path)
return json.load(path.open('r', encoding=encoding)) if path.exists() else {}
return json.loads(path.read_text(encoding=encoding)) if path.exists() else {}
async def load_json_from_url(url: str, path: Union[Path, str] = None, force_refresh: bool = False) -> dict:
"""
从网络url中读取json当有path参数时如果path文件不存在就会从url下载保存到path如果path文件存在则直接读取path
从网络url中读取json当有path参数时如果path文件不存在就会从url下载保存到path如果path文件存在则直接读取path
:param url: url
:param path: 本地json文件路径
:param force_refresh: 是否强制重新下载
@ -103,54 +93,54 @@ async def load_json_from_url(url: str, path: Union[Path, str] = None, force_refr
def save_json(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'):
"""
保存json文件
:param data: json数据
:param path: 保存路径
:param encoding: 编码
:param data: json数据
:param path: 保存路径
:param encoding: 编码
"""
if isinstance(path, str):
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
json.dump(data, path.open('w', encoding=encoding), ensure_ascii=False, indent=4)
with path.open('w', encoding=encoding) as f:
json.dump(data, f, ensure_ascii=False, indent=2)
def load_yaml(path: Union[Path, str], encoding: str = 'utf-8'):
"""
说明
读取本地yaml文件返回字典
参数
读取本地yaml文件返回字典
:param path: 文件路径
:param encoding: 编码默认为utf-8
:return: 字典
"""
if isinstance(path, str):
path = Path(path)
return yaml.load(path.open('r', encoding=encoding),
Loader=yaml.Loader) if path.exists() else yaml.round_trip_load('{}')
return yaml.load(path.read_text(encoding=encoding),
Loader=yaml.Loader) if path.exists() else {}
def save_yaml(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'):
"""
保存yaml文件
:param data: 数据
:param path: 保存路径
:param encoding: 编码
:param data: 数据
:param path: 保存路径
:param encoding: 编码
"""
if isinstance(path, str):
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
yaml.dump(
data,
path.open('w', encoding=encoding),
indent=2,
Dumper=yaml.RoundTripDumper,
allow_unicode=True)
with path.open('w', encoding=encoding) as f:
yaml.dump(
data,
f,
indent=2,
Dumper=yaml.RoundTripDumper,
allow_unicode=True)
async def download(url: str, save_path: Union[Path, str]):
"""
下载文件(带进度条)
:param url: url
:param save_path: 保存路径
:param url: url
:param save_path: 保存路径
"""
if isinstance(save_path, str):
save_path = Path(save_path)