This commit is contained in:
EillesWan 2024-07-24 00:25:38 +08:00
commit 3955a7eb00
7 changed files with 195 additions and 146 deletions

View File

@ -70,8 +70,8 @@ yanlun_path = (
) )
# 每天1点更新 # 每天4点更新
@scheduler.scheduled_job("cron", hour=1) @scheduler.scheduled_job("cron", hour=4)
async def every_day_update(): async def every_day_update():
ulang = Language(get_default_lang_code(), "zh-WY") ulang = Language(get_default_lang_code(), "zh-WY")
nonebot.logger.success(ulang.get("yanlun.refresh.success", COUNT=update_yanlun())) nonebot.logger.success(ulang.get("yanlun.refresh.success", COUNT=update_yanlun()))
@ -282,3 +282,22 @@ async def _(
if (iill := int(final_length)) == final_length if (iill := int(final_length)) == final_length
else await yanlun.finish(UniMessage.text(ulang.get("yanlun.length.float"))) else await yanlun.finish(UniMessage.text(ulang.get("yanlun.length.float")))
) )
time_query = on_alconna(
command=Alconna(
"时间",
),
aliases={"时间查询", "timeq", "timequery"},
)
@time_query.handle()
async def _(
event: T_MessageEvent,
bot: T_Bot,
):
# ulang = get_user_lang(event_utils.get_user_id(event)) # type: ignore
await time_query.finish(
UniMessage.text(zhDateTime.DateTime.now().to_lunar().hanzify())
)

View File

@ -44,7 +44,7 @@
- `-p | --player-selector <字符串>` : **仅当结果类型包含 `*-delay` 之一时生效、不可多填** : 播放使用的玩家选择器;默认为`@a` - `-p | --player-selector <字符串>` : **仅当结果类型包含 `*-delay` 之一时生效、不可多填** : 播放使用的玩家选择器;默认为`@a`
- `-h | --height-limit <整数>` : **仅当结果类型包含 `*-delay`、`bdx-*` 之一时生效** : 生成结构的最大高度限制;默认为`32` - `-l | --height-limit <整数>` : **仅当结果类型包含 `*-delay`、`bdx-*` 之一时生效** : 生成结构的最大高度限制;默认为`32`
- `-a | --author <字符串>` : **仅当结果类型包含 `bdx-*` 之一时生效、不可多填** : 音乐文件的作者署名;默认为`Eilles` - `-a | --author <字符串>` : **仅当结果类型包含 `bdx-*` 之一时生效、不可多填** : 音乐文件的作者署名;默认为`Eilles`
@ -54,13 +54,16 @@
生成 midi 音乐的《我的世界》播放预览效果。每次转换基础随机消耗一次点数,**若短时间内已使用同样的参数运行过一次 音乐转换 命令,则不消耗基础点数**,并随机消耗附加点数 [1.3, 2.9] 。该命令与上文中的 `音乐转换` 命令共享点数信息。 生成 midi 音乐的《我的世界》播放预览效果。每次转换基础随机消耗一次点数,**若短时间内已使用同样的参数运行过一次 音乐转换 命令,则不消耗基础点数**,并随机消耗附加点数 [1.3, 2.9] 。该命令与上文中的 `音乐转换` 命令共享点数信息。
- `-n | --file-name` : 缓存中的 midi 文件名称,需提前上传 mid 文件;默认为`all` - `-n | -f | --file-name` : 缓存中的 midi 文件名称,需提前上传 mid 文件;默认为`all`
- `-m | --mode` : 合成模式,支持以下内容。默认为 `0` - `-m | --mode` : 合成模式,支持以下内容。默认为 `0`
- 0 原始长度,不变化时长 - 0 原始长度,不变化时长
- 1 拉伸至 mc 播放器定义(我的世界效果) - 1 拉伸至 mc 播放器定义(我的世界效果)
- 2 根据 midi 音符长度裁剪 - 2 根据 midi 音符长度裁剪
- 3 混音预留 - 3 混音预留
- 4 匹配 midi 音符长度(最佳效果) - 4 匹配 midi 音符长度(最佳效果)
- `-g | --get-value-method` : GVM取值法支持以下内容。默认为 `1`
- 0 均值化
- 1 钳制位
- `-o | --output-file` : 是否输出文件,默认为`False` - `-o | --output-file` : 是否输出文件,默认为`False`
- 以下命令同上 音乐转换 参数 - 以下命令同上 音乐转换 参数
- `-emr | --enable-mismatch-error` - `-emr | --enable-mismatch-error`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 564 KiB

