mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2025-04-12 23:29:37 +08:00
✨ 更新米游社截图
域名,优化部分代码
This commit is contained in:
parent
75ea097074
commit
d0b6be8946
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
custom: ["https://afdian.net/@cherishmoon"]
|
@ -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_name': '米游社帖子截图',
|
||||||
'pm_description': '(被动技能)自动对消息中的米游社帖子链接内容进行截图发送',
|
'pm_description': '(被动技能)自动对消息中的米游社帖子链接内容进行截图发送',
|
||||||
'pm_usage': '米游社帖子截图',
|
'pm_usage': '米游社帖子截图',
|
||||||
|
@ -4,14 +4,16 @@ from nonebot import get_driver
|
|||||||
from .logger import logger
|
from .logger import logger
|
||||||
from .scheduler import scheduler
|
from .scheduler import scheduler
|
||||||
|
|
||||||
__version__ = '3.0.0'
|
__version__ = '3.0.1'
|
||||||
|
|
||||||
DRIVER = get_driver()
|
DRIVER = get_driver()
|
||||||
try:
|
try:
|
||||||
SUPERUSERS: List[int] = [int(s) for s in DRIVER.config.superusers]
|
SUPERUSERS: List[int] = [int(s) for s in DRIVER.config.superusers]
|
||||||
except Exception:
|
except Exception:
|
||||||
SUPERUSERS = []
|
SUPERUSERS = []
|
||||||
logger.warning('请在.env.prod文件中中配置超级用户SUPERUSERS')
|
|
||||||
|
if not SUPERUSERS or SUPERUSERS == ['123456']:
|
||||||
|
logger.warning('请在.env.prod文件中配置超级用户SUPERUSERS')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NICKNAME: str = list(DRIVER.config.nickname)[0]
|
NICKNAME: str = list(DRIVER.config.nickname)[0]
|
||||||
|
@ -2,7 +2,6 @@ try:
|
|||||||
import ujson as json
|
import ujson as json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
import hashlib
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ssl import SSLCertVerificationError
|
from ssl import SSLCertVerificationError
|
||||||
from typing import Union, Optional, Tuple, Dict
|
from typing import Union, Optional, Tuple, Dict
|
||||||
@ -12,17 +11,12 @@ import tqdm.asyncio
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from ruamel import yaml
|
from ruamel import yaml
|
||||||
|
|
||||||
from .path import RESOURCE_BASE_PATH
|
|
||||||
from .requests import aiorequests
|
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] = {}
|
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(
|
async def load_image(
|
||||||
@ -33,9 +27,7 @@ async def load_image(
|
|||||||
mode: Optional[str] = None,
|
mode: Optional[str] = None,
|
||||||
) -> Image.Image:
|
) -> Image.Image:
|
||||||
"""
|
"""
|
||||||
说明:
|
读取图像,并预处理
|
||||||
读取图像,并预处理
|
|
||||||
参数:
|
|
||||||
:param path: 图片路径
|
:param path: 图片路径
|
||||||
:param size: 预处理尺寸
|
:param size: 预处理尺寸
|
||||||
:param crop: 预处理裁剪大小
|
:param crop: 预处理裁剪大小
|
||||||
@ -68,21 +60,19 @@ async def load_image(
|
|||||||
|
|
||||||
def load_json(path: Union[Path, str], encoding: str = 'utf-8'):
|
def load_json(path: Union[Path, str], encoding: str = 'utf-8'):
|
||||||
"""
|
"""
|
||||||
说明:
|
读取本地json文件,返回文件数据。
|
||||||
读取本地json文件,返回文件数据。
|
|
||||||
参数:
|
|
||||||
:param path: 文件路径
|
:param path: 文件路径
|
||||||
:param encoding: 编码,默认为utf-8
|
:param encoding: 编码,默认为utf-8
|
||||||
:return: 数据
|
:return: 数据
|
||||||
"""
|
"""
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
path = Path(path)
|
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:
|
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 url: url
|
||||||
:param path: 本地json文件路径
|
:param path: 本地json文件路径
|
||||||
:param force_refresh: 是否强制重新下载
|
: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'):
|
def save_json(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'):
|
||||||
"""
|
"""
|
||||||
保存json文件
|
保存json文件
|
||||||
:param data: json数据
|
:param data: json数据
|
||||||
:param path: 保存路径
|
:param path: 保存路径
|
||||||
:param encoding: 编码
|
:param encoding: 编码
|
||||||
"""
|
"""
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
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'):
|
def load_yaml(path: Union[Path, str], encoding: str = 'utf-8'):
|
||||||
"""
|
"""
|
||||||
说明:
|
读取本地yaml文件,返回字典。
|
||||||
读取本地yaml文件,返回字典。
|
|
||||||
参数:
|
|
||||||
:param path: 文件路径
|
:param path: 文件路径
|
||||||
:param encoding: 编码,默认为utf-8
|
:param encoding: 编码,默认为utf-8
|
||||||
:return: 字典
|
:return: 字典
|
||||||
"""
|
"""
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
return yaml.load(path.open('r', encoding=encoding),
|
return yaml.load(path.read_text(encoding=encoding),
|
||||||
Loader=yaml.Loader) if path.exists() else yaml.round_trip_load('{}')
|
Loader=yaml.Loader) if path.exists() else {}
|
||||||
|
|
||||||
|
|
||||||
def save_yaml(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'):
|
def save_yaml(data: dict, path: Union[Path, str] = None, encoding: str = 'utf-8'):
|
||||||
"""
|
"""
|
||||||
保存yaml文件
|
保存yaml文件
|
||||||
:param data: 数据
|
:param data: 数据
|
||||||
:param path: 保存路径
|
:param path: 保存路径
|
||||||
:param encoding: 编码
|
:param encoding: 编码
|
||||||
"""
|
"""
|
||||||
if isinstance(path, str):
|
if isinstance(path, str):
|
||||||
path = Path(path)
|
path = Path(path)
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
yaml.dump(
|
with path.open('w', encoding=encoding) as f:
|
||||||
data,
|
yaml.dump(
|
||||||
path.open('w', encoding=encoding),
|
data,
|
||||||
indent=2,
|
f,
|
||||||
Dumper=yaml.RoundTripDumper,
|
indent=2,
|
||||||
allow_unicode=True)
|
Dumper=yaml.RoundTripDumper,
|
||||||
|
allow_unicode=True)
|
||||||
|
|
||||||
|
|
||||||
async def download(url: str, save_path: Union[Path, str]):
|
async def download(url: str, save_path: Union[Path, str]):
|
||||||
"""
|
"""
|
||||||
下载文件(带进度条)
|
下载文件(带进度条)
|
||||||
:param url: url
|
:param url: url
|
||||||
:param save_path: 保存路径
|
:param save_path: 保存路径
|
||||||
"""
|
"""
|
||||||
if isinstance(save_path, str):
|
if isinstance(save_path, str):
|
||||||
save_path = Path(save_path)
|
save_path = Path(save_path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user