qq-bot-roost 1.0.16 → 1.1.1
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 +2 -2
- package/docs//345/256/230/346/226/271/346/216/245/345/217/243/351/231/220/345/210/266.md +5 -1
- package/docs//345/256/277/344/270/273/345/215/217/350/256/256v1.md +31 -7
- package/docs//345/274/200/346/224/276/345/271/263/345/217/260/346/216/245/345/217/243.md +283 -0
- package/docs//346/217/222/344/273/266/345/215/217/350/256/256.md +17 -1
- package/docs//351/205/215/347/275/256/345/217/202/350/200/203.md +44 -1
- package/package.json +58 -58
- package/sdk/node/roost.mjs +3 -0
- package/sdk/python/roost_sdk.py +5 -0
- package/src/api.js +345 -3
- package/src/bot.js +63 -0
- package/src/config.js +13 -0
- package/src/dev/browser.js +1030 -0
- package/src/dev/errors.js +167 -0
- package/src/dev/platform.js +1392 -0
- package/src/dev/session.js +442 -0
- package/src/dev/url-guard.js +209 -0
- package/src/endpoints.js +71 -0
- package/src/ext-deps.js +107 -8
- package/src/gateway.js +27 -0
- package/src/host/dev.js +121 -0
- package/src/host/dispatch.js +19 -3
- package/src/host/media.js +18 -1
- package/src/host/methods.js +1071 -970
- package/src/host/ops.js +11 -3
- package/src/host/serialize.js +7 -0
- package/src/ledger.js +13 -4
- package/src/main.js +28 -1
- package/src/message-bus.js +3 -0
- package/src/message.js +57 -5
- package/src/mirror.js +9 -0
- package/src/npm-registry.js +211 -0
- package/src/onebot/actions.js +133 -0
- package/src/onebot/capability.js +5 -0
- package/src/outbound.js +30 -6
- package/src/plugin/context.js +15 -0
- package/src/plugin/deps.js +90 -3
- package/src/plugin/protocol.js +6 -0
- package/src/plugin/subprocess.js +22 -3
- package/src/services/dev-ticket.js +84 -0
- package/src/services/index.js +21 -0
- package/src/services/nickname.js +91 -0
- package/src/web/server.js +352 -6
- package/web/app.js +2294 -27
- package/web/index.html +277 -7
- package/web/style.css +503 -22
- package/web/theme-boot.js +2 -0
package/src/api.js
CHANGED
|
@@ -324,7 +324,7 @@ export class QQApi {
|
|
|
324
324
|
this._mediaReclaimDone = false;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
async #request(method, path, body, { retried = false, headers } = {}) {
|
|
327
|
+
async #request(method, path, body, { retried = false, headers, multipart = false } = {}) {
|
|
328
328
|
const token = await this.tokens.get();
|
|
329
329
|
let res;
|
|
330
330
|
try {
|
|
@@ -334,11 +334,18 @@ export class QQApi {
|
|
|
334
334
|
signal: AbortSignal.timeout(15000),
|
|
335
335
|
headers: {
|
|
336
336
|
Authorization: `QQBot ${token}`,
|
|
337
|
-
'Content-Type': 'application/json',
|
|
338
337
|
'X-Union-Appid': this.tokens.appId,
|
|
338
|
+
/**
|
|
339
|
+
* multipart 时**不能**手写 Content-Type:fetch 要自己带 boundary。
|
|
340
|
+
* 官方 send.html 明确频道发本地图片走 multipart/form-data,
|
|
341
|
+
* 且对象/数组字段要序列化成 JSON 字符串(见 #formDataOf)。
|
|
342
|
+
*/
|
|
343
|
+
...(multipart ? {} : { 'Content-Type': 'application/json' }),
|
|
339
344
|
...(headers ?? {}),
|
|
340
345
|
},
|
|
341
|
-
body:
|
|
346
|
+
body: multipart
|
|
347
|
+
? this.#formDataOf(body)
|
|
348
|
+
: (body === undefined ? undefined : JSON.stringify(body)),
|
|
342
349
|
});
|
|
343
350
|
} catch (e) {
|
|
344
351
|
this.metrics?.bump('errors');
|
|
@@ -1729,6 +1736,341 @@ export class QQApi {
|
|
|
1729
1736
|
return this.#request('DELETE', `/channels/${enc(channelId)}`);
|
|
1730
1737
|
}
|
|
1731
1738
|
|
|
1739
|
+
/* ---------------- 频道消息 / 私信 ---------------- */
|
|
1740
|
+
|
|
1741
|
+
/**
|
|
1742
|
+
* 频道这套接口(`server-inter/channel/message/`)用 **snake_case**,
|
|
1743
|
+
* 和 v2 群/单聊的 camelCase 是两套字段(对照官方 botpy 的
|
|
1744
|
+
* `post_message` / `post_dms`:`msg_id`、`event_id`、`message_reference` 原样进 body)。
|
|
1745
|
+
*
|
|
1746
|
+
* 框架内部一律 camelCase,所以这里做一次转换;同时只放行官方列出的字段,
|
|
1747
|
+
* 把 v2 专用的 `msgType` / `msgSeq` / `media` / `isWakeup` 丢掉,
|
|
1748
|
+
* 免得它们被当成未知参数带到频道接口上。
|
|
1749
|
+
*/
|
|
1750
|
+
/**
|
|
1751
|
+
* `file_image` 只接受**内存字节**,绝不接受路径字符串。
|
|
1752
|
+
*
|
|
1753
|
+
* `qq.call` 的参数是外部输入,一旦允许传路径就等于把框架本机的任意文件
|
|
1754
|
+
* 读出来发给平台。要发本地文件,由调用方(`message.js` / `host/media.js`)
|
|
1755
|
+
* 在做过路径白名单校验之后读成 Buffer 再传进来。
|
|
1756
|
+
*/
|
|
1757
|
+
#filePart(v) {
|
|
1758
|
+
if (typeof Blob !== 'undefined' && v instanceof Blob) return v;
|
|
1759
|
+
if (v instanceof Uint8Array || Buffer.isBuffer(v)) return v;
|
|
1760
|
+
if (v && typeof v === 'object' && v.data) {
|
|
1761
|
+
const d = v.data;
|
|
1762
|
+
if (d instanceof Uint8Array || Buffer.isBuffer(d)) return d;
|
|
1763
|
+
if (typeof Blob !== 'undefined' && d instanceof Blob) return d;
|
|
1764
|
+
}
|
|
1765
|
+
return null;
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
/**
|
|
1769
|
+
* `send.html`:`multipart/form-data` 下对象/数组字段要序列化成 JSON 字符串,
|
|
1770
|
+
* `file_image` 是文件字段。Node 22 自带 FormData / Blob,不引入依赖。
|
|
1771
|
+
*/
|
|
1772
|
+
#formDataOf(body) {
|
|
1773
|
+
const fd = new FormData();
|
|
1774
|
+
for (const [k, v] of Object.entries(body ?? {})) {
|
|
1775
|
+
if (v === undefined || v === null || v === '') continue;
|
|
1776
|
+
if (k === 'file_image') {
|
|
1777
|
+
const part = v instanceof Blob ? v : new Blob([v], { type: 'image/png' });
|
|
1778
|
+
fd.append('file_image', part, 'image.png');
|
|
1779
|
+
} else if (typeof v === 'object') {
|
|
1780
|
+
fd.append(k, JSON.stringify(v));
|
|
1781
|
+
} else {
|
|
1782
|
+
fd.append(k, String(v));
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
return fd;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
#channelBody(opts = {}) {
|
|
1789
|
+
const renamed = {
|
|
1790
|
+
msgId: 'msg_id',
|
|
1791
|
+
eventId: 'event_id',
|
|
1792
|
+
messageReference: 'message_reference',
|
|
1793
|
+
};
|
|
1794
|
+
const keep = new Set(['content', 'embed', 'ark', 'image', 'markdown', 'keyboard']);
|
|
1795
|
+
const out = {};
|
|
1796
|
+
let multipart = false;
|
|
1797
|
+
for (const [k, v] of Object.entries(opts ?? {})) {
|
|
1798
|
+
if (v === undefined || v === null || v === '') continue;
|
|
1799
|
+
if (k === 'fileImage') {
|
|
1800
|
+
const bytes = this.#filePart(v);
|
|
1801
|
+
if (!bytes) throw new Error('fileImage 只接受 Blob / Buffer / Uint8Array(不接受路径字符串)');
|
|
1802
|
+
out.file_image = bytes;
|
|
1803
|
+
multipart = true;
|
|
1804
|
+
} else if (renamed[k]) out[renamed[k]] = v;
|
|
1805
|
+
else if (keep.has(k)) out[k] = v;
|
|
1806
|
+
}
|
|
1807
|
+
return { body: out, multipart };
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
/** 发子频道消息。`POST /channels/{channel_id}/messages`(带 fileImage 自动走 multipart) */
|
|
1811
|
+
async sendChannelMessage(channelId, opts = {}) {
|
|
1812
|
+
const { body, multipart } = this.#channelBody(opts);
|
|
1813
|
+
return this.#request('POST', `/channels/${enc(channelId)}/messages`, body, { multipart });
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
/** 撤回子频道消息。`DELETE /channels/{channel_id}/messages/{message_id}` */
|
|
1817
|
+
retractChannelMessage(channelId, messageId, { hidetip = false } = {}) {
|
|
1818
|
+
const q = hidetip ? '?hidetip=true' : '';
|
|
1819
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/messages/${enc(messageId)}${q}`);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
/* ---------------- 频道·表情表态(仅频道内可用) ---------------- */
|
|
1823
|
+
|
|
1824
|
+
/** 机器人发表表情表态。`PUT /channels/{id}/messages/{mid}/reactions/{type}/{id}` */
|
|
1825
|
+
putReaction(channelId, messageId, type, emojiId) {
|
|
1826
|
+
return this.#request(
|
|
1827
|
+
'PUT',
|
|
1828
|
+
`/channels/${enc(channelId)}/messages/${enc(messageId)}/reactions/${enc(type)}/${enc(emojiId)}`,
|
|
1829
|
+
{},
|
|
1830
|
+
);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
/** 删除机器人自己发的表情表态。同上路径,`DELETE` */
|
|
1834
|
+
deleteReaction(channelId, messageId, type, emojiId) {
|
|
1835
|
+
return this.#request(
|
|
1836
|
+
'DELETE',
|
|
1837
|
+
`/channels/${enc(channelId)}/messages/${enc(messageId)}/reactions/${enc(type)}/${enc(emojiId)}`,
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
/** 表情表态的用户列表。`GET .../reactions/{type}/{id}?cookie=&limit=` */
|
|
1842
|
+
getReactionUsers(channelId, messageId, type, emojiId, { cookie = '', limit = 20 } = {}) {
|
|
1843
|
+
const qs = new URLSearchParams({
|
|
1844
|
+
...(cookie ? { cookie: String(cookie) } : {}),
|
|
1845
|
+
limit: String(limit),
|
|
1846
|
+
});
|
|
1847
|
+
return this.#request(
|
|
1848
|
+
'GET',
|
|
1849
|
+
`/channels/${enc(channelId)}/messages/${enc(messageId)}/reactions/${enc(type)}/${enc(emojiId)}?${qs}`,
|
|
1850
|
+
);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* 建私信会话。`POST /users/@me/dms`
|
|
1855
|
+
* 要求机器人与目标用户有共同频道;返回的 `guild_id` 才是私信会话 id,
|
|
1856
|
+
* 别和真正的频道 id 混(官方 botpy `create_dms` 同样做 user_id→recipient_id 映射)。
|
|
1857
|
+
*/
|
|
1858
|
+
createDms({ recipientId, sourceGuildId, recipient_id, source_guild_id } = {}) {
|
|
1859
|
+
const body = {
|
|
1860
|
+
recipient_id: String(recipientId ?? recipient_id ?? ''),
|
|
1861
|
+
source_guild_id: String(sourceGuildId ?? source_guild_id ?? ''),
|
|
1862
|
+
};
|
|
1863
|
+
return this.#request('POST', '/users/@me/dms', body);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
/** 发私信。`POST /dms/{guild_id}/messages`,参数与发子频道消息一致 */
|
|
1867
|
+
async sendDmMessage(guildId, opts = {}) {
|
|
1868
|
+
const { body, multipart } = this.#channelBody(opts);
|
|
1869
|
+
return this.#request('POST', `/dms/${enc(guildId)}/messages`, body, { multipart });
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
/** 撤回私信。`DELETE /dms/{guild_id}/messages/{message_id}` */
|
|
1873
|
+
retractDmMessage(guildId, messageId, { hidetip = false } = {}) {
|
|
1874
|
+
const q = hidetip ? '?hidetip=true' : '';
|
|
1875
|
+
return this.#request('DELETE', `/dms/${enc(guildId)}/messages/${enc(messageId)}${q}`);
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
/* ---------------- 频道·公告 ---------------- */
|
|
1879
|
+
|
|
1880
|
+
/** 创建频道公告。`POST /guilds/{guild_id}/announces` */
|
|
1881
|
+
postGuildAnnounces(guildId, body = {}) {
|
|
1882
|
+
return this.#request('POST', `/guilds/${enc(guildId)}/announces`, body);
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/** 删除频道公告。`DELETE /guilds/{guild_id}/announces/{message_id}`;`message_id=all` 删全部推荐子频道 */
|
|
1886
|
+
deleteGuildAnnounces(guildId, messageId) {
|
|
1887
|
+
return this.#request('DELETE', `/guilds/${enc(guildId)}/announces/${enc(messageId)}`);
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
/** 创建子频道公告。`POST /channels/{channel_id}/announces` */
|
|
1891
|
+
postChannelAnnounces(channelId, body = {}) {
|
|
1892
|
+
return this.#request('POST', `/channels/${enc(channelId)}/announces`, body);
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
/** 删除子频道公告。`DELETE /channels/{channel_id}/announces/{message_id}` */
|
|
1896
|
+
deleteChannelAnnounces(channelId, messageId) {
|
|
1897
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/announces/${enc(messageId)}`);
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
/* ---------------- 频道·论坛 ---------------- */
|
|
1901
|
+
|
|
1902
|
+
/** 帖子列表。`GET /channels/{channel_id}/threads` */
|
|
1903
|
+
getThreadsList(channelId) {
|
|
1904
|
+
return this.#request('GET', `/channels/${enc(channelId)}/threads`);
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
/** 帖子详情。`GET /channels/{channel_id}/threads/{thread_id}` */
|
|
1908
|
+
getThread(channelId, threadId) {
|
|
1909
|
+
return this.#request('GET', `/channels/${enc(channelId)}/threads/${enc(threadId)}`);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
/** 发表帖子。`PUT /channels/{channel_id}/threads`;format:1 文本 / 2 HTML / 3 Markdown / 4 JSON */
|
|
1913
|
+
putThread(channelId, body = {}) {
|
|
1914
|
+
return this.#request('PUT', `/channels/${enc(channelId)}/threads`, body);
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
/** 删除帖子。`DELETE /channels/{channel_id}/threads/{thread_id}` */
|
|
1918
|
+
deleteThread(channelId, threadId) {
|
|
1919
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/threads/${enc(threadId)}`);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
/* ---------------- 频道·精华消息 ---------------- */
|
|
1923
|
+
|
|
1924
|
+
/** 精华消息列表。`GET /channels/{channel_id}/pins` */
|
|
1925
|
+
getPinsMessage(channelId) {
|
|
1926
|
+
return this.#request('GET', `/channels/${enc(channelId)}/pins`);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/** 添加精华消息。`PUT /channels/{channel_id}/pins/{message_id}` */
|
|
1930
|
+
putPinsMessage(channelId, messageId) {
|
|
1931
|
+
return this.#request('PUT', `/channels/${enc(channelId)}/pins/${enc(messageId)}`);
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
/** 删除精华消息。`DELETE /channels/{channel_id}/pins/{message_id}` */
|
|
1935
|
+
deletePinsMessage(channelId, messageId) {
|
|
1936
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/pins/${enc(messageId)}`);
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
/* ---------------- 频道·日程 ---------------- */
|
|
1940
|
+
|
|
1941
|
+
/** 日程列表。`GET /channels/{channel_id}/schedules?since=` */
|
|
1942
|
+
getSchedules(channelId, { since = '' } = {}) {
|
|
1943
|
+
const qs = since === '' ? '' : `?${new URLSearchParams({ since: String(since) })}`;
|
|
1944
|
+
return this.#request('GET', `/channels/${enc(channelId)}/schedules${qs}`);
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/** 日程详情。`GET /channels/{channel_id}/schedules/{schedule_id}` */
|
|
1948
|
+
getSchedule(channelId, scheduleId) {
|
|
1949
|
+
return this.#request('GET', `/channels/${enc(channelId)}/schedules/${enc(scheduleId)}`);
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
/** 创建日程。`POST /channels/{channel_id}/schedules` */
|
|
1953
|
+
postSchedule(channelId, body = {}) {
|
|
1954
|
+
return this.#request('POST', `/channels/${enc(channelId)}/schedules`, body);
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
/** 修改日程。`PATCH /channels/{channel_id}/schedules/{schedule_id}` */
|
|
1958
|
+
patchSchedule(channelId, scheduleId, body = {}) {
|
|
1959
|
+
return this.#request('PATCH', `/channels/${enc(channelId)}/schedules/${enc(scheduleId)}`, body);
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
/** 删除日程。`DELETE /channels/{channel_id}/schedules/{schedule_id}` */
|
|
1963
|
+
deleteSchedule(channelId, scheduleId) {
|
|
1964
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/schedules/${enc(scheduleId)}`);
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
/* ---------------- 频道·身份组 ---------------- */
|
|
1968
|
+
|
|
1969
|
+
/** 身份组列表。`GET /guilds/{guild_id}/roles` */
|
|
1970
|
+
getGuildRoles(guildId) {
|
|
1971
|
+
return this.#request('GET', `/guilds/${enc(guildId)}/roles`);
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
/** 创建身份组。`POST /guilds/{guild_id}/roles` */
|
|
1975
|
+
postGuildRole(guildId, body = {}) {
|
|
1976
|
+
return this.#request('POST', `/guilds/${enc(guildId)}/roles`, body);
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
/** 修改身份组。`PATCH /guilds/{guild_id}/roles/{role_id}` */
|
|
1980
|
+
patchGuildRole(guildId, roleId, body = {}) {
|
|
1981
|
+
return this.#request('PATCH', `/guilds/${enc(guildId)}/roles/${enc(roleId)}`, body);
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
/** 删除身份组。`DELETE /guilds/{guild_id}/roles/{role_id}` */
|
|
1985
|
+
deleteGuildRole(guildId, roleId) {
|
|
1986
|
+
return this.#request('DELETE', `/guilds/${enc(guildId)}/roles/${enc(roleId)}`);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
/** 给成员加身份组。`PUT /guilds/{guild_id}/members/{user_id}/roles/{role_id}` */
|
|
1990
|
+
putGuildMemberRole(guildId, userId, roleId, body = {}) {
|
|
1991
|
+
return this.#request('PUT', `/guilds/${enc(guildId)}/members/${enc(userId)}/roles/${enc(roleId)}`, body);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
/** 移除成员身份组。`DELETE /guilds/{guild_id}/members/{user_id}/roles/{role_id}` */
|
|
1995
|
+
deleteGuildMemberRole(guildId, userId, roleId) {
|
|
1996
|
+
return this.#request('DELETE', `/guilds/${enc(guildId)}/members/${enc(userId)}/roles/${enc(roleId)}`);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/** 身份组成员列表。`GET /guilds/{guild_id}/roles/{role_id}/members` */
|
|
2000
|
+
getRoleMembers(guildId, roleId, { startIndex = '0', limit = 1 } = {}) {
|
|
2001
|
+
const qs = new URLSearchParams({ start_index: String(startIndex), limit: String(limit) });
|
|
2002
|
+
return this.#request('GET', `/guilds/${enc(guildId)}/roles/${enc(roleId)}/members?${qs}`);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
/* ---------------- 频道·子频道权限 ---------------- */
|
|
2006
|
+
|
|
2007
|
+
/** 子频道权限。`GET /channels/{channel_id}/permissions` */
|
|
2008
|
+
getChannelPermissions(channelId) {
|
|
2009
|
+
return this.#request('GET', `/channels/${enc(channelId)}/permissions`);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
/** 修改子频道权限。`PUT /channels/{channel_id}/permissions` */
|
|
2013
|
+
putChannelPermissions(channelId, body = {}) {
|
|
2014
|
+
return this.#request('PUT', `/channels/${enc(channelId)}/permissions`, body);
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
/** 身份组在子频道的权限。`GET /channels/{channel_id}/roles/{role_id}/permissions` */
|
|
2018
|
+
getChannelRolesPermissions(channelId, roleId) {
|
|
2019
|
+
return this.#request('GET', `/channels/${enc(channelId)}/roles/${enc(roleId)}/permissions`);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
/** 修改身份组在子频道的权限。`PUT /channels/{channel_id}/roles/{role_id}/permissions` */
|
|
2023
|
+
putChannelRolesPermissions(channelId, roleId, body = {}) {
|
|
2024
|
+
return this.#request('PUT', `/channels/${enc(channelId)}/roles/${enc(roleId)}/permissions`, body);
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
/* ---------------- 频道·成员 ---------------- */
|
|
2028
|
+
|
|
2029
|
+
/** 频道成员列表。`GET /guilds/{guild_id}/members?after=&limit=` */
|
|
2030
|
+
getGuildMembers(guildId, { after = '0', limit = 1 } = {}) {
|
|
2031
|
+
const qs = new URLSearchParams({ after: String(after), limit: String(limit) });
|
|
2032
|
+
return this.#request('GET', `/guilds/${enc(guildId)}/members?${qs}`);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
/** 频道成员详情。`GET /guilds/{guild_id}/members/{user_id}` */
|
|
2036
|
+
getGuildMember(guildId, userId) {
|
|
2037
|
+
return this.#request('GET', `/guilds/${enc(guildId)}/members/${enc(userId)}`);
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
/** 在线成员数。`GET /channels/{channel_id}/online_nums` */
|
|
2041
|
+
getOnlineNums(channelId) {
|
|
2042
|
+
return this.#request('GET', `/channels/${enc(channelId)}/online_nums`);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
/* ---------------- 频道·API 权限 ---------------- */
|
|
2046
|
+
|
|
2047
|
+
/** 频道 API 权限清单。`GET /guilds/{guild_id}/api_permission` */
|
|
2048
|
+
getGuildApiPermission(guildId) {
|
|
2049
|
+
return this.#request('GET', `/guilds/${enc(guildId)}/api_permission`);
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
/** 申请频道 API 权限。`POST /guilds/{guild_id}/api_permission/demand` */
|
|
2053
|
+
postGuildApiPermissionDemand(guildId, body = {}) {
|
|
2054
|
+
return this.#request('POST', `/guilds/${enc(guildId)}/api_permission/demand`, body);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
/* ---------------- 频道·音频(仅音频类机器人) ---------------- */
|
|
2058
|
+
|
|
2059
|
+
/** 音频控制。`POST /channels/{channel_id}/audio` */
|
|
2060
|
+
audioControl(channelId, body = {}) {
|
|
2061
|
+
return this.#request('POST', `/channels/${enc(channelId)}/audio`, body);
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/** 机器人上麦。`PUT /channels/{channel_id}/mic` */
|
|
2065
|
+
putMic(channelId) {
|
|
2066
|
+
return this.#request('PUT', `/channels/${enc(channelId)}/mic`, {});
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
/** 机器人下麦。`DELETE /channels/{channel_id}/mic` */
|
|
2070
|
+
deleteMic(channelId) {
|
|
2071
|
+
return this.#request('DELETE', `/channels/${enc(channelId)}/mic`);
|
|
2072
|
+
}
|
|
2073
|
+
|
|
1732
2074
|
/* ---------------- 内部 ---------------- */
|
|
1733
2075
|
|
|
1734
2076
|
/**
|
package/src/bot.js
CHANGED
|
@@ -175,6 +175,15 @@ export class BotRuntime {
|
|
|
175
175
|
online: this.online,
|
|
176
176
|
appId: this.cfg.appId,
|
|
177
177
|
intents: this.cfg.intents,
|
|
178
|
+
/**
|
|
179
|
+
* **当前连接实际用的** intents(构造 Gateway 时的快照)。
|
|
180
|
+
*
|
|
181
|
+
* `intents` 是配置值,`config.set` 改完就变了,但没重建 Gateway 之前
|
|
182
|
+
* 线上跑的还是旧值(`gateway.js` 的 `this.intents` 不变)。面板要显示
|
|
183
|
+
* 「当前连接 / 待生效」两栏,必须区分这两个,不能拿配置值冒充。
|
|
184
|
+
* 未连接时为 null。
|
|
185
|
+
*/
|
|
186
|
+
gatewayIntents: this.gateway?.intents ?? null,
|
|
178
187
|
plugins: this.plugins ? this.plugins.list() : [],
|
|
179
188
|
uptimeMs: this.startedAt ? Date.now() - this.startedAt : 0,
|
|
180
189
|
error: this.lastError,
|
|
@@ -803,6 +812,58 @@ export class BotRuntime {
|
|
|
803
812
|
|
|
804
813
|
/* ---------------- 事件分发 ---------------- */
|
|
805
814
|
|
|
815
|
+
/**
|
|
816
|
+
* 非消息频道事件入账。
|
|
817
|
+
*
|
|
818
|
+
* 消息事件在下面走 `ledger.append(msg)`,但非消息分支以前完全不写账本,
|
|
819
|
+
* 只有内存里的 `metrics.bumpEvent` —— GUILD_CREATE / CHANNEL_* / FORUM_* /
|
|
820
|
+
* MESSAGE_REACTION_* 这些频道事件重启后连「发生过」都查不到。
|
|
821
|
+
*
|
|
822
|
+
* 这里补一条 `kind:'notice'` 记录:`raw` 完整保留事件体,`recent()` /
|
|
823
|
+
* `timeline()` 能查到,面板与宿主协议也读得到。用 `notice` 而不是四态会话
|
|
824
|
+
* 类型,避免和聊天消息的 kind 语义混淆;content 带 `[事件]` 前缀,AI 邻文里
|
|
825
|
+
* 也能一眼认出那不是用户说的话。
|
|
826
|
+
*
|
|
827
|
+
* id 用事件名 + 场景 + 操作人 + 时间戳拼出**稳定**值,官方重推同一条时
|
|
828
|
+
* `ledger.append` 的 dedupe 唯一约束会把它挡掉,不会记重。
|
|
829
|
+
*/
|
|
830
|
+
#recordNotice(eventName, d) {
|
|
831
|
+
if (!this.ledger?.append) return;
|
|
832
|
+
const CHANNEL_NOTICE = /^(GUILD|CHANNEL|FORUM|AUDIO|MESSAGE_REACTION|MESSAGE_AUDIT|PUBLIC_MESSAGE_DELETE|DIRECT_MESSAGE_DELETE)/;
|
|
833
|
+
if (!CHANNEL_NOTICE.test(eventName)) return;
|
|
834
|
+
/**
|
|
835
|
+
* 账本是增强,不是主链路:这里任何异常都不能把事件分发带崩
|
|
836
|
+
* (`ledger.append` 自己会吞写入异常,但拼 id 时的 JSON.stringify 在它之外)。
|
|
837
|
+
*/
|
|
838
|
+
try {
|
|
839
|
+
/**
|
|
840
|
+
* 和 dsh-roost 的 `sessionKey` 同口径:同一个频道的文字子频道、
|
|
841
|
+
* 论坛、公告等事件的账本键也按 guild_id 聚合,别散在各子频道里。
|
|
842
|
+
*/
|
|
843
|
+
const guildId = String(d?.guild_id ?? (eventName.startsWith('GUILD_') ? d?.id : '') ?? '');
|
|
844
|
+
const chatId = guildId ? `guild:${guildId}` : String(d?.channel_id ?? '');
|
|
845
|
+
const sub = d?.channel_id ? ` @子频道 ${String(d.channel_id).slice(0, 32)}` : '';
|
|
846
|
+
const stable = [
|
|
847
|
+
eventName,
|
|
848
|
+
chatId,
|
|
849
|
+
String(d?.op_user_id ?? d?.author_id ?? ''),
|
|
850
|
+
String(d?.timestamp ?? d?.joined_at ?? ''),
|
|
851
|
+
JSON.stringify(d ?? {}).length,
|
|
852
|
+
].join(':');
|
|
853
|
+
this.ledger.append({
|
|
854
|
+
kind: 'notice',
|
|
855
|
+
chatId,
|
|
856
|
+
id: `notice:${stable}`,
|
|
857
|
+
userId: String(d?.op_user_id ?? d?.author_id ?? ''),
|
|
858
|
+
userName: '',
|
|
859
|
+
content: `[事件] ${eventName}${sub}${d?.name ? ` ${String(d.name).slice(0, 80)}` : ''}`,
|
|
860
|
+
raw: d,
|
|
861
|
+
});
|
|
862
|
+
} catch (e) {
|
|
863
|
+
this.log.warn(`频道事件入账失败(不影响分发):${e?.message ?? e}`);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
806
867
|
/**
|
|
807
868
|
* 这个方法和单机器人时的逻辑一致,只是绑到了某个实例上。
|
|
808
869
|
* 所有事件都会转交给插件,未知事件也不例外。
|
|
@@ -816,6 +877,8 @@ export class BotRuntime {
|
|
|
816
877
|
|
|
817
878
|
/* ---- 非消息事件 ---- */
|
|
818
879
|
if (!isMessageEvent(eventName)) {
|
|
880
|
+
/** 和消息事件一样「入账第一」,放在任何处理/过滤之前 */
|
|
881
|
+
this.#recordNotice(eventName, d);
|
|
819
882
|
if (!isKnownEvent(eventName)) {
|
|
820
883
|
this.log.warn(`收到未登记的事件 ${eventName},已转交插件。建议在 src/events.js 补登记`);
|
|
821
884
|
}
|
package/src/config.js
CHANGED
|
@@ -119,6 +119,19 @@ const GLOBAL_DEFAULTS = {
|
|
|
119
119
|
* 于是「浏览器能打开 GitHub、框架说连不上」。详见 src/proxy.js。
|
|
120
120
|
*/
|
|
121
121
|
proxy: 'auto',
|
|
122
|
+
/**
|
|
123
|
+
* npm 源。插件依赖、外接依赖(ws / silk-wasm / ffmpeg)都走 npm,
|
|
124
|
+
* 国内直连官方源经常超时。
|
|
125
|
+
*
|
|
126
|
+
* '' 跟随系统:环境变量 npm_config_registry → ~/.npmrc → 官方源
|
|
127
|
+
* 'npmmirror' 淘宝镜像 https://registry.npmmirror.com
|
|
128
|
+
* 'official' 强制官方源
|
|
129
|
+
* 完整 URL 自定义源(必须 http(s))
|
|
130
|
+
*
|
|
131
|
+
* 默认留空:用户自己 `npm config set registry` 过的话,这里不该覆盖他。
|
|
132
|
+
* 解析逻辑见 src/npm-registry.js。
|
|
133
|
+
*/
|
|
134
|
+
npmRegistry: '',
|
|
122
135
|
},
|
|
123
136
|
|
|
124
137
|
/**
|