mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-15 11:54:40 +08:00
🌟修复转换缓存功能的另一个问题
This commit is contained in:
parent
40607ed16b
commit
6347100cf5
@ -3,7 +3,7 @@ aiofiles>=23.2.1
|
|||||||
colored>=2.2.4
|
colored>=2.2.4
|
||||||
GitPython>=3.1.43
|
GitPython>=3.1.43
|
||||||
httpx>=0.27.0
|
httpx>=0.27.0
|
||||||
nonebot-plugin-htmlrender>=0.3.1
|
nonebot-plugin-htmlrender~=0.3.1
|
||||||
nonebot2[fastapi,httpx,websockets]>=2.3.3
|
nonebot2[fastapi,httpx,websockets]>=2.3.3
|
||||||
nonebot-adapter-onebot>=2.4.3
|
nonebot-adapter-onebot>=2.4.3
|
||||||
arclet_alconna==1.8.15
|
arclet_alconna==1.8.15
|
||||||
|
@ -189,7 +189,7 @@ def query_convert_points(
|
|||||||
return False, people_convert_point[usr_id][item]
|
return False, people_convert_point[usr_id][item]
|
||||||
|
|
||||||
|
|
||||||
something_to_delete: dict[
|
something_temporary: dict[
|
||||||
str,
|
str,
|
||||||
dict[
|
dict[
|
||||||
Literal["stuff", "time"],
|
Literal["stuff", "time"],
|
||||||
@ -199,21 +199,80 @@ something_to_delete: dict[
|
|||||||
|
|
||||||
|
|
||||||
def add_file_to_delete(file_: Path | os.PathLike[str] | str, wait_p30s: int = 0) -> str:
|
def add_file_to_delete(file_: Path | os.PathLike[str] | str, wait_p30s: int = 0) -> str:
|
||||||
global something_to_delete
|
"""
|
||||||
something_to_delete[rr := str(file_)] = {"stuff": file_, "time": wait_p30s}
|
增加一个地址,过会儿删除这个地址指向的文件
|
||||||
|
|
||||||
|
参数:
|
||||||
|
file_: Path | os.PathLike[str] | str
|
||||||
|
文件路径
|
||||||
|
wait_p30s: int
|
||||||
|
等待时间,单位为 30 秒内(不大于 30 秒),默认为 `0`
|
||||||
|
|
||||||
|
返回:
|
||||||
|
str
|
||||||
|
文件路径的字符串
|
||||||
|
"""
|
||||||
|
global something_temporary
|
||||||
|
something_temporary[rr := str(file_)] = {"stuff": file_, "time": wait_p30s}
|
||||||
return rr
|
return rr
|
||||||
|
|
||||||
|
|
||||||
def add_memory_to_delete(
|
def add_memory_to_temporary(
|
||||||
index: str, memory_: Any, description: str = "一个内存", wait_p30s: int = 0
|
index: str, memory_: Any, description: str = "一个内存", wait_p30s: int = 0
|
||||||
) -> None:
|
) -> None:
|
||||||
global something_to_delete
|
"""
|
||||||
something_to_delete[index] = {"stuff": (memory_, description), "time": wait_p30s}
|
向临时内存存储中填入内存信息
|
||||||
|
|
||||||
|
参数:
|
||||||
|
index: str
|
||||||
|
索引
|
||||||
|
memory_: Any
|
||||||
|
内存
|
||||||
|
description: str
|
||||||
|
内存描述
|
||||||
|
wait_p30s: int
|
||||||
|
等待时间,单位为 30 秒内(不大于 30 秒),默认为 `0`
|
||||||
|
"""
|
||||||
|
global something_temporary
|
||||||
|
something_temporary[index] = {"stuff": (memory_, description), "time": wait_p30s}
|
||||||
|
|
||||||
|
def read_memory_from_temporary(index: str) -> Any:
|
||||||
|
"""
|
||||||
|
从临时内存存储中读取内容
|
||||||
|
|
||||||
|
参数:
|
||||||
|
index: str
|
||||||
|
索引
|
||||||
|
|
||||||
|
返回:
|
||||||
|
Any
|
||||||
|
内容,当无此内容时返回 `None`
|
||||||
|
"""
|
||||||
|
global something_temporary
|
||||||
|
memory_cmp = something_temporary.get(index, {"stuff": None})["stuff"]
|
||||||
|
if isinstance(memory_cmp, tuple):
|
||||||
|
return memory_cmp[0]
|
||||||
|
else:
|
||||||
|
return memory_cmp
|
||||||
|
|
||||||
def get_stored_path(
|
def get_stored_path(
|
||||||
user_id: str, item: Union[Path, os.PathLike[str], str], superuser: bool = False
|
user_id: str, item: Union[Path, os.PathLike[str], str], superuser: bool = False
|
||||||
) -> Path:
|
) -> Path:
|
||||||
|
"""
|
||||||
|
获取用户文件存储路径
|
||||||
|
|
||||||
|
参数:
|
||||||
|
user_id: str
|
||||||
|
用户id
|
||||||
|
item: Union[Path, os.PathLike[str], str]
|
||||||
|
文件名(对于用户目录的相对路径)
|
||||||
|
superuser: bool
|
||||||
|
是否为超级用户,默认为 `False` 若为 `True` 则在用户文件中寻找
|
||||||
|
|
||||||
|
返回:
|
||||||
|
Path
|
||||||
|
文件路径
|
||||||
|
"""
|
||||||
|
|
||||||
if not isinstance(item, Path):
|
if not isinstance(item, Path):
|
||||||
item_ = Path(item).name
|
item_ = Path(item).name
|
||||||
@ -260,8 +319,8 @@ async def _():
|
|||||||
nonebot.logger.info(
|
nonebot.logger.info(
|
||||||
"-删除临时内容-",
|
"-删除临时内容-",
|
||||||
)
|
)
|
||||||
global something_to_delete
|
global something_temporary
|
||||||
for index_, stuff_component in something_to_delete.items():
|
for index_, stuff_component in something_temporary.items():
|
||||||
if stuff_component["time"] <= 0: # type: ignore
|
if stuff_component["time"] <= 0: # type: ignore
|
||||||
if isinstance(stuff_component["stuff"], (str, Path, os.PathLike)):
|
if isinstance(stuff_component["stuff"], (str, Path, os.PathLike)):
|
||||||
try:
|
try:
|
||||||
@ -279,7 +338,7 @@ async def _():
|
|||||||
nonebot.logger.warning(
|
nonebot.logger.warning(
|
||||||
"路径不存在或未知类型:{}".format(stuff_component["stuff"])
|
"路径不存在或未知类型:{}".format(stuff_component["stuff"])
|
||||||
)
|
)
|
||||||
del something_to_delete[index_]
|
del something_temporary[index_]
|
||||||
except:
|
except:
|
||||||
nonebot.logger.warning(
|
nonebot.logger.warning(
|
||||||
"跳过删除:{}".format(stuff_component["stuff"])
|
"跳过删除:{}".format(stuff_component["stuff"])
|
||||||
@ -289,12 +348,13 @@ async def _():
|
|||||||
nonebot.logger.info(
|
nonebot.logger.info(
|
||||||
"清理内存:{}".format(stuff_component["stuff"][-1]) # type: ignore
|
"清理内存:{}".format(stuff_component["stuff"][-1]) # type: ignore
|
||||||
)
|
)
|
||||||
del something_to_delete[index_]
|
del something_temporary[index_]
|
||||||
except:
|
except:
|
||||||
nonebot.logger.warning(
|
nonebot.logger.warning(
|
||||||
"无法删除:{}".format(stuff_component["stuff"][-1]) # type: ignore
|
"无法删除:{}".format(stuff_component["stuff"][-1]) # type: ignore
|
||||||
)
|
)
|
||||||
something_to_delete[index]["time"] -= 1 # type: ignore
|
else:
|
||||||
|
something_temporary[index_]["time"] -= 1 # type: ignore
|
||||||
global filesaves
|
global filesaves
|
||||||
qqidlist = list(filesaves.keys()).copy()
|
qqidlist = list(filesaves.keys()).copy()
|
||||||
save_file = False
|
save_file = False
|
||||||
@ -340,10 +400,10 @@ async def _():
|
|||||||
filesaves.pop(qqid)
|
filesaves.pop(qqid)
|
||||||
save_file = True
|
save_file = True
|
||||||
if save_file:
|
if save_file:
|
||||||
nonebot.logger.success("-已删除过期文件-")
|
nonebot.logger.success("-已删除过期内容-")
|
||||||
save_filesaves()
|
save_filesaves()
|
||||||
else:
|
else:
|
||||||
nonebot.logger.success("-无过期文件需要删除-")
|
nonebot.logger.success("-无过期内容需要删除-")
|
||||||
|
|
||||||
|
|
||||||
# @nonebot.rule.Rule
|
# @nonebot.rule.Rule
|
||||||
@ -867,19 +927,15 @@ async def _(
|
|||||||
not _args["enable-mismatch-error"],
|
not _args["enable-mismatch-error"],
|
||||||
_args["play-speed"],
|
_args["play-speed"],
|
||||||
_args["default-tempo"],
|
_args["default-tempo"],
|
||||||
pitched_notechart,
|
str(pitched_notechart),
|
||||||
percussion_notechart,
|
str(percussion_notechart),
|
||||||
volume_curve,
|
volume_curve,
|
||||||
).__hash__()
|
).__hash__()
|
||||||
)
|
)
|
||||||
|
|
||||||
if identify_cmp in something_to_delete.keys():
|
if identify_cmp in something_temporary.keys():
|
||||||
nonebot.logger.info("载入已有缓存。")
|
nonebot.logger.info("载入已有缓存。")
|
||||||
msct_obj: Musicreater.MidiConvert = something_to_delete[
|
msct_obj: Musicreater.MidiConvert = read_memory_from_temporary(identify_cmp)
|
||||||
identify_cmp
|
|
||||||
][
|
|
||||||
"stuff"
|
|
||||||
] # type: ignore
|
|
||||||
msct_obj.redefine_execute_format(_args["old-execute-format"])
|
msct_obj.redefine_execute_format(_args["old-execute-format"])
|
||||||
msct_obj.set_min_volume(_args["minimal-volume"])
|
msct_obj.set_min_volume(_args["minimal-volume"])
|
||||||
# msct_obj.set_deviation()
|
# msct_obj.set_deviation()
|
||||||
@ -896,7 +952,7 @@ async def _(
|
|||||||
min_volume=_args["minimal-volume"],
|
min_volume=_args["minimal-volume"],
|
||||||
vol_processing_func=volume_curve,
|
vol_processing_func=volume_curve,
|
||||||
)
|
)
|
||||||
add_memory_to_delete(
|
add_memory_to_temporary(
|
||||||
identify_cmp,
|
identify_cmp,
|
||||||
msct_obj,
|
msct_obj,
|
||||||
"音乐转换类{}".format(msct_obj.music_name),
|
"音乐转换类{}".format(msct_obj.music_name),
|
||||||
|
@ -44,13 +44,14 @@ from src.utils.message.message import MarkdownMessage
|
|||||||
from src.utils.message.html_tool import md_to_pic
|
from src.utils.message.html_tool import md_to_pic
|
||||||
|
|
||||||
from .msctexec import (
|
from .msctexec import (
|
||||||
something_to_delete,
|
something_temporary,
|
||||||
query_convert_points,
|
query_convert_points,
|
||||||
filesaves,
|
filesaves,
|
||||||
configdict,
|
configdict,
|
||||||
temporary_dir,
|
temporary_dir,
|
||||||
add_file_to_delete,
|
add_file_to_delete,
|
||||||
add_memory_to_delete,
|
add_memory_to_temporary,
|
||||||
|
read_memory_from_temporary,
|
||||||
get_stored_path,
|
get_stored_path,
|
||||||
)
|
)
|
||||||
from .utils import hanzi_timeid
|
from .utils import hanzi_timeid
|
||||||
@ -304,19 +305,17 @@ async def _(
|
|||||||
not _args["enable-mismatch-error"],
|
not _args["enable-mismatch-error"],
|
||||||
_args["play-speed"],
|
_args["play-speed"],
|
||||||
_args["default-tempo"],
|
_args["default-tempo"],
|
||||||
pitched_notechart,
|
str(pitched_notechart),
|
||||||
percussion_notechart,
|
str(percussion_notechart),
|
||||||
volume_curve,
|
volume_curve,
|
||||||
).__hash__()
|
).__hash__()
|
||||||
)
|
)
|
||||||
|
|
||||||
if identify_cmp in something_to_delete.keys():
|
if identify_cmp in something_temporary.keys():
|
||||||
nonebot.logger.info("载入已有缓存。")
|
nonebot.logger.info("载入已有缓存。")
|
||||||
msct_obj: Musicreater.MidiConvert = something_to_delete[
|
msct_obj: Musicreater.MidiConvert = read_memory_from_temporary(
|
||||||
identify_cmp
|
identify_cmp
|
||||||
][
|
)
|
||||||
"stuff"
|
|
||||||
] # type: ignore
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if go_chk_point():
|
if go_chk_point():
|
||||||
@ -329,7 +328,7 @@ async def _(
|
|||||||
percussion_note_table=percussion_notechart,
|
percussion_note_table=percussion_notechart,
|
||||||
vol_processing_func=volume_curve,
|
vol_processing_func=volume_curve,
|
||||||
)
|
)
|
||||||
add_memory_to_delete(
|
add_memory_to_temporary(
|
||||||
identify_cmp,
|
identify_cmp,
|
||||||
msct_obj,
|
msct_obj,
|
||||||
"音乐转换类{}".format(msct_obj.music_name),
|
"音乐转换类{}".format(msct_obj.music_name),
|
||||||
|
Loading…
Reference in New Issue
Block a user