After

Width:  |  Height:  |  Size: 662 KiB

View File

@ -56,7 +56,7 @@ from src.utils.base.language import get_user_lang
from src.utils.message.message import MarkdownMessage from src.utils.message.message import MarkdownMessage
from .execute_auto_translator import auto_translate # type: ignore from .execute_auto_translator import auto_translate # type: ignore
from .utils import utime_hanzify
nonebot.require("nonebot_plugin_alconna") nonebot.require("nonebot_plugin_alconna")
nonebot.require("nonebot_plugin_apscheduler") nonebot.require("nonebot_plugin_apscheduler")
@ -180,7 +180,7 @@ def query_convert_points(
return store, people_convert_point[usr_id][item]["point"] return store, people_convert_point[usr_id][item]["point"]
# 每天1点更新 # 每天4点更新
@scheduler.scheduled_job("cron", hour=4) @scheduler.scheduled_job("cron", hour=4)
async def every_day_update(): async def every_day_update():
# ulang = Language(get_default_lang_code(), "zh-WY") # ulang = Language(get_default_lang_code(), "zh-WY")
@ -206,6 +206,7 @@ async def _():
file_to_delete = [] 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(
@ -237,8 +238,7 @@ async def _():
except: except:
pass pass
if qqid in people_convert_point: query_convert_points(qqid,"music",0,False)
del people_convert_point[qqid]
filesaves[qqid]["totalSize"] -= filesaves[qqid][name]["size"] filesaves[qqid]["totalSize"] -= filesaves[qqid][name]["size"]
nonebot.logger.info( nonebot.logger.info(
"\t删除{}".format(name), "\t删除{}".format(name),
@ -762,15 +762,12 @@ async def _(
all_files[file_to_convert] = {} all_files[file_to_convert] = {}
if ( if isinstance(
((msct_obj := query_convert_points(usr_id, "music", 0)[0]) is None) msct_obj := query_convert_points(usr_id, "music", 0)[0], tuple
or ( ) and (
isinstance(msct_obj, tuple)
and (
(
isinstance(msct_obj[0], Musicreater.MidiConvert) isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1] and msct_obj[1]
!= ( == (
not _args["enable-mismatch-error"], not _args["enable-mismatch-error"],
_args["play-speed"], _args["play-speed"],
_args["default-tempo"], _args["default-tempo"],
@ -778,16 +775,20 @@ async def _(
percussion_notechart, percussion_notechart,
volume_curve, volume_curve,
) )
) and (
or (
msct_obj[0].music_name msct_obj[0].music_name
!= os.path.splitext( == os.path.splitext(
os.path.basename(usr_data_path / file_to_convert) os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_") )[0].replace(" ", "_")
) )
) ):
) nonebot.logger.info("载入已有缓存。")
) and go_chk_point(): msct_obj = msct_obj[0]
msct_obj.redefine_execute_format(_args["old-execute-format"])
msct_obj.set_min_volume(_args["minimal-volume"])
# msct_obj.set_deviation()
else:
if go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file( msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert, midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"], mismatch_error_ignorance=not _args["enable-mismatch-error"],
@ -815,28 +816,6 @@ async def _(
), ),
), ),
) )
elif isinstance(msct_obj, tuple) and (
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
== (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
)
and (
msct_obj[0].music_name
!= os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
):
msct_obj = msct_obj[0]
msct_obj.redefine_execute_format(_args["old-execute-format"])
msct_obj.set_min_volume(_args["minimal-volume"])
# msct_obj.set_deviation()
else: else:
buffer.write( buffer.write(
"点数不足或出现错误:{}".format( "点数不足或出现错误:{}".format(
@ -844,6 +823,7 @@ async def _(
) )
) )
break break
# people_convert_point[usr_id] += 0.5 # people_convert_point[usr_id] += 0.5
if "msq" in all_cvt_types: if "msq" in all_cvt_types:
@ -974,19 +954,30 @@ async def _(
"无可供转换的文件", "无可供转换的文件",
) )
await linglun_convert.finish( await linglun_convert.finish(
UniMessage("不是哥们,空气咱这转不成面包,那是中科院的事。") UniMessage("不是哥们,二氧化碳咱这转不成面包,那是中科院的事。")
) )
except Exception as e: except Exception as e:
nonebot.logger.error("转换存在错误:{}".format(e)) nonebot.logger.error("转换存在错误:{}".format(e))
buffer.write("[ERROR] {}\n".format(e)) buffer.write(
"[ERROR] {}\n".format(e).replace(
"C:\\Users\\Administrator\\Desktop\\RyBot\\", "[]"
)
)
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
Musicreater.plugin.archive.compress_zipfile( Musicreater.plugin.archive.compress_zipfile(
usr_temp_path, usr_temp_path,
fp := str(temporary_dir / (fn := "result-{}.zip".format(usr_id))), fp := str(
temporary_dir
/ (
fn := "msctr[{}]-{}.zip".format(
utime_hanzify(zhDateTime.DateTime.now().to_lunar()), usr_id
)
)
),
) )
shutil.rmtree(usr_temp_path) shutil.rmtree(usr_temp_path)

View File

@ -5,12 +5,14 @@ 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
import nonebot import nonebot
import soundfile import soundfile
import zhDateTime
import Musicreater import Musicreater
import Musicreater.plugin import Musicreater.plugin
import nonebot.adapters.onebot.v11.exception import nonebot.adapters.onebot.v11.exception
@ -50,12 +52,16 @@ from .msctexec import (
temporary_dir, temporary_dir,
file_to_delete, file_to_delete,
) )
from .utils import utime_hanzify
mspv_sync = on_alconna( mspv_sync = on_alconna(
Alconna( Alconna(
"音乐合成", "音乐合成",
Option("-n|--file-name", default="all", args=Args["file-name", str, "all"]), Option("-n|-f|--file-name", default="all", args=Args["file-name", str, "all"]),
Option("-m|--mode", default=0, args=Args["mode", int, 0]), Option("-m|--mode", default=0, args=Args["mode", int, 0]),
Option(
"-g|--get-value-method", default=1, args=Args["get-value-method", int, 1]
),
Option("-o|--output-file", default=False, action=store_true), Option("-o|--output-file", default=False, action=store_true),
Option("-emr|--enable-mismatch-error", default=False, action=store_true), Option("-emr|--enable-mismatch-error", default=False, action=store_true),
Option("-ps|--play-speed", default=1.0, args=Args["play-speed", float, 1.0]), Option("-ps|--play-speed", default=1.0, args=Args["play-speed", float, 1.0]),
@ -129,6 +135,7 @@ async def _(
"file-name": "all", "file-name": "all",
"output-file": False, "output-file": False,
"mode": 0, "mode": 0,
"get-value-method": 1,
"enable-mismatch-error": False, "enable-mismatch-error": False,
"play-speed": 1.0, "play-speed": 1.0,
"default-tempo": 500000, "default-tempo": 500000,
@ -156,6 +163,16 @@ async def _(
UniMessage.text("模式 {} 不存在,请详阅文档。".format(_args["mode"])) UniMessage.text("模式 {} 不存在,请详阅文档。".format(_args["mode"]))
) )
if _args["get-value-method"] not in [
0,
1,
]:
await mspv_sync.finish(
UniMessage.text(
"取值法 {} 不存在,请详阅文档。".format(_args["get-value-method"])
)
)
usr_data_path = database_dir / usr_id usr_data_path = database_dir / usr_id
(usr_temp_path := temporary_dir / usr_id).mkdir(exist_ok=True) (usr_temp_path := temporary_dir / usr_id).mkdir(exist_ok=True)
@ -256,15 +273,14 @@ async def _(
nonebot.logger.info("载入待合成文件:{}".format(file_to_convert)) nonebot.logger.info("载入待合成文件:{}".format(file_to_convert))
# print("1") # print("1")
# await mspv_sync.finish("处理中") # await mspv_sync.finish("处理中")
if (
((msct_obj := query_convert_points(usr_id, "music", 0)[0]) is None) if isinstance(
or ( msct_obj := query_convert_points(usr_id, "music", 0)[0], tuple
isinstance(msct_obj, tuple) ) and (
and (
(
isinstance(msct_obj[0], Musicreater.MidiConvert) isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1] and (
!= ( msct_obj[1]
== (
not _args["enable-mismatch-error"], not _args["enable-mismatch-error"],
_args["play-speed"], _args["play-speed"],
_args["default-tempo"], _args["default-tempo"],
@ -273,15 +289,18 @@ async def _(
volume_curve, volume_curve,
) )
) )
or ( and (
msct_obj[0].music_name msct_obj[0].music_name
!= os.path.splitext( == os.path.splitext(
os.path.basename(usr_data_path / file_to_convert) os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_") )[0].replace(" ", "_")
) )
) ):
) nonebot.logger.info("载入已有缓存。")
) and go_chk_point(): msct_obj = msct_obj[0]
else:
if go_chk_point():
msct_obj = Musicreater.MidiConvert.from_midi_file( msct_obj = Musicreater.MidiConvert.from_midi_file(
midi_file_path=usr_data_path / file_to_convert, midi_file_path=usr_data_path / file_to_convert,
mismatch_error_ignorance=not _args["enable-mismatch-error"], mismatch_error_ignorance=not _args["enable-mismatch-error"],
@ -307,26 +326,6 @@ async def _(
), ),
), ),
) )
elif isinstance(msct_obj, tuple) and (
isinstance(msct_obj[0], Musicreater.MidiConvert)
and msct_obj[1]
== (
not _args["enable-mismatch-error"],
_args["play-speed"],
_args["default-tempo"],
pitched_notechart,
percussion_notechart,
volume_curve,
)
and (
msct_obj[0].music_name
!= os.path.splitext(
os.path.basename(usr_data_path / file_to_convert)
)[0].replace(" ", "_")
)
):
nonebot.logger.info("载入已有缓存。")
msct_obj = msct_obj[0]
else: else:
buffer.write( buffer.write(
"点数不足或出现错误:\n{}".format( "点数不足或出现错误:\n{}".format(
@ -339,8 +338,8 @@ async def _(
music_temp = PreviewMusic( music_temp = PreviewMusic(
msct_obj, msct_obj,
mode=1, mode=_args["mode"],
gvm=1, gvm=_args["get-value-method"],
default_channel_num=1, default_channel_num=1,
overlay_channels=1, overlay_channels=1,
out_sr=44100, out_sr=44100,
@ -385,7 +384,11 @@ async def _(
except Exception as e: except Exception as e:
nonebot.logger.error("合成存在错误:{}".format(e)) nonebot.logger.error("合成存在错误:{}".format(e))
buffer.write("[ERROR] {}\n".format(e)) buffer.write(
"[ERROR] {}\n".format(e).replace(
"C:\\Users\\Administrator\\Desktop\\RyBot\\", "[]"
)
)
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
@ -393,7 +396,14 @@ async def _(
if _args["output-file"]: if _args["output-file"]:
Musicreater.plugin.archive.compress_zipfile( Musicreater.plugin.archive.compress_zipfile(
usr_temp_path, usr_temp_path,
fp := str(temporary_dir / (fn := "mpr-wav-{}.zip".format(usr_id))), fp := str(
temporary_dir
/ (
fn := "mprwav[{}]{}.zip".format(
utime_hanzify(zhDateTime.DateTime.now().to_lunar()), usr_id
)
)
),
) )
try: try:
@ -424,7 +434,6 @@ async def _(
# nonebot.logger.info(buffer.getvalue()) # nonebot.logger.info(buffer.getvalue())
shutil.rmtree(usr_temp_path) shutil.rmtree(usr_temp_path)
await mspv_sync.finish( await mspv_sync.finish(

View File

@ -0,0 +1,27 @@
import zhDateTime
def utime_hanzify(
zhd: zhDateTime.zhDateTime = zhDateTime.DateTime.now().to_lunar(),
) -> str:
return "{地支时}{刻}{分}{秒}".format(
地支时=zhDateTime.DÌZHĪ[zhd.shichen]
+ (
""
if ((zhd.quarters) or (zhd.minutes) or (zhd.seconds) or (zhd.microseconds))
else ""
),
=(
(zhDateTime.HANNUM[zhd.quarters])
+ ("" if ((zhd.minutes) or (zhd.seconds) or (zhd.microseconds)) else "")
),
=(
zhDateTime.lkint_hànzìfy(zhd.minutes)
+ ("" if ((zhd.seconds) or (zhd.microseconds)) else "")
),
=(
zhDateTime.HANNUM[zhd.seconds // 10]
+ zhDateTime.HANNUM[zhd.seconds % 10]
+ ("" if (zhd.microseconds) else "")
),
).strip()