koishi-plugin-iirose-cut 0.0.8 → 0.1.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/LICENSE +21 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +83 -71
- package/package.json +15 -7
- package/readme.md +1 -1
- package/src/index.ts +154 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 IIROSE-Plugins
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export declare const name = "iirose-cut";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export declare const usage = "\n---\n\nBOT\u9700\u8981\u6709\u623F\u95F4\u6210\u5458\u7684\u661F\u6807\u6743\u9650 / \u7BA1\u7406\u6743\u9650\u3002\n\n\u5982\u679C\u4F60\u7684bot\u6CA1\u6709\u6743\u9650\uFF0C\u5219\u53EF\u4EE5\u53D1\u8D77cut\u6295\u7968\uFF0C\u8BF7\u4F7F\u7528 iirose-self-cut \u63D2\u4EF6\u3002\n\n---\n\n\u4E5F\u53EF\u4EE5\u4F7F\u7528\u6307\u4EE4\u5207\u6B4C\uFF1A\n\n- iirose.media.cut \uFF1A \u7EC8\u6B62\u5F53\u524D\u6B4C\u66F2\n- iirose.media.cutall \uFF1A \u7EC8\u6B62\u6240\u6709\u6B4C\u66F2\n\n---\n\n\u672C\u63D2\u4EF6\u9700\u8981\u8C03\u7528\u8005\u9700\u8981\u81F3\u5C112\u7EA7\u6743\u9650\u3002\n\n\u5982\u679C\u4F60\u7684\u6743\u9650\u4E0D\u591F\uFF0C\u8BF7\u4F7F\u7528 change-auth-callme \u63D2\u4EF6\u6765\u63D0\u6743\u3002\n\n\u52A1\u5FC5\u4E0D\u8981\u4F7F\u75281\u7EA7\u6743\u9650\uFF0C\u5426\u5219\u53EF\u80FD\u4F1A\u5BFC\u81F4\n\n---\n";
|
|
3
5
|
export interface Config {
|
|
6
|
+
commandAuthority: number;
|
|
4
7
|
}
|
|
5
8
|
export declare const Config: Schema<Config>;
|
|
6
|
-
export declare function apply(ctx: Context): void;
|
|
9
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -22,96 +22,108 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Config: () => Config,
|
|
24
24
|
apply: () => apply,
|
|
25
|
-
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name,
|
|
27
|
+
usage: () => usage
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(src_exports);
|
|
28
30
|
var import_koishi = require("koishi");
|
|
29
31
|
var name = "iirose-cut";
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
var inject = ["database"];
|
|
33
|
+
var usage = `
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
BOT需要有房间成员的星标权限 / 管理权限。
|
|
37
|
+
|
|
38
|
+
如果你的bot没有权限,则可以发起cut投票,请使用 iirose-self-cut 插件。
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
也可以使用指令切歌:
|
|
43
|
+
|
|
44
|
+
- iirose.media.cut : 终止当前歌曲
|
|
45
|
+
- iirose.media.cutall : 终止所有歌曲
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
本插件需要调用者需要至少2级权限。
|
|
50
|
+
|
|
51
|
+
如果你的权限不够,请使用 change-auth-callme 插件来提权。
|
|
52
|
+
|
|
53
|
+
务必不要使用1级权限,否则可能会导致
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
`;
|
|
57
|
+
var Config = import_koishi.Schema.object({
|
|
58
|
+
commandAuthority: import_koishi.Schema.number().role("slider").min(0).max(5).step(1).default(2).description("指令权限等级")
|
|
59
|
+
});
|
|
60
|
+
function apply(ctx, config) {
|
|
61
|
+
ctx.command("iirose.media.cut", "终止当前歌曲", { authority: config.commandAuthority }).action(async ({ session }) => {
|
|
62
|
+
if (session.platform !== "iirose") {
|
|
63
|
+
return "暂不支持其他平台。";
|
|
43
64
|
}
|
|
44
|
-
|
|
65
|
+
await session.bot.internal.cutOne();
|
|
66
|
+
return;
|
|
45
67
|
});
|
|
46
|
-
ctx.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return;
|
|
68
|
+
ctx.command("iirose.media.cutall", "终止所有歌曲", { authority: config.commandAuthority }).action(async ({ session }) => {
|
|
69
|
+
if (session.platform !== "iirose") {
|
|
70
|
+
return "暂不支持其他平台。";
|
|
50
71
|
}
|
|
51
|
-
|
|
72
|
+
await session.bot.internal.cutAll();
|
|
73
|
+
return;
|
|
52
74
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
nowUserList.splice(index, 1);
|
|
75
|
+
const userSongs = /* @__PURE__ */ new Map();
|
|
76
|
+
const leftUsers = /* @__PURE__ */ new Set();
|
|
77
|
+
ctx.on("dispose", () => {
|
|
78
|
+
userSongs.clear();
|
|
79
|
+
leftUsers.clear();
|
|
59
80
|
});
|
|
60
|
-
ctx.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
if (v.options.hasOwnProperty("del")) {
|
|
75
|
-
const at = getAt(v.options.del);
|
|
76
|
-
const index = whiteList.indexOf(at);
|
|
77
|
-
if (index < 0) {
|
|
78
|
-
return "[IIROSE-CUT] 该用户不在白名单中";
|
|
81
|
+
ctx.platform("iirose").on("message", (session) => {
|
|
82
|
+
if (session.content.startsWith("<json")) {
|
|
83
|
+
try {
|
|
84
|
+
const jsonData = import_koishi.h.parse(session.content)[0].attrs.data;
|
|
85
|
+
if (jsonData?.type === "iirose:music" && jsonData.name && session.username) {
|
|
86
|
+
const username = session.username;
|
|
87
|
+
const songTitle = jsonData.name;
|
|
88
|
+
if (!userSongs.has(username)) {
|
|
89
|
+
userSongs.set(username, /* @__PURE__ */ new Set());
|
|
90
|
+
}
|
|
91
|
+
userSongs.get(username).add(songTitle);
|
|
92
|
+
}
|
|
93
|
+
} catch (e) {
|
|
79
94
|
}
|
|
80
|
-
whiteList.splice(index, 1);
|
|
81
95
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
});
|
|
97
|
+
ctx.platform("iirose").on("guild-member-added", (session) => {
|
|
98
|
+
if (session.username && leftUsers.has(session.username)) {
|
|
99
|
+
leftUsers.delete(session.username);
|
|
85
100
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
});
|
|
102
|
+
ctx.platform("iirose").on("guild-member-removed", (session) => {
|
|
103
|
+
if (session.username) {
|
|
104
|
+
leftUsers.add(session.username);
|
|
105
|
+
ctx.logger.info(`用户 ${session.username} 已离开,其点播的歌曲将在播放时被切掉。`);
|
|
89
106
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
});
|
|
108
|
+
ctx.platform("iirose").on("iirose/music-play", async (session, data) => {
|
|
109
|
+
if (data?.owner) {
|
|
110
|
+
if (leftUsers.has(data.owner)) {
|
|
111
|
+
try {
|
|
112
|
+
await session.bot.internal.cutOne();
|
|
113
|
+
ctx.logger.info(`检测到点播者 ${data.owner} 已离开,已切掉歌曲: ${data.title}`);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
ctx.logger.warn(`自动切歌失败: ${e}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
100
118
|
}
|
|
101
119
|
});
|
|
102
120
|
}
|
|
103
121
|
__name(apply, "apply");
|
|
104
|
-
var getAt = /* @__PURE__ */ __name((message) => {
|
|
105
|
-
const reg = /\[\*([\s\S]+)\*\]/;
|
|
106
|
-
const a = reg.test(message);
|
|
107
|
-
if (!a) {
|
|
108
|
-
return "";
|
|
109
|
-
}
|
|
110
|
-
return message.match(reg)[1];
|
|
111
|
-
}, "getAt");
|
|
112
122
|
// Annotate the CommonJS export names for ESM import in node:
|
|
113
123
|
0 && (module.exports = {
|
|
114
124
|
Config,
|
|
115
125
|
apply,
|
|
116
|
-
|
|
126
|
+
inject,
|
|
127
|
+
name,
|
|
128
|
+
usage
|
|
117
129
|
});
|
package/package.json
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-iirose-cut",
|
|
3
|
-
"description": "适用于的[IIROSE蔷薇花园](https://iirose.com/)
|
|
4
|
-
"version": "0.0
|
|
3
|
+
"description": "适用于的[IIROSE蔷薇花园](https://iirose.com/)切除退出房间的人所点的歌曲",
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"
|
|
9
|
+
"src"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/iirose-plugins/koishi-plugin-iirose-cut/issues/new/choose"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/iirose-plugins/koishi-plugin-iirose-cut.git"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/iirose-plugins/koishi-plugin-iirose-cut",
|
|
12
20
|
"keywords": [
|
|
13
21
|
"chatbot",
|
|
14
22
|
"koishi",
|
|
15
|
-
"plugin"
|
|
23
|
+
"plugin",
|
|
24
|
+
"iirose-cut"
|
|
16
25
|
],
|
|
17
26
|
"peerDependencies": {
|
|
18
|
-
"koishi": "^4.18.7"
|
|
19
|
-
"koishi-plugin-adapter-iirose": "~0.3.63"
|
|
27
|
+
"koishi": "^4.18.7"
|
|
20
28
|
}
|
|
21
|
-
}
|
|
29
|
+
}
|
package/readme.md
CHANGED
package/src/index.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Context, h, Schema, Session } from 'koishi';
|
|
2
|
+
|
|
3
|
+
export const name = 'iirose-cut';
|
|
4
|
+
|
|
5
|
+
export const inject = ['database'];
|
|
6
|
+
|
|
7
|
+
export const usage = `
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
BOT需要有房间成员的星标权限 / 管理权限。
|
|
11
|
+
|
|
12
|
+
如果你的bot没有权限,则可以发起cut投票,请使用 iirose-self-cut 插件。
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
也可以使用指令切歌:
|
|
17
|
+
|
|
18
|
+
- iirose.media.cut : 终止当前歌曲
|
|
19
|
+
- iirose.media.cutall : 终止所有歌曲
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
本插件需要调用者需要至少2级权限。
|
|
24
|
+
|
|
25
|
+
如果你的权限不够,请使用 change-auth-callme 插件来提权。
|
|
26
|
+
|
|
27
|
+
务必不要使用1级权限,否则可能会导致
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
export interface Config
|
|
33
|
+
{
|
|
34
|
+
commandAuthority: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const Config: Schema<Config> = Schema.object({
|
|
38
|
+
commandAuthority: Schema.number().role('slider').min(0).max(5).step(1).default(2).description("指令权限等级"),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export function apply(ctx: Context, config: Config)
|
|
42
|
+
{
|
|
43
|
+
ctx
|
|
44
|
+
.command('iirose.media.cut', '终止当前歌曲', { authority: config.commandAuthority })
|
|
45
|
+
.action(async ({ session }) =>
|
|
46
|
+
{
|
|
47
|
+
if (session.platform !== "iirose")
|
|
48
|
+
{
|
|
49
|
+
return "暂不支持其他平台。";
|
|
50
|
+
}
|
|
51
|
+
await session.bot.internal.cutOne();
|
|
52
|
+
return;
|
|
53
|
+
});
|
|
54
|
+
ctx
|
|
55
|
+
.command('iirose.media.cutall', '终止所有歌曲', { authority: config.commandAuthority })
|
|
56
|
+
.action(async ({ session }) =>
|
|
57
|
+
{
|
|
58
|
+
if (session.platform !== "iirose")
|
|
59
|
+
{
|
|
60
|
+
return "暂不支持其他平台。";
|
|
61
|
+
}
|
|
62
|
+
await session.bot.internal.cutAll();
|
|
63
|
+
return;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 用于存储用户和他们点播的歌曲,主要用于调试和记录
|
|
67
|
+
const userSongs = new Map<string, Set<string>>(); // username -> Set<songTitle>
|
|
68
|
+
// 用于存储已离开房间的用户
|
|
69
|
+
const leftUsers = new Set<string>(); // Set<username>
|
|
70
|
+
|
|
71
|
+
// 插件卸载时清空数据
|
|
72
|
+
ctx.on('dispose', () =>
|
|
73
|
+
{
|
|
74
|
+
userSongs.clear();
|
|
75
|
+
leftUsers.clear();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
ctx.platform("iirose")
|
|
79
|
+
.on('message', (session: Session) =>
|
|
80
|
+
{
|
|
81
|
+
// 监听消息,解析点歌信息
|
|
82
|
+
if (session.content.startsWith("<json"))
|
|
83
|
+
{
|
|
84
|
+
try
|
|
85
|
+
{
|
|
86
|
+
const jsonData = h.parse(session.content)[0].attrs.data;
|
|
87
|
+
// 确认是音乐点播消息
|
|
88
|
+
if (jsonData?.type === 'iirose:music' && jsonData.name && session.username)
|
|
89
|
+
{
|
|
90
|
+
const username = session.username;
|
|
91
|
+
const songTitle = jsonData.name;
|
|
92
|
+
|
|
93
|
+
// 记录用户点播的歌曲
|
|
94
|
+
if (!userSongs.has(username))
|
|
95
|
+
{
|
|
96
|
+
userSongs.set(username, new Set<string>());
|
|
97
|
+
}
|
|
98
|
+
userSongs.get(username).add(songTitle);
|
|
99
|
+
// ctx.logger.info(`记录到用户 ${username} 点播了歌曲: ${songTitle}`);
|
|
100
|
+
}
|
|
101
|
+
} catch (e)
|
|
102
|
+
{
|
|
103
|
+
// JSON解析失败或格式不符,不是点歌消息,忽略
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// 监听用户加入房间事件
|
|
109
|
+
ctx.platform("iirose")
|
|
110
|
+
.on('guild-member-added', (session: Session) =>
|
|
111
|
+
{
|
|
112
|
+
// 如果用户重新加入房间,则从“已离开”列表中移除
|
|
113
|
+
if (session.username && leftUsers.has(session.username))
|
|
114
|
+
{
|
|
115
|
+
leftUsers.delete(session.username);
|
|
116
|
+
// ctx.logger.info(`用户 ${session.username} 已重新加入房间。`);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
ctx.platform("iirose")
|
|
122
|
+
.on('guild-member-removed', (session: Session) =>
|
|
123
|
+
{
|
|
124
|
+
// 记录离开房间的用户
|
|
125
|
+
if (session.username)
|
|
126
|
+
{
|
|
127
|
+
leftUsers.add(session.username);
|
|
128
|
+
ctx.logger.info(`用户 ${session.username} 已离开,其点播的歌曲将在播放时被切掉。`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
ctx.platform("iirose")
|
|
133
|
+
.on('iirose/music-play' as any, async (session: Session, data) =>
|
|
134
|
+
{
|
|
135
|
+
// 检查点播这首歌曲的用户是否已经离开
|
|
136
|
+
if (data?.owner)
|
|
137
|
+
{
|
|
138
|
+
// ctx.logger.info(`正在播放歌曲: ${data.title}, 点播者: ${data.owner}`);
|
|
139
|
+
// 如果点歌者在已离开用户列表中
|
|
140
|
+
if (leftUsers.has(data.owner))
|
|
141
|
+
{
|
|
142
|
+
try
|
|
143
|
+
{
|
|
144
|
+
// 则切掉当前歌曲
|
|
145
|
+
await session.bot.internal.cutOne();
|
|
146
|
+
ctx.logger.info(`检测到点播者 ${data.owner} 已离开,已切掉歌曲: ${data.title}`);
|
|
147
|
+
} catch (e)
|
|
148
|
+
{
|
|
149
|
+
ctx.logger.warn(`自动切歌失败: ${e}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|