mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-11 01:27:29 +08:00
😎减少文件删除难度
This commit is contained in:
parent
59a3c92ff3
commit
907740172b
@ -204,11 +204,23 @@ async def _():
|
|||||||
nonebot.logger.success("删除临时文件目录完成")
|
nonebot.logger.success("删除临时文件目录完成")
|
||||||
|
|
||||||
|
|
||||||
|
file_to_delete = []
|
||||||
|
|
||||||
@scheduler.scheduled_job("interval", seconds=30)
|
@scheduler.scheduled_job("interval", seconds=30)
|
||||||
async def _():
|
async def _():
|
||||||
nonebot.logger.info(
|
nonebot.logger.info(
|
||||||
"-删除文件检测-",
|
"-删除文件检测-",
|
||||||
)
|
)
|
||||||
|
global file_to_delete
|
||||||
|
for path_d in file_to_delete.copy():
|
||||||
|
try:
|
||||||
|
if os.path.exists(path_d):
|
||||||
|
os.remove(path_d)
|
||||||
|
file_to_delete.remove(path_d)
|
||||||
|
nonebot.logger.success("删除临时文件:{}".format(path_d))
|
||||||
|
except:
|
||||||
|
nonebot.logger.warning("跳过临时文件删除:{}".format(path_d))
|
||||||
|
global filesaves
|
||||||
qqidlist = list(filesaves.keys()).copy()
|
qqidlist = list(filesaves.keys()).copy()
|
||||||
save_file = False
|
save_file = False
|
||||||
for qqid in qqidlist:
|
for qqid in qqidlist:
|
||||||
@ -577,7 +589,7 @@ async def _(
|
|||||||
if (qres := query_convert_points(usr_id, "music"))[0] is False:
|
if (qres := query_convert_points(usr_id, "music"))[0] is False:
|
||||||
await linglun_convert.finish(
|
await linglun_convert.finish(
|
||||||
UniMessage.text(
|
UniMessage.text(
|
||||||
"转换点数不足,当前剩余:{}|{}点".format(
|
"转换点数不足,当前剩余:⌊p⌋≈{:.2f}|{}".format(
|
||||||
qres[1],
|
qres[1],
|
||||||
configdict["maxPersonConvert"]["music"],
|
configdict["maxPersonConvert"]["music"],
|
||||||
)
|
)
|
||||||
@ -728,6 +740,8 @@ async def _(
|
|||||||
return True
|
return True
|
||||||
# return res, pnt
|
# return res, pnt
|
||||||
|
|
||||||
|
await linglun_convert.send(UniMessage.text("转换开始……"))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
progress_bar_style = (
|
progress_bar_style = (
|
||||||
@ -1024,11 +1038,13 @@ async def _(
|
|||||||
event=event,
|
event=event,
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(fp)
|
global file_to_delete
|
||||||
|
file_to_delete.append(fp)
|
||||||
|
# os.remove(fp)
|
||||||
|
|
||||||
await linglun_convert.finish(
|
await linglun_convert.finish(
|
||||||
UniMessage.text(
|
UniMessage.text(
|
||||||
"转换结束,当前剩余转换点数: {}|{}".format(
|
"转换结束,当前剩余转换点数:⌊p⌋≈{:.2f}|{}".format(
|
||||||
query_convert_points(usr_id, "music", 0, None)[1],
|
query_convert_points(usr_id, "music", 0, None)[1],
|
||||||
configdict["maxPersonConvert"]["music"],
|
configdict["maxPersonConvert"]["music"],
|
||||||
)
|
)
|
||||||
@ -1103,7 +1119,7 @@ async def _(
|
|||||||
|
|
||||||
await linglun_convert.finish(
|
await linglun_convert.finish(
|
||||||
UniMessage.text(
|
UniMessage.text(
|
||||||
"重置转换状况并修改点数成功!当前{}的{}点数为:{}|{}".format(
|
"重置转换状况并修改点数成功!当前{}的{}点数为:⌊p⌋≈{:.2f}|{}".format(
|
||||||
to_change,
|
to_change,
|
||||||
v_item,
|
v_item,
|
||||||
query_convert_points(to_change, v_item, -cd_value, None)[1],
|
query_convert_points(to_change, v_item, -cd_value, None)[1],
|
||||||
|
@ -5,7 +5,7 @@ import shutil
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
# from pathlib import Path
|
||||||
|
|
||||||
# import nonebot.rule
|
# import nonebot.rule
|
||||||
|
|
||||||
@ -24,15 +24,15 @@ from nonebot.adapters.onebot.v11.event import (
|
|||||||
)
|
)
|
||||||
from nonebot_plugin_alconna import (
|
from nonebot_plugin_alconna import (
|
||||||
Alconna,
|
Alconna,
|
||||||
AlconnaQuery,
|
# AlconnaQuery,
|
||||||
Args,
|
Args,
|
||||||
Image,
|
# Image,
|
||||||
Option,
|
Option,
|
||||||
Query,
|
# Query,
|
||||||
Text,
|
# Text,
|
||||||
UniMessage,
|
UniMessage,
|
||||||
on_alconna,
|
on_alconna,
|
||||||
Voice,
|
# Voice,
|
||||||
Arparma,
|
Arparma,
|
||||||
Args,
|
Args,
|
||||||
store_true,
|
store_true,
|
||||||
@ -42,12 +42,13 @@ from src.utils.base.ly_typing import T_Bot, T_MessageEvent
|
|||||||
from src.utils.message.message import MarkdownMessage
|
from src.utils.message.message import MarkdownMessage
|
||||||
|
|
||||||
from .msctexec import (
|
from .msctexec import (
|
||||||
people_convert_point,
|
# people_convert_point,
|
||||||
query_convert_points,
|
query_convert_points,
|
||||||
filesaves,
|
filesaves,
|
||||||
configdict,
|
configdict,
|
||||||
database_dir,
|
database_dir,
|
||||||
temporary_dir,
|
temporary_dir,
|
||||||
|
file_to_delete,
|
||||||
)
|
)
|
||||||
|
|
||||||
mspv_sync = on_alconna(
|
mspv_sync = on_alconna(
|
||||||
@ -111,7 +112,7 @@ async def _(
|
|||||||
if (qres := query_convert_points(usr_id, "music"))[0] is False:
|
if (qres := query_convert_points(usr_id, "music"))[0] is False:
|
||||||
await mspv_sync.finish(
|
await mspv_sync.finish(
|
||||||
UniMessage.text(
|
UniMessage.text(
|
||||||
"转换点数不足,当前剩余:{}|{}点".format(
|
"转换点数不足,当前剩余:⌊p⌋≈{:.2f}|{}".format(
|
||||||
qres[1],
|
qres[1],
|
||||||
configdict["maxPersonConvert"]["music"],
|
configdict["maxPersonConvert"]["music"],
|
||||||
)
|
)
|
||||||
@ -240,6 +241,8 @@ async def _(
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
await mspv_sync.send(UniMessage.text("转换开始……"))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
all_files = []
|
all_files = []
|
||||||
@ -407,7 +410,8 @@ async def _(
|
|||||||
except nonebot.adapters.onebot.v11.exception.NetworkError as E:
|
except nonebot.adapters.onebot.v11.exception.NetworkError as E:
|
||||||
buffer.write("文件上传发生网络错误:\n{}".format(E))
|
buffer.write("文件上传发生网络错误:\n{}".format(E))
|
||||||
|
|
||||||
os.remove(fp)
|
global file_to_delete
|
||||||
|
file_to_delete.append(fp)
|
||||||
|
|
||||||
await MarkdownMessage.send_md(
|
await MarkdownMessage.send_md(
|
||||||
"##{}\n\n```\n{}\n```".format(
|
"##{}\n\n```\n{}\n```".format(
|
||||||
@ -420,13 +424,13 @@ async def _(
|
|||||||
|
|
||||||
# nonebot.logger.info(buffer.getvalue())
|
# nonebot.logger.info(buffer.getvalue())
|
||||||
|
|
||||||
await mspv_sync.send(UniMessage.text("成功转换:{}".format("、".join(all_files))))
|
|
||||||
|
|
||||||
shutil.rmtree(usr_temp_path)
|
shutil.rmtree(usr_temp_path)
|
||||||
|
|
||||||
await mspv_sync.finish(
|
await mspv_sync.finish(
|
||||||
UniMessage.text(
|
UniMessage.text(
|
||||||
"转换结束,当前剩余转换点数: {}|{}".format(
|
"成功转换:{}\n当前剩余转换点数:⌊p⌋≈{:.2f}|{}".format(
|
||||||
|
"、".join(all_files),
|
||||||
query_convert_points(usr_id, "music", 0, None)[1],
|
query_convert_points(usr_id, "music", 0, None)[1],
|
||||||
configdict["maxPersonConvert"]["music"],
|
configdict["maxPersonConvert"]["music"],
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user