@acedatacloud/koishi-plugin-acemusic 0.0.0-stage → 1.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/index.js +57 -0
  4. package/package.json +56 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ace Data Cloud
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/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # ACE Music for Koishi
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 在机器人私聊中查询已有 ACE Music 任务的状态,选择其中一条音轨播放。查询不会发起音乐生成。音频的实际呈现方式取决于聊天适配器是否支持 Koishi 的音频消息。
4
+
5
+ ## 安装和配置
6
+
7
+ 1. 在 Koishi 控制台插件市场搜索 `@acedatacloud/koishi-plugin-acemusic`。也可在 Koishi 项目目录执行 `npm install @acedatacloud/koishi-plugin-acemusic`。
8
+ 2. 在 [Ace Data Cloud 应用管理](https://platform.acedata.cloud/console/applications) 为拥有这些任务的应用创建独立令牌。只需允许 ACE Music 的任务查询接口。
9
+ 3. 在 Koishi 配置中添加 `@acedatacloud/acemusic` 插件,并将令牌填入其 `token` 密钥字段(不含 `Bearer `)。请在插件配置中设置令牌,勿在聊天中发送。
10
+ 4. 用 Koishi 已启用 Koishi 数据库的机器人和权限等级 3 或以上的账号私聊机器人。输入 `acemusic YOUR_TASK_ID` 查看状态及音轨清单,再输入 `acemusic YOUR_TASK_ID 1` 播放第一条。仍在处理的任务可以稍后使用相同 ID 再查。
11
+
12
+ ## English
13
+
14
+ Install `@acedatacloud/koishi-plugin-acemusic` in a Koishi 4.18 project with its database service enabled so the host can enforce user authority. Enable the plugin and set its secret `token` field to a dedicated [Ace application key](https://platform.acedata.cloud/console/applications) with access to ACE Music task lookup. Use a Koishi authority level 3 account or higher to message the bot privately:
15
+
16
+ - `acemusic YOUR_TASK_ID` lists the task state and available tracks.
17
+ - `acemusic YOUR_TASK_ID 2` sends the second available track as an audio message. The chat adapter determines playback support.
18
+
19
+ The bot uses the configured application's library. Restrict its use to administrators who should have access to those tracks. No generation command is provided. An unfinished task can be looked up again using its original ID.
20
+
21
+ [ACE Music API reference](https://docs.acedata.cloud/openapi/acemusic.json) · [Support](https://github.com/AceDataCloud/KoishiPluginAceMusic/issues)
package/index.js ADDED
@@ -0,0 +1,57 @@
1
+ const { h, Schema } = require('koishi')
2
+
3
+ exports.name = 'acemusic'
4
+ exports.inject = ['database']
5
+ exports.Config = Schema.object({
6
+ token: Schema.string().role('secret').required()
7
+ .description('ACE Music application token with task lookup access.'),
8
+ })
9
+
10
+ exports.apply = (ctx, config) => {
11
+ ctx.private().command('acemusic <taskId:string> [track:posint]', '查询 ACE Music 任务,或播放指定音轨', { authority: 3 })
12
+ .example('acemusic YOUR_TASK_ID')
13
+ .example('acemusic YOUR_TASK_ID 1')
14
+ .action(async (_, taskId, track) => {
15
+ if (!taskId) return '用法:acemusic <任务 ID> [音轨编号]'
16
+
17
+ let result
18
+ try {
19
+ const response = await fetch('https://api.acedata.cloud/acemusic/tasks', {
20
+ method: 'POST',
21
+ redirect: 'error',
22
+ signal: AbortSignal.timeout(15000),
23
+ headers: { Authorization: 'Bearer ' + config.token, 'Content-Type': 'application/json' },
24
+ body: JSON.stringify({ action: 'retrieve', id: taskId }),
25
+ })
26
+ if (!response.ok) return '查询失败(HTTP ' + response.status + ')。请检查应用权限和任务 ID。'
27
+ result = await response.json()
28
+ } catch {
29
+ return '无法连接 ACE Music 查询服务,请稍后重试。'
30
+ }
31
+
32
+ const group = result?.response
33
+ if (result?.id !== taskId || (group?.task_id != null && group.task_id !== taskId)) {
34
+ return '响应中的任务 ID 与查询不符。'
35
+ }
36
+ const state = String(group?.status || result.state || 'pending')
37
+ const tracks = []
38
+ for (const item of Array.isArray(group?.data) ? group.data : []) {
39
+ if (typeof item?.audio_url !== 'string') continue
40
+ let url
41
+ try { url = new URL(item.audio_url) } catch { continue }
42
+ if (url.protocol !== 'https:' || url.username || url.password) continue
43
+ tracks.push({ title: String(item.title || 'ACE Music'), url: url.href })
44
+ }
45
+
46
+ if (!tracks.length) return h.text('状态:' + state + '。暂无可播放音轨。')
47
+ if (track === undefined) {
48
+ const list = tracks.map((item, index) => (index + 1) + '. ' + item.title).join('\n')
49
+ return h.text('状态:' + state + '\n' + list + '\n播放:acemusic ' + taskId + ' <编号>')
50
+ }
51
+ if (!Number.isInteger(track) || track < 1 || track > tracks.length) {
52
+ return '请选择 1 至 ' + tracks.length + ' 的音轨编号。'
53
+ }
54
+ const selected = tracks[track - 1]
55
+ return [h.text(selected.title), h.audio(selected.url)]
56
+ })
57
+ }
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@acedatacloud/koishi-plugin-acemusic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Retrieve an existing ACE Music task and play a selected track in your Koishi bot's private chat.",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js",
8
+ "README.md",
9
+ "LICENSE"
10
+ ],
11
+ "license": "MIT",
12
+ "author": "Ace Data Cloud",
13
+ "contributors": [
14
+ "Ace Data Cloud Dev <dev@acedata.cloud>"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/AceDataCloud/KoishiPluginAceMusic.git"
19
+ },
20
+ "homepage": "https://github.com/AceDataCloud/KoishiPluginAceMusic#readme",
21
+ "keywords": [
22
+ "koishi",
23
+ "plugin",
24
+ "music",
25
+ "audio",
26
+ "acemusic",
27
+ "bot"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "peerDependencies": {
33
+ "koishi": "^4.18.0"
34
+ },
35
+ "devDependencies": {
36
+ "@koishijs/plugin-database-memory": "3.7.0",
37
+ "@koishijs/plugin-mock": "2.6.6",
38
+ "koishi": "4.18.11"
39
+ },
40
+ "scripts": {
41
+ "test": "node --test"
42
+ },
43
+ "koishi": {
44
+ "description": {
45
+ "zh": "在机器人私聊中查询已有 ACE Music 任务状态,并播放指定音轨。",
46
+ "en": "Check an existing ACE Music task and play one of its tracks in a private bot conversation."
47
+ },
48
+ "service": {
49
+ "required": [
50
+ "database"
51
+ ]
52
+ }
53
+ },
54
+ "publishConfig": {
55
+ "access": "public",
56
+ "registry": "https://registry.npmjs.org"
57
+ }
58
+ }