@satorijs/adapter-discord 3.6.1 → 3.7.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/lib/bot.d.ts +23 -14
- package/lib/index.js +66 -18
- package/lib/index.js.map +3 -3
- package/lib/message.d.ts +4 -4
- package/lib/types/reaction.d.ts +2 -2
- package/lib/types/role.d.ts +14 -14
- package/lib/utils.d.ts +2 -0
- package/package.json +2 -2
package/lib/bot.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Bot, Context, Fragment, Quester, Schema,
|
|
2
|
-
import {
|
|
1
|
+
import { Bot, Context, Fragment, Quester, Schema, Universal } from '@satorijs/satori';
|
|
2
|
+
import { DiscordMessageEncoder } from './message';
|
|
3
3
|
import { Internal, Webhook } from './types';
|
|
4
4
|
import { WsClient } from './ws';
|
|
5
5
|
export declare class DiscordBot extends Bot<DiscordBot.Config> {
|
|
6
|
+
static MessageEncoder: typeof DiscordMessageEncoder;
|
|
6
7
|
http: Quester;
|
|
7
8
|
internal: Internal;
|
|
8
9
|
webhooks: Record<string, Webhook>;
|
|
@@ -10,16 +11,14 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
|
|
|
10
11
|
constructor(ctx: Context, config: DiscordBot.Config);
|
|
11
12
|
private _ensureWebhook;
|
|
12
13
|
ensureWebhook(channelId: string): Promise<Webhook>;
|
|
13
|
-
getSelf(): Promise<
|
|
14
|
-
sendMessage(channelId: string, content: Fragment, guildId?: string, options?: SendOptions): Promise<string[]>;
|
|
15
|
-
sendPrivateMessage(channelId: string, content: Fragment, options?: SendOptions): Promise<string[]>;
|
|
14
|
+
getSelf(): Promise<Universal.User>;
|
|
16
15
|
deleteMessage(channelId: string, messageId: string): Promise<void>;
|
|
17
16
|
editMessage(channelId: string, messageId: string, content: Fragment): Promise<void>;
|
|
18
|
-
getMessage(channelId: string, messageId: string): Promise<
|
|
19
|
-
getMessageList(channelId: string, before?: string): Promise<
|
|
20
|
-
getUser(userId: string): Promise<
|
|
21
|
-
getGuildMemberList(guildId: string): Promise<
|
|
22
|
-
getChannel(channelId: string): Promise<
|
|
17
|
+
getMessage(channelId: string, messageId: string): Promise<Universal.Message>;
|
|
18
|
+
getMessageList(channelId: string, before?: string): Promise<Universal.Message[]>;
|
|
19
|
+
getUser(userId: string): Promise<Universal.User>;
|
|
20
|
+
getGuildMemberList(guildId: string): Promise<Universal.User[]>;
|
|
21
|
+
getChannel(channelId: string): Promise<Universal.Channel>;
|
|
23
22
|
getGuildMember(guildId: string, userId: string): Promise<{
|
|
24
23
|
nickname: string;
|
|
25
24
|
userId: string;
|
|
@@ -29,12 +28,22 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
|
|
|
29
28
|
isBot?: boolean;
|
|
30
29
|
}>;
|
|
31
30
|
kickGuildMember(guildId: string, userId: string): Promise<void>;
|
|
32
|
-
getGuild(guildId: string): Promise<
|
|
33
|
-
getGuildList(): Promise<
|
|
34
|
-
getChannelList(guildId: string): Promise<
|
|
31
|
+
getGuild(guildId: string): Promise<Universal.Guild>;
|
|
32
|
+
getGuildList(): Promise<Universal.Guild[]>;
|
|
33
|
+
getChannelList(guildId: string): Promise<Universal.Channel[]>;
|
|
34
|
+
createReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
|
|
35
|
+
deleteReaction(channelId: string, messageId: string, emoji: string, userId?: string): Promise<void>;
|
|
36
|
+
clearReaction(channelId: string, messageId: string, emoji?: string): Promise<void>;
|
|
37
|
+
getReactions(channelId: string, messageId: string, emoji: string): Promise<Universal.User[]>;
|
|
38
|
+
setGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>;
|
|
39
|
+
unsetGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>;
|
|
40
|
+
getGuildRoles(guildId: string): Promise<Universal.Role[]>;
|
|
41
|
+
createGuildRole(guildId: string, data: Partial<Universal.Role>): Promise<Universal.Role>;
|
|
42
|
+
modifyGuildRole(guildId: string, roleId: string, data: Partial<Universal.Role>): Promise<void>;
|
|
43
|
+
deleteGuildRole(guildId: string, roleId: string): Promise<void>;
|
|
35
44
|
}
|
|
36
45
|
export declare namespace DiscordBot {
|
|
37
|
-
interface Config extends Bot.Config, Quester.Config,
|
|
46
|
+
interface Config extends Bot.Config, Quester.Config, DiscordMessageEncoder.Config, WsClient.Config {
|
|
38
47
|
token: string;
|
|
39
48
|
}
|
|
40
49
|
const Config: Schema<Config>;
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Discord: () => types_exports,
|
|
34
34
|
DiscordBot: () => DiscordBot,
|
|
35
|
-
|
|
35
|
+
DiscordMessageEncoder: () => DiscordMessageEncoder,
|
|
36
36
|
WsClient: () => WsClient,
|
|
37
37
|
adaptAuthor: () => adaptAuthor,
|
|
38
38
|
adaptChannel: () => adaptChannel,
|
|
@@ -40,7 +40,9 @@ __export(src_exports, {
|
|
|
40
40
|
adaptMessage: () => adaptMessage,
|
|
41
41
|
adaptSession: () => adaptSession,
|
|
42
42
|
adaptUser: () => adaptUser,
|
|
43
|
+
decodeRole: () => decodeRole,
|
|
43
44
|
default: () => src_default,
|
|
45
|
+
encodeRole: () => encodeRole,
|
|
44
46
|
prepareMessage: () => prepareMessage,
|
|
45
47
|
sanitize: () => sanitize
|
|
46
48
|
});
|
|
@@ -71,6 +73,14 @@ var adaptAuthor = /* @__PURE__ */ __name((author) => ({
|
|
|
71
73
|
...adaptUser(author),
|
|
72
74
|
nickname: author.username
|
|
73
75
|
}), "adaptAuthor");
|
|
76
|
+
var decodeRole = /* @__PURE__ */ __name((role) => ({
|
|
77
|
+
...role,
|
|
78
|
+
permissions: BigInt(role.permissions)
|
|
79
|
+
}), "decodeRole");
|
|
80
|
+
var encodeRole = /* @__PURE__ */ __name((role) => ({
|
|
81
|
+
...role,
|
|
82
|
+
permissions: role.permissions && "" + role.permissions
|
|
83
|
+
}), "encodeRole");
|
|
74
84
|
async function adaptMessage(bot, meta, session = {}) {
|
|
75
85
|
var _a, _b, _c;
|
|
76
86
|
const { platform } = bot;
|
|
@@ -237,7 +247,7 @@ var State = class {
|
|
|
237
247
|
}
|
|
238
248
|
};
|
|
239
249
|
__name(State, "State");
|
|
240
|
-
var
|
|
250
|
+
var DiscordMessageEncoder = class extends import_satori2.MessageEncoder {
|
|
241
251
|
constructor() {
|
|
242
252
|
super(...arguments);
|
|
243
253
|
this.stack = [new State("message")];
|
|
@@ -503,9 +513,9 @@ var DiscordMessenger = class extends import_satori2.Messenger {
|
|
|
503
513
|
}
|
|
504
514
|
}
|
|
505
515
|
};
|
|
506
|
-
__name(
|
|
507
|
-
((
|
|
508
|
-
|
|
516
|
+
__name(DiscordMessageEncoder, "DiscordMessageEncoder");
|
|
517
|
+
((DiscordMessageEncoder2) => {
|
|
518
|
+
DiscordMessageEncoder2.Config = import_satori2.Schema.object({
|
|
509
519
|
handleExternalAsset: import_satori2.Schema.union([
|
|
510
520
|
import_satori2.Schema.const("download").description("先下载后发送"),
|
|
511
521
|
import_satori2.Schema.const("direct").description("直接发送链接"),
|
|
@@ -517,7 +527,7 @@ __name(DiscordMessenger, "DiscordMessenger");
|
|
|
517
527
|
import_satori2.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
|
|
518
528
|
]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
|
|
519
529
|
}).description("发送设置");
|
|
520
|
-
})(
|
|
530
|
+
})(DiscordMessageEncoder || (DiscordMessageEncoder = {}));
|
|
521
531
|
|
|
522
532
|
// satori/adapters/discord/src/types/index.ts
|
|
523
533
|
var types_exports = {};
|
|
@@ -1609,10 +1619,10 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
|
|
|
1609
1619
|
}
|
|
1610
1620
|
async prepare() {
|
|
1611
1621
|
if (this._resumeUrl) {
|
|
1612
|
-
return this.bot.http.ws(this._resumeUrl);
|
|
1622
|
+
return this.bot.http.ws(this._resumeUrl + "/?v=10&encoding=json");
|
|
1613
1623
|
}
|
|
1614
1624
|
const { url } = await this.bot.internal.getGatewayBot();
|
|
1615
|
-
return this.bot.http.ws(url);
|
|
1625
|
+
return this.bot.http.ws(url + "/?v=10&encoding=json");
|
|
1616
1626
|
}
|
|
1617
1627
|
heartbeat() {
|
|
1618
1628
|
logger2.debug(`heartbeat d ${this._d}`);
|
|
@@ -1752,12 +1762,6 @@ var DiscordBot = class extends import_satori5.Bot {
|
|
|
1752
1762
|
const data = await this.internal.getCurrentUser();
|
|
1753
1763
|
return adaptUser(data);
|
|
1754
1764
|
}
|
|
1755
|
-
async sendMessage(channelId, content, guildId, options) {
|
|
1756
|
-
return new DiscordMessenger(this, channelId, guildId, options).send(content);
|
|
1757
|
-
}
|
|
1758
|
-
async sendPrivateMessage(channelId, content, options) {
|
|
1759
|
-
return new DiscordMessenger(this, channelId, null, options).send(content);
|
|
1760
|
-
}
|
|
1761
1765
|
async deleteMessage(channelId, messageId) {
|
|
1762
1766
|
await this.internal.deleteMessage(channelId, messageId);
|
|
1763
1767
|
}
|
|
@@ -1808,21 +1812,63 @@ var DiscordBot = class extends import_satori5.Bot {
|
|
|
1808
1812
|
}
|
|
1809
1813
|
async getGuildList() {
|
|
1810
1814
|
const data = await this.internal.getCurrentUserGuilds();
|
|
1811
|
-
return data.map(
|
|
1815
|
+
return data.map(adaptGuild);
|
|
1812
1816
|
}
|
|
1813
1817
|
async getChannelList(guildId) {
|
|
1814
1818
|
const data = await this.internal.getGuildChannels(guildId);
|
|
1815
|
-
return data.map(
|
|
1819
|
+
return data.map(adaptChannel);
|
|
1820
|
+
}
|
|
1821
|
+
createReaction(channelId, messageId, emoji) {
|
|
1822
|
+
return this.internal.createReaction(channelId, messageId, emoji);
|
|
1823
|
+
}
|
|
1824
|
+
deleteReaction(channelId, messageId, emoji, userId) {
|
|
1825
|
+
if (!userId) {
|
|
1826
|
+
return this.internal.deleteOwnReaction(channelId, messageId, emoji);
|
|
1827
|
+
} else {
|
|
1828
|
+
return this.internal.deleteUserReaction(channelId, messageId, emoji, userId);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
clearReaction(channelId, messageId, emoji) {
|
|
1832
|
+
if (!emoji) {
|
|
1833
|
+
return this.internal.deleteAllReactions(channelId, messageId);
|
|
1834
|
+
} else {
|
|
1835
|
+
return this.internal.deleteAllReactionsForEmoji(channelId, messageId, emoji);
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
async getReactions(channelId, messageId, emoji) {
|
|
1839
|
+
const data = await this.internal.getReactions(channelId, messageId, emoji);
|
|
1840
|
+
return data.map(adaptUser);
|
|
1841
|
+
}
|
|
1842
|
+
setGuildMemberRole(guildId, userId, roleId) {
|
|
1843
|
+
return this.internal.addGuildMemberRole(guildId, userId, roleId);
|
|
1844
|
+
}
|
|
1845
|
+
unsetGuildMemberRole(guildId, userId, roleId) {
|
|
1846
|
+
return this.internal.removeGuildMemberRole(guildId, userId, roleId);
|
|
1847
|
+
}
|
|
1848
|
+
async getGuildRoles(guildId) {
|
|
1849
|
+
const data = await this.internal.getGuildRoles(guildId);
|
|
1850
|
+
return data.map(decodeRole);
|
|
1851
|
+
}
|
|
1852
|
+
async createGuildRole(guildId, data) {
|
|
1853
|
+
const role = await this.internal.createGuildRole(guildId, encodeRole(data));
|
|
1854
|
+
return decodeRole(role);
|
|
1855
|
+
}
|
|
1856
|
+
async modifyGuildRole(guildId, roleId, data) {
|
|
1857
|
+
await this.internal.modifyGuildRole(guildId, roleId, encodeRole(data));
|
|
1858
|
+
}
|
|
1859
|
+
deleteGuildRole(guildId, roleId) {
|
|
1860
|
+
return this.internal.deleteGuildRole(guildId, roleId);
|
|
1816
1861
|
}
|
|
1817
1862
|
};
|
|
1818
1863
|
__name(DiscordBot, "DiscordBot");
|
|
1864
|
+
DiscordBot.MessageEncoder = DiscordMessageEncoder;
|
|
1819
1865
|
((DiscordBot2) => {
|
|
1820
1866
|
DiscordBot2.Config = import_satori5.Schema.intersect([
|
|
1821
1867
|
import_satori5.Schema.object({
|
|
1822
1868
|
token: import_satori5.Schema.string().description("机器人的用户令牌。").role("secret").required()
|
|
1823
1869
|
}),
|
|
1824
1870
|
WsClient.Config,
|
|
1825
|
-
|
|
1871
|
+
DiscordMessageEncoder.Config,
|
|
1826
1872
|
import_satori5.Quester.createConfig("https://discord.com/api/v10")
|
|
1827
1873
|
]);
|
|
1828
1874
|
})(DiscordBot || (DiscordBot = {}));
|
|
@@ -1834,7 +1880,7 @@ var src_default = DiscordBot;
|
|
|
1834
1880
|
0 && (module.exports = {
|
|
1835
1881
|
Discord,
|
|
1836
1882
|
DiscordBot,
|
|
1837
|
-
|
|
1883
|
+
DiscordMessageEncoder,
|
|
1838
1884
|
WsClient,
|
|
1839
1885
|
adaptAuthor,
|
|
1840
1886
|
adaptChannel,
|
|
@@ -1842,6 +1888,8 @@ var src_default = DiscordBot;
|
|
|
1842
1888
|
adaptMessage,
|
|
1843
1889
|
adaptSession,
|
|
1844
1890
|
adaptUser,
|
|
1891
|
+
decodeRole,
|
|
1892
|
+
encodeRole,
|
|
1845
1893
|
prepareMessage,
|
|
1846
1894
|
sanitize
|
|
1847
1895
|
});
|