mioku-plugin-music 2.4.4 → 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.
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { definePlugin } from "mioki";
1
+ import { definePlugin } from "mioku";
2
2
  import { AppleMusicService } from "mioku-service-applemusic";
3
3
  import { NeteaseService } from "mioku-service-netease";
4
4
  import { getService, Services } from "mioku";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-plugin-music",
3
- "version": "2.4.4",
3
+ "version": "3.0.0",
4
4
  "description": "音乐插件:点歌、搜索音乐、听歌语音发送",
5
5
  "main": "index.ts",
6
6
  "type": "module",
@@ -57,14 +57,12 @@
57
57
  }
58
58
  },
59
59
  "peerDependencies": {
60
- "mioku": "^0.8.0",
61
- "mioki": "^0.16.0",
62
- "mioku-service-applemusic": "^2.0.0",
63
- "mioku-service-netease": "^1.0.0"
60
+ "mioku": "^1.0.0",
61
+ "mioku-service-applemusic": "^3.0.0",
62
+ "mioku-service-netease": "^2.0.0"
64
63
  },
65
64
  "devDependencies": {
66
65
  "mioku": "workspace:*",
67
- "mioki": "^0.16.0",
68
66
  "mioku-service-applemusic": "workspace:*",
69
67
  "mioku-service-netease": "workspace:*"
70
68
  }
@@ -4,11 +4,11 @@ import { getMusicProviderLabel } from "../providers/provider-labels";
4
4
  function escapeHtml(value: string): string {
5
5
  const source = String(value || "");
6
6
  return source
7
- .replace(/&/g, "&")
8
- .replace(/</g, "&lt;")
9
- .replace(/>/g, "&gt;")
10
- .replace(/"/g, "&quot;")
11
- .replace(/'/g, "&#039;");
7
+ .replace(/&/g, "&amp);")
8
+ .replace(/</g, "&lt);")
9
+ .replace(/>/g, "&gt);")
10
+ .replace(/"/g, "&quot);")
11
+ .replace(/'/g, "&#039);");
12
12
  }
13
13
 
14
14
  export function renderMusicSearchListHtml(search: MusicSearchResult): string {
@@ -25,16 +25,12 @@ function getBotAndTarget(ctx: any, event: any): {
25
25
  groupId?: number;
26
26
  userId?: number;
27
27
  } {
28
- const selfId = event?.self_id != null ? Number(event.self_id) : undefined;
29
- const bot =
30
- selfId != null && typeof ctx?.pickBot === "function"
31
- ? ctx.pickBot(selfId)
32
- : undefined;
28
+ const bot = event?.bot;
33
29
 
34
30
  return {
35
31
  bot,
36
- groupId: event?.message_type === "group" ? Number(event.group_id) : undefined,
37
- userId: event?.message_type !== "group" ? Number(event?.user_id) : undefined,
32
+ groupId: event?.message_type === "group" ? event.group_id : undefined,
33
+ userId: event?.message_type !== "group" ? event?.user_id : undefined,
38
34
  };
39
35
  }
40
36
 
@@ -46,7 +42,7 @@ export async function sendTextMessage(
46
42
  const { bot, groupId, userId } = getBotAndTarget(ctx, event);
47
43
  const payload: any[] = [];
48
44
 
49
- payload.push(ctx?.segment?.text ? ctx.segment.text(text) : { type: "text", text });
45
+ payload.push(ctx.segment.text(text));
50
46
 
51
47
  if (bot && groupId != null) {
52
48
  await bot.sendGroupMsg(groupId, payload);
@@ -71,11 +67,7 @@ export async function sendImageMessage(
71
67
  const { bot, groupId, userId } = getBotAndTarget(ctx, event);
72
68
  const sendPayload = async (source: string) => {
73
69
  const payload: any[] = [];
74
- payload.push(
75
- ctx?.segment?.image
76
- ? ctx.segment.image(normalizeFileSource(source))
77
- : { type: "image", file: normalizeFileSource(source) },
78
- );
70
+ payload.push(ctx.segment.image(normalizeFileSource(source)));
79
71
 
80
72
  if (bot && groupId != null) {
81
73
  await bot.sendGroupMsg(groupId, payload);
@@ -112,11 +104,7 @@ export async function sendFileMessage(
112
104
  const { bot, groupId, userId } = getBotAndTarget(ctx, event);
113
105
  const sendPayload = async (source: string) => {
114
106
  const payload: any[] = [];
115
- payload.push(
116
- ctx?.segment?.file
117
- ? ctx.segment.file(normalizeFileSource(source), { name: fileName })
118
- : { type: "file", file: normalizeFileSource(source), name: fileName },
119
- );
107
+ payload.push(ctx.segment.file(normalizeFileSource(source), { name: fileName }));
120
108
 
121
109
  if (bot && groupId != null) {
122
110
  await bot.sendGroupMsg(groupId, payload);
@@ -184,11 +172,7 @@ export async function sendRecordMessage(
184
172
  const { bot, groupId, userId } = getBotAndTarget(ctx, event);
185
173
  const sendPayload = async (source: string) => {
186
174
  const payload: any[] = [];
187
- payload.push(
188
- ctx?.segment?.record
189
- ? ctx.segment.record(normalizeFileSource(source))
190
- : { type: "record", file: normalizeFileSource(source) },
191
- );
175
+ payload.push(ctx.segment.record(normalizeFileSource(source)));
192
176
 
193
177
  if (bot && groupId != null) {
194
178
  await bot.sendGroupMsg(groupId, payload);
@@ -414,19 +414,13 @@ export class MusicPluginRuntime {
414
414
  return;
415
415
  }
416
416
 
417
- const selfId = Number(event?.self_id || ctx?.self_id);
418
- if (!Number.isFinite(selfId) || selfId <= 0) {
419
- return;
420
- }
421
-
422
- const bot =
423
- typeof ctx?.pickBot === "function" ? ctx.pickBot(selfId) : undefined;
424
- if (!bot || typeof bot.api !== "function") {
425
- return;
417
+ const bot = event?.bot;
418
+ if (!bot || bot.adapter !== "onebotv11") {
419
+ return; // set_msg_emoji_like 是 onebot 专属特殊 API,icqq 不支持
426
420
  }
427
421
 
428
422
  try {
429
- await bot.api("set_msg_emoji_like", {
423
+ await bot.sendApi("set_msg_emoji_like", {
430
424
  message_id: messageId,
431
425
  emoji_id: MusicPluginRuntime.COMMAND_REACTION_FACE_ID,
432
426
  set: true,