nonebot-plugin-acemusic 0.1.1__py3-none-any.whl

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.
@@ -0,0 +1,70 @@
1
+ import hashlib
2
+
3
+ import httpx
4
+ from nonebot import get_plugin_config, on_command
5
+ from nonebot.adapters.onebot.v11 import Message, PrivateMessageEvent
6
+ from nonebot.params import CommandArg
7
+ from nonebot.permission import SUPERUSER
8
+ from nonebot.plugin import PluginMetadata
9
+ from pydantic import BaseModel, SecretStr
10
+
11
+ from .client import create_song, read_song
12
+
13
+
14
+ class Config(BaseModel):
15
+ acemusic_api_token: SecretStr | None = None
16
+
17
+
18
+ __plugin_meta__ = PluginMetadata(
19
+ name="ACE Music 音乐助手", description="管理员私聊生成音乐并查询原任务",
20
+ usage="/创作音乐 提示词(消耗 Credits);/音乐任务 原任务ID(查询)",
21
+ type="application", homepage="https://github.com/AceDataCloud/NoneBotPluginAceMusic",
22
+ config=Config, supported_adapters={"~onebot.v11"},
23
+ )
24
+
25
+
26
+ async def private_chat(event: PrivateMessageEvent) -> bool:
27
+ return True
28
+
29
+
30
+ generate = on_command("创作音乐", rule=private_chat, permission=SUPERUSER, block=True)
31
+ lookup = on_command("音乐任务", rule=private_chat, permission=SUPERUSER, block=True)
32
+
33
+
34
+ def token_value() -> str:
35
+ value = get_plugin_config(Config).acemusic_api_token
36
+ return value.get_secret_value().strip() if value else ""
37
+
38
+
39
+ @generate.handle()
40
+ async def submit(event: PrivateMessageEvent, args: Message = CommandArg()):
41
+ token = token_value()
42
+ prompt = args.extract_plain_text().strip()
43
+ if not token or not prompt:
44
+ await generate.finish("请配置 ACEMUSIC_API_TOKEN,再发送 /创作音乐 提示词。提交将使用应用的 Credits。")
45
+ event_key = f"nonebot-v11:{event.self_id}:{event.user_id}:{event.message_id}:{event.time}"
46
+ key = hashlib.sha256(event_key.encode()).hexdigest()
47
+ try:
48
+ async with httpx.AsyncClient(timeout=45) as client:
49
+ task_id = await create_song(client, token, prompt, key)
50
+ except httpx.HTTPStatusError as exc:
51
+ await generate.finish(f"提交返回 HTTP {exc.response.status_code}。请先核对 Ace 任务历史,再决定是否重试。")
52
+ except (httpx.RequestError, ValueError):
53
+ await generate.finish("未确认提交结果,请先到 Ace 控制台查看任务历史,避免重复生成。")
54
+ await generate.finish(f"已受理。查询命令:/音乐任务 {task_id}")
55
+
56
+
57
+ @lookup.handle()
58
+ async def retrieve(args: Message = CommandArg()):
59
+ token = token_value()
60
+ task_id = args.extract_plain_text().strip()
61
+ if not token or not task_id:
62
+ await lookup.finish("请配置 ACEMUSIC_API_TOKEN,再发送 /音乐任务 原任务ID。")
63
+ try:
64
+ async with httpx.AsyncClient(timeout=30) as client:
65
+ text = await read_song(client, token, task_id)
66
+ except httpx.HTTPStatusError as exc:
67
+ await lookup.finish(f"查询返回 HTTP {exc.response.status_code},请核对应用权限和任务 ID。")
68
+ except (httpx.RequestError, ValueError):
69
+ await lookup.finish("暂时无法确认结果,请稍后使用同一任务 ID 查询。")
70
+ await lookup.finish(text)
@@ -0,0 +1,36 @@
1
+ import httpx
2
+
3
+
4
+ async def request(client: httpx.AsyncClient, token: str, resource: str, payload: dict, *, key: str | None = None) -> dict:
5
+ headers = {"Authorization": "Bearer " + token}
6
+ if key is not None:
7
+ headers["Idempotency-Key"] = key
8
+ response = await client.post("https://api.acedata.cloud/acemusic/" + resource,
9
+ headers=headers, json=payload)
10
+ response.raise_for_status()
11
+ result = response.json()
12
+ if not isinstance(result, dict):
13
+ raise ValueError("Invalid response")
14
+ return result
15
+
16
+
17
+ async def create_song(client: httpx.AsyncClient, token: str, prompt: str, key: str) -> str:
18
+ result = await request(client, token, "audios", {"action": "generate", "custom": False,
19
+ "async": True, "model": "acemusic-v1.1", "prompt": prompt}, key=key)
20
+ task_id = result.get("task_id")
21
+ if result.get("success") is False or not isinstance(task_id, str) or not task_id:
22
+ raise ValueError("No confirmed task ID")
23
+ return task_id
24
+
25
+
26
+ async def read_song(client: httpx.AsyncClient, token: str, task_id: str) -> str:
27
+ result = await request(client, token, "tasks", {"action": "retrieve", "id": task_id})
28
+ inner = result.get("response") or {}
29
+ if result.get("id") != task_id or not isinstance(inner, dict) or inner.get("task_id") not in (None, task_id):
30
+ raise ValueError("Task identity mismatch")
31
+ state = inner.get("status") or result.get("state") or result.get("status") or "pending"
32
+ lines = [f"任务 {task_id} · {state}"]
33
+ for row in inner.get("data") or []:
34
+ if isinstance(row, dict) and isinstance(row.get("audio_url"), str) and row["audio_url"].startswith("https://"):
35
+ lines.append(f'{row.get("title") or "音轨"}:{row["audio_url"]}')
36
+ return "\n".join(lines)
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.5
2
+ Name: nonebot-plugin-acemusic
3
+ Version: 0.1.1
4
+ Summary: 在 NoneBot 2 的 OneBot V11 私聊中提交 ACE Music 音乐任务并查询结果
5
+ Project-URL: Homepage, https://github.com/AceDataCloud/NoneBotPluginAceMusic
6
+ Project-URL: Issues, https://github.com/AceDataCloud/NoneBotPluginAceMusic/issues
7
+ Author-email: Ace Data Cloud Dev <dev@acedata.cloud>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: httpx<1,>=0.25
12
+ Requires-Dist: nonebot-adapter-onebot<3,>=2.4
13
+ Requires-Dist: nonebot2<3,>=2.3
14
+ Description-Content-Type: text/markdown
15
+
16
+ # NoneBot ACE Music 音乐助手
17
+
18
+ 在 NoneBot 2 的 OneBot V11 私聊中生成歌曲,或查询已提交任务的音频。安装插件后无需密钥即可加载。命令仅向 NoneBot 的超级用户开放,因为机器人使用同一应用的额度和私有任务历史。
19
+
20
+ ```sh
21
+ nb plugin install nonebot-plugin-acemusic
22
+ ```
23
+
24
+ 在 [Ace 应用](https://platform.acedata.cloud/console/applications) 中开通 ACE Music,把令牌配置为机器人环境变量 `ACEMUSIC_API_TOKEN`。在 NoneBot 的 `SUPERUSERS` 中指定获准使用的账号,启用 OneBot V11 适配器,再启动机器人。请勿在聊天中发送令牌。
25
+
26
+ - `/创作音乐 黄昏时的轻快爵士配乐`:提交一次计费生成并返回任务 ID。相同消息投递使用相同幂等键。请求超时后先检查 Ace 控制台的历史。
27
+ - `/音乐任务 <原任务ID>`:查询状态和已交付的音频链接。可重复查询,部分失败时保留仍可用的音轨。
28
+
29
+ [ACE Music 服务](https://platform.acedata.cloud/services/024e09b4-52cf-5e98-a91a-efedf43104c4) · [支持](https://github.com/AceDataCloud/NoneBotPluginAceMusic/issues)
@@ -0,0 +1,6 @@
1
+ nonebot_plugin_acemusic/__init__.py,sha256=eQJN7h5fTYMQmU0jPJpEWUcc8NAmQuvP5xQ9TFdXyeU,3003
2
+ nonebot_plugin_acemusic/client.py,sha256=QbgbkEOPx_bdwb6vCgayk9_CUqvbotFcZ86EqeO84mQ,1819
3
+ nonebot_plugin_acemusic-0.1.1.dist-info/METADATA,sha256=gBxlpy4fbzE0dQkSkJWg7j2u0XJQE534Mp1AOHC8V-E,1722
4
+ nonebot_plugin_acemusic-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ nonebot_plugin_acemusic-0.1.1.dist-info/licenses/LICENSE,sha256=ctMHMNBo4Ge-WIeJWbrCRQ9aBfKy48NlzcE6AYFjXDw,1071
6
+ nonebot_plugin_acemusic-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -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.