mioku-plugin-meme 2.1.3 → 3.0.0

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.
Files changed (3) hide show
  1. package/index.ts +2 -2
  2. package/package.json +3 -5
  3. package/shared.ts +14 -33
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  definePlugin,
3
- type MiokiContext,
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: MiokiContext) {
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": "2.1.3",
3
+ "version": "3.0.0",
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.8.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({ type: "reply", id: String(event.message_id) });
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?.segment?.image
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 selfId = event?.self_id != null ? Number(event.self_id) : undefined;
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({ type: "reply", id: String(event.message_id) });
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
  }
@@ -978,11 +962,11 @@ export class MemePluginRuntime {
978
962
  messageId: number,
979
963
  ): Promise<string | null> {
980
964
  try {
981
- const selfId = event?.self_id != null ? Number(event.self_id) : undefined;
982
- if (selfId == null || !ctx?.pickBot) {
965
+ const bot = event?.bot;
966
+ if (!bot) {
983
967
  return null;
984
968
  }
985
- const msg = await ctx.pickBot(selfId).getMsg(messageId);
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
- event?.self_id != null && typeof ctx?.pickBot === "function"
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.getGroupMemberInfo(event.group_id, userId);
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"),