mioku-plugin-music 3.0.1 → 3.0.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/index.ts +34 -4
- package/package.json +2 -40
- package/runtime-core/service.ts +3 -66
package/index.ts
CHANGED
|
@@ -13,8 +13,6 @@ function cloneConfig<T>(value: T): T {
|
|
|
13
13
|
|
|
14
14
|
export default definePlugin({
|
|
15
15
|
name: "music",
|
|
16
|
-
version: "1.0.0",
|
|
17
|
-
description: "点歌与听歌插件",
|
|
18
16
|
async setup(ctx) {
|
|
19
17
|
const configService = getService(ctx, Services.Config);
|
|
20
18
|
const aiService = getService(ctx, Services.AI);
|
|
@@ -56,8 +54,40 @@ export default definePlugin({
|
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const react = (event: any) => runtime.tryReactToCommandMessage(ctx, event);
|
|
58
|
+
|
|
59
|
+
ctx.command({
|
|
60
|
+
name: "点歌",
|
|
61
|
+
match: /^\/?点歌\s*(.+)$/,
|
|
62
|
+
prefixes: false,
|
|
63
|
+
description: "搜索歌曲/歌手/专辑,返回最多 15 条结果图片列表",
|
|
64
|
+
usage: "/点歌 晴天",
|
|
65
|
+
handler: async ({ event, match }) => {
|
|
66
|
+
await react(event);
|
|
67
|
+
await runtime.searchAndSendList(ctx, event, match![1].trim());
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
ctx.command({
|
|
71
|
+
name: "听",
|
|
72
|
+
match: /^\/?听\s*(\d{1,2})$/,
|
|
73
|
+
prefixes: false,
|
|
74
|
+
description: "发送上次搜索列表中的指定歌曲语音",
|
|
75
|
+
usage: "听1",
|
|
76
|
+
handler: async ({ event, match }) => {
|
|
77
|
+
await react(event);
|
|
78
|
+
await runtime.sendByIndex(ctx, event, Number(match![1]), false);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
ctx.command({
|
|
82
|
+
name: "原曲",
|
|
83
|
+
match: /^\/?原曲\s*(\d{1,2})$/,
|
|
84
|
+
prefixes: false,
|
|
85
|
+
description: "发送上次搜索列表中的指定歌曲原曲文件",
|
|
86
|
+
usage: "原曲1",
|
|
87
|
+
handler: async ({ event, match }) => {
|
|
88
|
+
await react(event);
|
|
89
|
+
await runtime.sendByIndex(ctx, event, Number(match![1]), true);
|
|
90
|
+
},
|
|
61
91
|
});
|
|
62
92
|
|
|
63
93
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-music",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "音乐插件:点歌、搜索音乐、听歌语音发送",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -16,45 +16,7 @@
|
|
|
16
16
|
"config",
|
|
17
17
|
"ai",
|
|
18
18
|
"screenshot"
|
|
19
|
-
]
|
|
20
|
-
"accessHooks": [
|
|
21
|
-
{
|
|
22
|
-
"id": "点歌",
|
|
23
|
-
"match": "/^\\/?点歌\\s+/"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"id": "听",
|
|
27
|
-
"match": "/^听\\d+$/"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"id": "原曲",
|
|
31
|
-
"match": "/^原曲\\d+$/"
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"help": {
|
|
35
|
-
"title": "音乐",
|
|
36
|
-
"description": "点歌并发送语音,支持搜索结果图片列表",
|
|
37
|
-
"commands": [
|
|
38
|
-
{
|
|
39
|
-
"cmd": "点歌 <歌曲名>",
|
|
40
|
-
"desc": "搜索歌曲/歌手/专辑,返回最多 15 条结果图片列表",
|
|
41
|
-
"usage": "/点歌 晴天",
|
|
42
|
-
"role": "member"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"cmd": "听 <编号>",
|
|
46
|
-
"desc": "发送上次搜索列表中的指定歌曲语音",
|
|
47
|
-
"usage": "听1",
|
|
48
|
-
"role": "member"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"cmd": "原曲 <编号>",
|
|
52
|
-
"desc": "发送上次搜索列表中的指定歌曲原曲文件",
|
|
53
|
-
"usage": "原曲1",
|
|
54
|
-
"role": "member"
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
19
|
+
]
|
|
58
20
|
},
|
|
59
21
|
"peerDependencies": {
|
|
60
22
|
"mioku": "^1.0.0",
|
package/runtime-core/service.ts
CHANGED
|
@@ -32,39 +32,6 @@ interface MusicPluginRuntimeDeps {
|
|
|
32
32
|
neteaseService?: NeteaseServiceApi;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function parseListenIndex(text: string): number | null {
|
|
36
|
-
const match = text.match(/^\/?听\s*(\d{1,2})$/);
|
|
37
|
-
if (!match) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const idx = Number(match[1]);
|
|
41
|
-
if (!Number.isFinite(idx) || idx <= 0) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return idx;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function parseOriginalIndex(text: string): number | null {
|
|
48
|
-
const match = text.match(/^\/?原曲\s*(\d{1,2})$/);
|
|
49
|
-
if (!match) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const idx = Number(match[1]);
|
|
53
|
-
if (!Number.isFinite(idx) || idx <= 0) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
return idx;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function parseSearchKeyword(text: string): string | null {
|
|
60
|
-
const match = text.match(/^\/?点歌\s*(.+)$/);
|
|
61
|
-
if (!match) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const value = String(match[1] || "").trim();
|
|
65
|
-
return value ? value : null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
35
|
export class MusicPluginRuntime {
|
|
69
36
|
private readonly deps: MusicPluginRuntimeDeps;
|
|
70
37
|
private readonly sessions = new MusicSessionStore();
|
|
@@ -110,36 +77,6 @@ export class MusicPluginRuntime {
|
|
|
110
77
|
return this.sessions.get(event);
|
|
111
78
|
}
|
|
112
79
|
|
|
113
|
-
async handleMessage(ctx: any, event: any): Promise<boolean> {
|
|
114
|
-
const text = String(ctx.text(event) || "").trim();
|
|
115
|
-
if (!text) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const searchKeyword = parseSearchKeyword(text);
|
|
120
|
-
if (searchKeyword) {
|
|
121
|
-
await this.tryReactToCommandMessage(ctx, event);
|
|
122
|
-
await this.searchAndSendList(ctx, event, searchKeyword);
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const listenIndex = parseListenIndex(text);
|
|
127
|
-
if (listenIndex != null) {
|
|
128
|
-
await this.tryReactToCommandMessage(ctx, event);
|
|
129
|
-
await this.sendByIndex(ctx, event, listenIndex, false);
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const originalIndex = parseOriginalIndex(text);
|
|
134
|
-
if (originalIndex != null) {
|
|
135
|
-
await this.tryReactToCommandMessage(ctx, event);
|
|
136
|
-
await this.sendByIndex(ctx, event, originalIndex, true);
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
80
|
async searchSongs(event: any, query: string): Promise<MusicSearchResult> {
|
|
144
81
|
const session = this.getOrCreateSession(event);
|
|
145
82
|
const provider = await this.createProvider(
|
|
@@ -245,7 +182,7 @@ export class MusicPluginRuntime {
|
|
|
245
182
|
await this.sendSongById(ctx, event, first.id, first.title, options);
|
|
246
183
|
}
|
|
247
184
|
|
|
248
|
-
|
|
185
|
+
async searchAndSendList(
|
|
249
186
|
ctx: any,
|
|
250
187
|
event: any,
|
|
251
188
|
keyword: string,
|
|
@@ -296,7 +233,7 @@ export class MusicPluginRuntime {
|
|
|
296
233
|
}
|
|
297
234
|
}
|
|
298
235
|
|
|
299
|
-
|
|
236
|
+
async sendByIndex(
|
|
300
237
|
ctx: any,
|
|
301
238
|
event: any,
|
|
302
239
|
index: number,
|
|
@@ -404,7 +341,7 @@ export class MusicPluginRuntime {
|
|
|
404
341
|
};
|
|
405
342
|
}
|
|
406
343
|
|
|
407
|
-
|
|
344
|
+
async tryReactToCommandMessage(ctx: any, event: any): Promise<void> {
|
|
408
345
|
if (event?.message_type === "group") {
|
|
409
346
|
return;
|
|
410
347
|
}
|