mioku-plugin-music 3.0.2 → 3.0.3

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/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  ## 功能
4
4
 
5
- - 点歌搜索:`点歌 晴天`
5
+ - 点歌搜索:`.点歌 晴天`
6
6
  - 搜索结果截图列表
7
- - 编号听歌(语音):`听1`
8
- - 编号听歌(原曲文件,群聊也直接发文件):`原曲1`
7
+ - 编号听歌(语音):`.听1`
8
+ - 编号听歌(原曲文件,群聊也直接发文件):`.原曲1`
9
9
  - AI skills:搜索、发送歌曲
10
10
 
11
11
  ## 已适配 Provider
package/index.ts CHANGED
@@ -57,33 +57,33 @@ export default definePlugin({
57
57
  const react = (event: any) => runtime.tryReactToCommandMessage(ctx, event);
58
58
 
59
59
  ctx.command({
60
- name: "点歌",
61
- match: /^\/?点歌\s*(.+)$/,
62
60
  prefixes: false,
61
+ name: "点歌",
62
+ match: /^点歌\s*(.+)$/,
63
63
  description: "搜索歌曲/歌手/专辑,返回最多 15 条结果图片列表",
64
- usage: "/点歌 晴天",
64
+ usage: ".点歌 晴天",
65
65
  handler: async ({ event, match }) => {
66
66
  await react(event);
67
67
  await runtime.searchAndSendList(ctx, event, match![1].trim());
68
68
  },
69
69
  });
70
70
  ctx.command({
71
- name: "听",
72
- match: /^\/?听\s*(\d{1,2})$/,
73
71
  prefixes: false,
72
+ name: "听",
73
+ match: /^听\s*(\d{1,2})$/,
74
74
  description: "发送上次搜索列表中的指定歌曲语音",
75
- usage: "听1",
75
+ usage: ".听1",
76
76
  handler: async ({ event, match }) => {
77
77
  await react(event);
78
78
  await runtime.sendByIndex(ctx, event, Number(match![1]), false);
79
79
  },
80
80
  });
81
81
  ctx.command({
82
- name: "原曲",
83
- match: /^\/?原曲\s*(\d{1,2})$/,
84
82
  prefixes: false,
83
+ name: "原曲",
84
+ match: /^原曲\s*(\d{1,2})$/,
85
85
  description: "发送上次搜索列表中的指定歌曲原曲文件",
86
- usage: "原曲1",
86
+ usage: ".原曲1",
87
87
  handler: async ({ event, match }) => {
88
88
  await react(event);
89
89
  await runtime.sendByIndex(ctx, event, Number(match![1]), true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-plugin-music",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "音乐插件:点歌、搜索音乐、听歌语音发送",
5
5
  "main": "index.ts",
6
6
  "type": "module",
@@ -26,7 +26,8 @@ export async function notifyFallback(options: {
26
26
  }
27
27
 
28
28
  const text = options.ctx.text(options.event)?.trim() ?? "";
29
- if (!text.startsWith("/")) {
29
+ // 只有像命令的消息才触发 AI 兜底提示(命令支持裸写与 . 前缀)
30
+ if (!/^[./]/.test(text)) {
30
31
  return;
31
32
  }
32
33
 
@@ -22,15 +22,17 @@ function normalizeFileSource(file: string): string {
22
22
 
23
23
  function getBotAndTarget(ctx: any, event: any): {
24
24
  bot: any;
25
- groupId?: number;
26
- userId?: number;
25
+ groupId?: string;
26
+ userId?: string;
27
27
  } {
28
28
  const bot = event?.bot;
29
+ const groupId = String(event?.group_id ?? "").trim();
30
+ const userId = String(event?.user_id ?? "").trim();
29
31
 
30
32
  return {
31
33
  bot,
32
- groupId: event?.message_type === "group" ? event.group_id : undefined,
33
- userId: event?.message_type !== "group" ? event?.user_id : undefined,
34
+ groupId: event?.message_type === "group" ? groupId : undefined,
35
+ userId: event?.message_type !== "group" ? userId : undefined,
34
36
  };
35
37
  }
36
38
 
@@ -44,11 +46,11 @@ export async function sendTextMessage(
44
46
 
45
47
  payload.push(ctx.segment.text(text));
46
48
 
47
- if (bot && groupId != null) {
49
+ if (bot && groupId != null && groupId !== "") {
48
50
  await bot.sendGroupMsg(groupId, payload);
49
51
  return;
50
52
  }
51
- if (bot && userId != null) {
53
+ if (bot && userId != null && userId !== "") {
52
54
  await bot.sendPrivateMsg(userId, payload);
53
55
  return;
54
56
  }
@@ -69,11 +71,11 @@ export async function sendImageMessage(
69
71
  const payload: any[] = [];
70
72
  payload.push(ctx.segment.image(normalizeFileSource(source)));
71
73
 
72
- if (bot && groupId != null) {
74
+ if (bot && groupId != null && groupId !== "") {
73
75
  await bot.sendGroupMsg(groupId, payload);
74
76
  return;
75
77
  }
76
- if (bot && userId != null) {
78
+ if (bot && userId != null && userId !== "") {
77
79
  await bot.sendPrivateMsg(userId, payload);
78
80
  return;
79
81
  }
@@ -106,11 +108,11 @@ export async function sendFileMessage(
106
108
  const payload: any[] = [];
107
109
  payload.push(ctx.segment.file(normalizeFileSource(source), { name: fileName }));
108
110
 
109
- if (bot && groupId != null) {
111
+ if (bot && groupId != null && groupId !== "") {
110
112
  await bot.sendGroupMsg(groupId, payload);
111
113
  return;
112
114
  }
113
- if (bot && userId != null) {
115
+ if (bot && userId != null && userId !== "") {
114
116
  await bot.sendPrivateMsg(userId, payload);
115
117
  return;
116
118
  }
@@ -174,11 +176,11 @@ export async function sendRecordMessage(
174
176
  const payload: any[] = [];
175
177
  payload.push(ctx.segment.record(normalizeFileSource(source)));
176
178
 
177
- if (bot && groupId != null) {
179
+ if (bot && groupId != null && groupId !== "") {
178
180
  await bot.sendGroupMsg(groupId, payload);
179
181
  return;
180
182
  }
181
- if (bot && userId != null) {
183
+ if (bot && userId != null && userId !== "") {
182
184
  await bot.sendPrivateMsg(userId, payload);
183
185
  return;
184
186
  }
@@ -346,8 +346,8 @@ export class MusicPluginRuntime {
346
346
  return;
347
347
  }
348
348
 
349
- const messageId = Number(event?.message_id);
350
- if (!Number.isFinite(messageId) || messageId <= 0) {
349
+ const messageId = String(event?.message_id ?? "").trim();
350
+ if (!messageId) {
351
351
  return;
352
352
  }
353
353