koishi-plugin-nmc-radar 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +10 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -39,6 +39,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
39
39
|
var import_node_buffer = require("node:buffer");
|
|
40
40
|
var import_promises = require("node:fs/promises");
|
|
41
41
|
var import_node_path = __toESM(require("node:path"));
|
|
42
|
+
var import_node_url = require("node:url");
|
|
42
43
|
var import_jsdom = require("jsdom");
|
|
43
44
|
var import_koishi = require("koishi");
|
|
44
45
|
|
|
@@ -333,7 +334,7 @@ var Config = import_koishi.Schema.object({
|
|
|
333
334
|
defaultResolver: import_koishi.Schema.union(Object.keys(resolvers)).default("img").description("默认输出类型。")
|
|
334
335
|
});
|
|
335
336
|
function apply(ctx, config) {
|
|
336
|
-
const command = ctx.command("radar <name:string>", "查看雷达图"
|
|
337
|
+
const command = ctx.command("radar <name:string>", "查看雷达图").alias("雷达").option("name", "--name <name:string> 雷达站名称").option("count", "-n <count:number> 最大输出数量").option("reverse", "-R 反转顺序").option("type", "--type <type:string> 输出类型", { type: Object.keys(resolvers) }).option("type", "--img 输出图片", { value: "img" }).option("type", "--url 输出 URL", { value: "url" }).action(async ({ session, options = {} }, name2) => {
|
|
337
338
|
options.name ??= name2;
|
|
338
339
|
if (!(name2 in radars_default))
|
|
339
340
|
return void session?.send("雷达站不存在,可使用 radar.list 查看所有雷达站。");
|
|
@@ -355,7 +356,7 @@ function apply(ctx, config) {
|
|
|
355
356
|
const baseDir = import_node_path.default.join(ctx2.baseDir, "cache", name, options.name);
|
|
356
357
|
const outputPath = import_node_path.default.join(baseDir, [
|
|
357
358
|
`${products[0].slug}+${products[products.length - 1].slug}`,
|
|
358
|
-
|
|
359
|
+
`#${options.fps}@${options.loop}.gif`
|
|
359
360
|
].join(""));
|
|
360
361
|
try {
|
|
361
362
|
await (0, import_promises.access)(outputPath);
|
|
@@ -375,12 +376,14 @@ function apply(ctx, config) {
|
|
|
375
376
|
}
|
|
376
377
|
return filePath;
|
|
377
378
|
}));
|
|
378
|
-
const buffer =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
379
|
+
const buffer = filePaths.filter(Boolean).flatMap((filePath) => `file '${filePath.replaceAll("\\", "/")}'`).join("\n");
|
|
380
|
+
await ctx2.ffmpeg.builder().input(import_node_buffer.Buffer.from(buffer)).inputOption("-f", "concat").inputOption("-safe", "0").inputOption("-protocol_whitelist", "file,fd").inputOption("-r", options.fps).outputOption("-loop", options.loop).outputOption("-filter_complex", [
|
|
381
|
+
"[0:v]split[out1][out2]",
|
|
382
|
+
"[out1]palettegen[p]",
|
|
383
|
+
"[out2][p]paletteuse"
|
|
384
|
+
].join(";")).run("file", outputPath);
|
|
382
385
|
}
|
|
383
|
-
return import_koishi.h.img(
|
|
386
|
+
return import_koishi.h.img((0, import_node_url.pathToFileURL)(outputPath).href);
|
|
384
387
|
};
|
|
385
388
|
});
|
|
386
389
|
command.subcommand(".list", "查看所有雷达站").action(() => Object.keys(radars_default).join(" "));
|