mioku-plugin-meme 2.1.3 → 3.0.1
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/index.ts +2 -2
- package/package.json +3 -5
- package/shared.ts +17 -36
- package/skills/meme.ts +4 -4
- package/types.ts +1 -1
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
definePlugin,
|
|
3
|
-
type
|
|
3
|
+
type MiokuContext,
|
|
4
4
|
getService,
|
|
5
5
|
Services,
|
|
6
6
|
} from "mioku";
|
|
@@ -45,7 +45,7 @@ const memePlugin = definePlugin({
|
|
|
45
45
|
version: "1.0.0",
|
|
46
46
|
description: "基于 meme-generator API 的表情包制作插件",
|
|
47
47
|
|
|
48
|
-
async setup(ctx:
|
|
48
|
+
async setup(ctx: MiokuContext) {
|
|
49
49
|
const configService = getService(ctx, Services.Config);
|
|
50
50
|
const aiService = getService(ctx, Services.AI);
|
|
51
51
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-meme",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "基于 meme-generator API 的表情包制作插件",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -82,11 +82,9 @@
|
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"mioku": "^0.
|
|
86
|
-
"mioki": "^0.16.0"
|
|
85
|
+
"mioku": "^1.0.0"
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
89
|
-
"mioku": "workspace:*"
|
|
90
|
-
"mioki": "^0.16.0"
|
|
88
|
+
"mioku": "workspace:*"
|
|
91
89
|
}
|
|
92
90
|
}
|
package/shared.ts
CHANGED
|
@@ -187,10 +187,10 @@ export async function replyWithParts(options: {
|
|
|
187
187
|
parts: any[];
|
|
188
188
|
quoteReply?: boolean;
|
|
189
189
|
}): Promise<void> {
|
|
190
|
-
const { event, parts, quoteReply = false } = options;
|
|
190
|
+
const { ctx, event, parts, quoteReply = false } = options;
|
|
191
191
|
const payload = [...parts];
|
|
192
192
|
if (quoteReply && event?.message_id != null) {
|
|
193
|
-
payload.unshift(
|
|
193
|
+
payload.unshift(ctx.segment.reply(event.message_id));
|
|
194
194
|
}
|
|
195
195
|
await event.reply(payload.length === 1 ? payload[0] : payload);
|
|
196
196
|
}
|
|
@@ -208,9 +208,7 @@ export async function replyWithImage(options: {
|
|
|
208
208
|
parts.push(caption);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
const imageSegment = ctx
|
|
212
|
-
? ctx.segment.image(image)
|
|
213
|
-
: { type: "image", file: image };
|
|
211
|
+
const imageSegment = ctx.segment.image(image);
|
|
214
212
|
parts.push(imageSegment);
|
|
215
213
|
|
|
216
214
|
try {
|
|
@@ -228,11 +226,7 @@ export async function replyWithImage(options: {
|
|
|
228
226
|
if (caption) {
|
|
229
227
|
fallbackParts.push(caption);
|
|
230
228
|
}
|
|
231
|
-
fallbackParts.push(
|
|
232
|
-
ctx?.segment?.image
|
|
233
|
-
? ctx.segment.image(base64Image)
|
|
234
|
-
: { type: "image", file: base64Image },
|
|
235
|
-
);
|
|
229
|
+
fallbackParts.push(ctx.segment.image(base64Image));
|
|
236
230
|
await replyWithParts({ ctx, event, parts: fallbackParts, quoteReply });
|
|
237
231
|
}
|
|
238
232
|
|
|
@@ -244,11 +238,7 @@ export async function sendSkillImage(options: {
|
|
|
244
238
|
quoteReply?: boolean;
|
|
245
239
|
}): Promise<void> {
|
|
246
240
|
const { ctx, event, image, caption, quoteReply = false } = options;
|
|
247
|
-
const
|
|
248
|
-
const bot =
|
|
249
|
-
selfId != null && typeof ctx?.pickBot === "function"
|
|
250
|
-
? ctx.pickBot(selfId)
|
|
251
|
-
: undefined;
|
|
241
|
+
const bot = event?.bot;
|
|
252
242
|
|
|
253
243
|
if (!bot) {
|
|
254
244
|
throw new Error("当前上下文不支持发送图片");
|
|
@@ -257,14 +247,12 @@ export async function sendSkillImage(options: {
|
|
|
257
247
|
const buildPayload = (file: string) => {
|
|
258
248
|
const payload: any[] = [];
|
|
259
249
|
if (quoteReply && event?.message_id != null) {
|
|
260
|
-
payload.push(
|
|
250
|
+
payload.push(ctx.segment.reply(event.message_id));
|
|
261
251
|
}
|
|
262
252
|
if (caption) {
|
|
263
253
|
payload.push(caption);
|
|
264
254
|
}
|
|
265
|
-
payload.push(
|
|
266
|
-
ctx?.segment?.image ? ctx.segment.image(file) : { type: "image", file },
|
|
267
|
-
);
|
|
255
|
+
payload.push(ctx.segment.image(file));
|
|
268
256
|
return payload;
|
|
269
257
|
};
|
|
270
258
|
|
|
@@ -622,11 +610,7 @@ export class MemePluginRuntime {
|
|
|
622
610
|
);
|
|
623
611
|
const previewBuffer = Buffer.from(await previewResponse.arrayBuffer());
|
|
624
612
|
const previewBase64 = await imageBufferToBase64(previewBuffer);
|
|
625
|
-
parts.push(
|
|
626
|
-
ctx?.segment?.image
|
|
627
|
-
? ctx.segment.image(previewBase64)
|
|
628
|
-
: { type: "image", file: previewBase64 },
|
|
629
|
-
);
|
|
613
|
+
parts.push(ctx.segment.image(previewBase64));
|
|
630
614
|
} catch (error) {
|
|
631
615
|
this.logger.warn(`[meme] 获取预览失败: ${error}`);
|
|
632
616
|
}
|
|
@@ -930,8 +914,8 @@ export class MemePluginRuntime {
|
|
|
930
914
|
}
|
|
931
915
|
|
|
932
916
|
if (sourceType === "message_image") {
|
|
933
|
-
const messageId =
|
|
934
|
-
if (!
|
|
917
|
+
const messageId = String(source?.messageId ?? "").trim();
|
|
918
|
+
if (!messageId) {
|
|
935
919
|
return [];
|
|
936
920
|
}
|
|
937
921
|
const imageUrl = await this.getImageUrlByMessageId(ctx, event, messageId);
|
|
@@ -975,14 +959,14 @@ export class MemePluginRuntime {
|
|
|
975
959
|
private async getImageUrlByMessageId(
|
|
976
960
|
ctx: any,
|
|
977
961
|
event: any,
|
|
978
|
-
messageId: number,
|
|
962
|
+
messageId: string | number,
|
|
979
963
|
): Promise<string | null> {
|
|
980
964
|
try {
|
|
981
|
-
const
|
|
982
|
-
if (
|
|
965
|
+
const bot = event?.bot;
|
|
966
|
+
if (!bot) {
|
|
983
967
|
return null;
|
|
984
968
|
}
|
|
985
|
-
const msg = await
|
|
969
|
+
const msg = await bot.getMessage(messageId);
|
|
986
970
|
if (!msg?.message || !Array.isArray(msg.message)) {
|
|
987
971
|
return null;
|
|
988
972
|
}
|
|
@@ -1013,11 +997,8 @@ export class MemePluginRuntime {
|
|
|
1013
997
|
];
|
|
1014
998
|
}
|
|
1015
999
|
|
|
1016
|
-
const bot =
|
|
1017
|
-
|
|
1018
|
-
? ctx.pickBot(event.self_id)
|
|
1019
|
-
: undefined;
|
|
1020
|
-
if (!bot?.getGroupMemberInfo) {
|
|
1000
|
+
const bot = event?.bot;
|
|
1001
|
+
if (!bot) {
|
|
1021
1002
|
return atUserIds.map((userId) => ({
|
|
1022
1003
|
name: String(userId),
|
|
1023
1004
|
gender: "unknown",
|
|
@@ -1027,7 +1008,7 @@ export class MemePluginRuntime {
|
|
|
1027
1008
|
const infos = await Promise.all(
|
|
1028
1009
|
atUserIds.map(async (userId) => {
|
|
1029
1010
|
try {
|
|
1030
|
-
const member = await bot.
|
|
1011
|
+
const member = await bot.getMemberInfo(event.group_id, userId);
|
|
1031
1012
|
return {
|
|
1032
1013
|
name: member?.card || member?.nickname || String(userId),
|
|
1033
1014
|
gender: String(member?.sex || "unknown"),
|
package/skills/meme.ts
CHANGED
|
@@ -33,8 +33,8 @@ function parseImageSource(args: any): {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (sourceType === "message_image") {
|
|
36
|
-
const messageId =
|
|
37
|
-
if (!
|
|
36
|
+
const messageId = String(args?.message_id ?? "").trim();
|
|
37
|
+
if (!messageId) {
|
|
38
38
|
return {
|
|
39
39
|
ok: false,
|
|
40
40
|
message: "source_type=message_image 时必须提供有效的 message_id。",
|
|
@@ -114,9 +114,9 @@ export function createMemeSkills(runtime: MemePluginRuntime): AISkill[] {
|
|
|
114
114
|
description: "source_type=user_avatar 时必填,头像对应 QQ 号",
|
|
115
115
|
},
|
|
116
116
|
message_id: {
|
|
117
|
-
type: "number",
|
|
117
|
+
type: ["number", "string"],
|
|
118
118
|
description:
|
|
119
|
-
"source_type=message_image 时必填,包含图片的消息 message_id",
|
|
119
|
+
"source_type=message_image 时必填,包含图片的消息 message_id(支持数字或含字母的字符串 id)",
|
|
120
120
|
},
|
|
121
121
|
},
|
|
122
122
|
required: ["keyword", "source_type"],
|
package/types.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type MemeImageSourceType = "auto" | "user_avatar" | "message_image";
|
|
|
43
43
|
export interface MemeImageSourceOptions {
|
|
44
44
|
type?: MemeImageSourceType;
|
|
45
45
|
qq?: number;
|
|
46
|
-
messageId?: number;
|
|
46
|
+
messageId?: number | string;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface MemeInfoParams {
|