mioku-plugin-deerpipe 1.1.0 → 1.1.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/image.ts +23 -4
- package/index.ts +3 -5
- package/package.json +1 -1
package/image.ts
CHANGED
|
@@ -65,17 +65,36 @@ interface AssetUris {
|
|
|
65
65
|
|
|
66
66
|
let assetsCache: AssetUris | null = null;
|
|
67
67
|
|
|
68
|
+
const TRANSPARENT_PNG =
|
|
69
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNgAAIAAAUAAen63NgAAAAASUVORK5CYII=";
|
|
70
|
+
|
|
68
71
|
async function loadAssets(): Promise<AssetUris> {
|
|
69
72
|
if (assetsCache) return assetsCache;
|
|
70
73
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
71
74
|
const assetsDir = path.join(here, "assets");
|
|
75
|
+
|
|
76
|
+
async function readOptional(name: string): Promise<Buffer | null> {
|
|
77
|
+
try {
|
|
78
|
+
return await fs.readFile(path.join(assetsDir, name));
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
const [avatar, check, deerpipe] = await Promise.all([
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
readOptional("akkarin@80x80.png"),
|
|
86
|
+
readOptional("check@96x100.png"),
|
|
87
|
+
readOptional("deerpipe@100x82.png"),
|
|
76
88
|
]);
|
|
89
|
+
if (!check || !deerpipe) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"deerpipe 必需素材缺失:check@96x100.png / deerpipe@100x82.png",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
77
94
|
assetsCache = {
|
|
78
|
-
defaultAvatar:
|
|
95
|
+
defaultAvatar: avatar
|
|
96
|
+
? `data:image/png;base64,${avatar.toString("base64")}`
|
|
97
|
+
: TRANSPARENT_PNG,
|
|
79
98
|
check: `data:image/png;base64,${check.toString("base64")}`,
|
|
80
99
|
deerpipe: `data:image/png;base64,${deerpipe.toString("base64")}`,
|
|
81
100
|
};
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ScreenshotService } from "mioku";
|
|
2
1
|
import { definePlugin, type MiokiContext } from "mioki";
|
|
2
|
+
import { getService, Services } from "mioku";
|
|
3
3
|
import { initDeerDatabase, type DeerDatabase } from "./db";
|
|
4
4
|
import { handleDeerCommand, parseDeerCommand } from "./commands";
|
|
5
5
|
|
|
@@ -11,9 +11,7 @@ const deerpipePlugin = definePlugin({
|
|
|
11
11
|
async setup(ctx: MiokiContext) {
|
|
12
12
|
ctx.logger.info("deerpipe 插件正在初始化...");
|
|
13
13
|
|
|
14
|
-
const screenshotService = ctx.
|
|
15
|
-
| ScreenshotService
|
|
16
|
-
| undefined;
|
|
14
|
+
const screenshotService = getService(ctx, Services.Screenshot);
|
|
17
15
|
|
|
18
16
|
if (!screenshotService) {
|
|
19
17
|
ctx.logger.warn("screenshot 服务未加载,deerpipe 插件无法生成图片");
|
|
@@ -51,7 +49,7 @@ const deerpipePlugin = definePlugin({
|
|
|
51
49
|
}
|
|
52
50
|
});
|
|
53
51
|
|
|
54
|
-
ctx.handle("message", async (event
|
|
52
|
+
ctx.handle("message", async (event) => {
|
|
55
53
|
const text = ctx.text(event);
|
|
56
54
|
if (!text) return;
|
|
57
55
|
|