koishi-plugin-best-cave 1.5.10 → 1.5.12
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 +7 -12
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1271,7 +1271,10 @@ async function buildMessage(cave, resourceDir, session) {
|
|
|
1271
1271
|
lines.push(element.content);
|
|
1272
1272
|
} else if (element.type === "img" && element.file) {
|
|
1273
1273
|
const filePath = path5.join(resourceDir, element.file);
|
|
1274
|
-
|
|
1274
|
+
const base64Data = await processMediaFile(filePath, "image");
|
|
1275
|
+
if (base64Data) {
|
|
1276
|
+
lines.push((0, import_koishi5.h)("image", { src: base64Data }));
|
|
1277
|
+
}
|
|
1275
1278
|
}
|
|
1276
1279
|
}
|
|
1277
1280
|
lines.push(session.text("commands.cave.message.contributorSuffix", [cave.contributor_name]));
|
|
@@ -1297,17 +1300,9 @@ async function sendMessage(session, key, params = [], isTemp = true, timeout = 1
|
|
|
1297
1300
|
}
|
|
1298
1301
|
__name(sendMessage, "sendMessage");
|
|
1299
1302
|
async function processMediaFile(filePath, type) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
return filePath;
|
|
1304
|
-
} else {
|
|
1305
|
-
const data = await fs5.promises.readFile(filePath);
|
|
1306
|
-
return `data:${type}/mp4;base64,${data.toString("base64")}`;
|
|
1307
|
-
}
|
|
1308
|
-
} catch {
|
|
1309
|
-
return null;
|
|
1310
|
-
}
|
|
1303
|
+
const data = await fs5.promises.readFile(filePath).catch(() => null);
|
|
1304
|
+
if (!data) return null;
|
|
1305
|
+
return `data:${type}/${type === "image" ? "png" : "mp4"};base64,${data.toString("base64")}`;
|
|
1311
1306
|
}
|
|
1312
1307
|
__name(processMediaFile, "processMediaFile");
|
|
1313
1308
|
async function extractMediaContent(originalContent, config, session) {
|