@satorijs/adapter-discord 4.0.3 → 4.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/lib/index.js +110 -48
- package/lib/index.js.map +3 -3
- package/lib/message.d.ts +4 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -312,7 +312,7 @@ Internal.define({
|
|
|
312
312
|
|
|
313
313
|
// satori/adapters/discord/src/types/channel.ts
|
|
314
314
|
var Channel2;
|
|
315
|
-
((
|
|
315
|
+
((Channel11) => {
|
|
316
316
|
let Type;
|
|
317
317
|
((Type2) => {
|
|
318
318
|
Type2[Type2["GUILD_TEXT"] = 0] = "GUILD_TEXT";
|
|
@@ -328,7 +328,7 @@ var Channel2;
|
|
|
328
328
|
Type2[Type2["GUILD_STAGE_VOICE"] = 13] = "GUILD_STAGE_VOICE";
|
|
329
329
|
Type2[Type2["GUILD_DIRECTORY"] = 14] = "GUILD_DIRECTORY";
|
|
330
330
|
Type2[Type2["GUILD_FORUM"] = 15] = "GUILD_FORUM";
|
|
331
|
-
})(Type =
|
|
331
|
+
})(Type = Channel11.Type || (Channel11.Type = {}));
|
|
332
332
|
})(Channel2 || (Channel2 = {}));
|
|
333
333
|
var OverwriteType = /* @__PURE__ */ ((OverwriteType2) => {
|
|
334
334
|
OverwriteType2[OverwriteType2["ROLE"] = 0] = "ROLE";
|
|
@@ -749,7 +749,7 @@ Internal.define({
|
|
|
749
749
|
|
|
750
750
|
// satori/adapters/discord/src/types/message.ts
|
|
751
751
|
var Message2;
|
|
752
|
-
((
|
|
752
|
+
((Message5) => {
|
|
753
753
|
let Type;
|
|
754
754
|
((Type2) => {
|
|
755
755
|
Type2[Type2["DEFAULT"] = 0] = "DEFAULT";
|
|
@@ -779,14 +779,14 @@ var Message2;
|
|
|
779
779
|
Type2[Type2["ROLE_SUBSCRIPTION_PURCHASE"] = 25] = "ROLE_SUBSCRIPTION_PURCHASE";
|
|
780
780
|
Type2[Type2["INTERACTION_PREMIUM_UPSELL"] = 26] = "INTERACTION_PREMIUM_UPSELL";
|
|
781
781
|
Type2[Type2["GUILD_APPLICATION_PREMIUM_SUBSCRIPTION"] = 32] = "GUILD_APPLICATION_PREMIUM_SUBSCRIPTION";
|
|
782
|
-
})(Type =
|
|
782
|
+
})(Type = Message5.Type || (Message5.Type = {}));
|
|
783
783
|
let ActivityType2;
|
|
784
784
|
((ActivityType3) => {
|
|
785
785
|
ActivityType3[ActivityType3["JOIN"] = 1] = "JOIN";
|
|
786
786
|
ActivityType3[ActivityType3["SPECTATE"] = 2] = "SPECTATE";
|
|
787
787
|
ActivityType3[ActivityType3["LISTEN"] = 3] = "LISTEN";
|
|
788
788
|
ActivityType3[ActivityType3["JOIN_REQUEST"] = 5] = "JOIN_REQUEST";
|
|
789
|
-
})(ActivityType2 =
|
|
789
|
+
})(ActivityType2 = Message5.ActivityType || (Message5.ActivityType = {}));
|
|
790
790
|
let Flag;
|
|
791
791
|
((Flag2) => {
|
|
792
792
|
Flag2[Flag2["CROSSPOSTED"] = 1] = "CROSSPOSTED";
|
|
@@ -798,7 +798,7 @@ var Message2;
|
|
|
798
798
|
Flag2[Flag2["EPHEMERAL"] = 64] = "EPHEMERAL";
|
|
799
799
|
Flag2[Flag2["LOADING"] = 128] = "LOADING";
|
|
800
800
|
Flag2[Flag2["FAILED_TO_MENTION_SOME_ROLES_IN_THREAD"] = 256] = "FAILED_TO_MENTION_SOME_ROLES_IN_THREAD";
|
|
801
|
-
})(Flag =
|
|
801
|
+
})(Flag = Message5.Flag || (Message5.Flag = {}));
|
|
802
802
|
})(Message2 || (Message2 = {}));
|
|
803
803
|
Internal.define({
|
|
804
804
|
"/channels/{channel.id}/messages": {
|
|
@@ -1396,6 +1396,57 @@ async function adaptSession(bot, input) {
|
|
|
1396
1396
|
session.messageId = input.d.id;
|
|
1397
1397
|
session.content = "";
|
|
1398
1398
|
session.event.argv = decodeArgv(data, command);
|
|
1399
|
+
} else if (input.t === "INTERACTION_CREATE" && input.d.type === Interaction.Type.MODAL_SUBMIT) {
|
|
1400
|
+
const data = input.d.data;
|
|
1401
|
+
if (!data.custom_id.startsWith("input:"))
|
|
1402
|
+
return;
|
|
1403
|
+
const user_input = data.components[0].components[0].value;
|
|
1404
|
+
await bot.internal.createInteractionResponse(input.d.id, input.d.token, {
|
|
1405
|
+
type: Interaction.CallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
|
|
1406
|
+
});
|
|
1407
|
+
session.type = "interaction/command";
|
|
1408
|
+
session.isDirect = !input.d.guild_id;
|
|
1409
|
+
session.subtype = input.d.guild_id ? "group" : "private";
|
|
1410
|
+
session.channelId = input.d.channel_id;
|
|
1411
|
+
session.guildId = input.d.guild_id;
|
|
1412
|
+
session.userId = session.isDirect ? input.d.user.id : input.d.member.user.id;
|
|
1413
|
+
session.messageId = input.d.id;
|
|
1414
|
+
session.content = user_input;
|
|
1415
|
+
} else if (input.t === "INTERACTION_CREATE" && input.d.type === Interaction.Type.MESSAGE_COMPONENT) {
|
|
1416
|
+
const id = input.d.data.custom_id;
|
|
1417
|
+
if (id.startsWith("input:")) {
|
|
1418
|
+
await bot.internal.createInteractionResponse(input.d.id, input.d.token, {
|
|
1419
|
+
type: Interaction.CallbackType.MODAL,
|
|
1420
|
+
data: {
|
|
1421
|
+
custom_id: id,
|
|
1422
|
+
title: "title",
|
|
1423
|
+
components: [{
|
|
1424
|
+
type: 1 /* ACTION_ROW */,
|
|
1425
|
+
components: [{
|
|
1426
|
+
custom_id: id,
|
|
1427
|
+
type: 4 /* TEXT_INPUT */,
|
|
1428
|
+
label: "auto complete",
|
|
1429
|
+
value: id.slice("input:".length),
|
|
1430
|
+
style: 1
|
|
1431
|
+
}]
|
|
1432
|
+
}]
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
} else {
|
|
1436
|
+
await bot.internal.createInteractionResponse(input.d.id, input.d.token, {
|
|
1437
|
+
type: Interaction.CallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
session.type = "interaction/button";
|
|
1441
|
+
session.isDirect = !input.d.guild_id;
|
|
1442
|
+
session.channelId = input.d.channel_id;
|
|
1443
|
+
session.guildId = input.d.guild_id;
|
|
1444
|
+
session.userId = session.isDirect ? input.d.user.id : input.d.member.user.id;
|
|
1445
|
+
session.messageId = input.d.id;
|
|
1446
|
+
session.content = "";
|
|
1447
|
+
session.event.button = {
|
|
1448
|
+
id
|
|
1449
|
+
};
|
|
1399
1450
|
} else if (input.t === "CHANNEL_UPDATE") {
|
|
1400
1451
|
session.type = "channel-updated";
|
|
1401
1452
|
session.guildId = input.d.guild_id;
|
|
@@ -1507,6 +1558,8 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
|
|
|
1507
1558
|
figure = null;
|
|
1508
1559
|
mode = "default";
|
|
1509
1560
|
listType = null;
|
|
1561
|
+
rows = [];
|
|
1562
|
+
buttonGroupState = false;
|
|
1510
1563
|
async getUrl() {
|
|
1511
1564
|
var _a, _b, _c, _d;
|
|
1512
1565
|
const input = (_b = (_a = this.options) == null ? void 0 : _a.session) == null ? void 0 : _b.discord;
|
|
@@ -1618,9 +1671,35 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
|
|
|
1618
1671
|
const content = this.buffer.trim();
|
|
1619
1672
|
if (!content)
|
|
1620
1673
|
return;
|
|
1674
|
+
this.addition.components = this.rows;
|
|
1621
1675
|
await this.post({ ...this.addition, content });
|
|
1622
1676
|
this.buffer = "";
|
|
1623
1677
|
this.addition = {};
|
|
1678
|
+
this.rows = [];
|
|
1679
|
+
}
|
|
1680
|
+
decodeButton(attrs, label) {
|
|
1681
|
+
if (attrs.type === "link") {
|
|
1682
|
+
return {
|
|
1683
|
+
type: 2 /* BUTTON */,
|
|
1684
|
+
url: attrs.href,
|
|
1685
|
+
label,
|
|
1686
|
+
style: 5
|
|
1687
|
+
};
|
|
1688
|
+
} else if (attrs.type === "action") {
|
|
1689
|
+
return {
|
|
1690
|
+
type: 2 /* BUTTON */,
|
|
1691
|
+
custom_id: attrs.id,
|
|
1692
|
+
label,
|
|
1693
|
+
style: 1
|
|
1694
|
+
};
|
|
1695
|
+
} else if (attrs.type === "input") {
|
|
1696
|
+
return {
|
|
1697
|
+
type: 2 /* BUTTON */,
|
|
1698
|
+
custom_id: "input:" + attrs.text,
|
|
1699
|
+
label,
|
|
1700
|
+
style: 1
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1624
1703
|
}
|
|
1625
1704
|
async visit(element) {
|
|
1626
1705
|
var _a;
|
|
@@ -1795,6 +1874,29 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
|
|
|
1795
1874
|
this.stack[1].author = {};
|
|
1796
1875
|
}
|
|
1797
1876
|
}
|
|
1877
|
+
} else if (type === "button") {
|
|
1878
|
+
if (this.buttonGroupState) {
|
|
1879
|
+
const last = this.rows[this.rows.length - 1];
|
|
1880
|
+
last.components.push(this.decodeButton(
|
|
1881
|
+
attrs,
|
|
1882
|
+
children.join("")
|
|
1883
|
+
));
|
|
1884
|
+
} else {
|
|
1885
|
+
this.rows.push({
|
|
1886
|
+
type: 1 /* ACTION_ROW */,
|
|
1887
|
+
components: [
|
|
1888
|
+
this.decodeButton(attrs, children.join(""))
|
|
1889
|
+
]
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
} else if (type === "button-group") {
|
|
1893
|
+
this.buttonGroupState = true;
|
|
1894
|
+
this.rows.push({
|
|
1895
|
+
type: 1 /* ACTION_ROW */,
|
|
1896
|
+
components: []
|
|
1897
|
+
});
|
|
1898
|
+
await this.render(children);
|
|
1899
|
+
this.buttonGroupState = false;
|
|
1798
1900
|
} else if (type === "message" && attrs.forward) {
|
|
1799
1901
|
this.stack.unshift(new State("forward"));
|
|
1800
1902
|
await this.render(children);
|
|
@@ -2095,26 +2197,9 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2095
2197
|
if (!this.config.slash)
|
|
2096
2198
|
return;
|
|
2097
2199
|
this.commands = commands;
|
|
2098
|
-
const
|
|
2099
|
-
const remote = Object.fromEntries((await this.internal.getGlobalApplicationCommands(this.selfId, { with_localizations: true })).filter((cmd) => cmd.type === ApplicationCommand2.Type.CHAT_INPUT).map((cmd) => [cmd.name, cmd]));
|
|
2100
|
-
const updates = [];
|
|
2101
|
-
for (const key in { ...local, ...remote }) {
|
|
2102
|
-
if (!local[key]) {
|
|
2103
|
-
logger3.debug("delete command %s", key);
|
|
2104
|
-
await this.internal.deleteGlobalApplicationCommand(this.selfId, remote[key].id);
|
|
2105
|
-
continue;
|
|
2106
|
-
}
|
|
2107
|
-
const data = encodeCommand(local[key]);
|
|
2108
|
-
logger3.debug(data, remote[key]);
|
|
2109
|
-
if (!remote[key]) {
|
|
2110
|
-
logger3.debug("create command: %s", local[key].name);
|
|
2111
|
-
updates.push(data);
|
|
2112
|
-
} else if (!shapeEqual(data, remote[key])) {
|
|
2113
|
-
logger3.debug("edit command: %s", local[key].name);
|
|
2114
|
-
updates.push(data);
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2200
|
+
const updates = commands.map(encodeCommand);
|
|
2117
2201
|
if (updates.length) {
|
|
2202
|
+
logger3.debug("update %d command(s)", updates.length);
|
|
2118
2203
|
await this.internal.bulkOverwriteGlobalApplicationCommands(this.selfId, updates);
|
|
2119
2204
|
}
|
|
2120
2205
|
}
|
|
@@ -2122,29 +2207,6 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2122
2207
|
__name(_DiscordBot, "DiscordBot");
|
|
2123
2208
|
__publicField(_DiscordBot, "MessageEncoder", DiscordMessageEncoder);
|
|
2124
2209
|
var DiscordBot = _DiscordBot;
|
|
2125
|
-
function shapeEqual(a, b) {
|
|
2126
|
-
if (a === b)
|
|
2127
|
-
return true;
|
|
2128
|
-
if ((0, import_satori5.isNullable)(a) && (0, import_satori5.isNullable)(b))
|
|
2129
|
-
return true;
|
|
2130
|
-
if (typeof a !== typeof b)
|
|
2131
|
-
return false;
|
|
2132
|
-
if (typeof a !== "object")
|
|
2133
|
-
return false;
|
|
2134
|
-
if (Object.values(a).every(import_satori5.isNullable) && (0, import_satori5.isNullable)(b))
|
|
2135
|
-
return true;
|
|
2136
|
-
if (!a || !b)
|
|
2137
|
-
return false;
|
|
2138
|
-
if (Array.isArray(a)) {
|
|
2139
|
-
if (!Array.isArray(b) || a.length !== b.length)
|
|
2140
|
-
return false;
|
|
2141
|
-
return a.every((item, index) => shapeEqual(item, b[index]));
|
|
2142
|
-
} else if (Array.isArray(b)) {
|
|
2143
|
-
return false;
|
|
2144
|
-
}
|
|
2145
|
-
return Object.keys(a).every((key) => shapeEqual(a[key], b[key]));
|
|
2146
|
-
}
|
|
2147
|
-
__name(shapeEqual, "shapeEqual");
|
|
2148
2210
|
((DiscordBot2) => {
|
|
2149
2211
|
DiscordBot2.Config = import_satori5.Schema.intersect([
|
|
2150
2212
|
import_satori5.Schema.object({
|