@satorijs/adapter-discord 3.8.5 → 3.8.6
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 +26 -18
- package/lib/index.js.map +2 -2
- package/lib/types/command.d.ts +7 -2
- package/package.json +1 -1
- package/readme.md +5 -0
package/lib/index.js
CHANGED
|
@@ -1322,15 +1322,17 @@ __name(setupReaction, "setupReaction");
|
|
|
1322
1322
|
async function adaptSession(bot, input) {
|
|
1323
1323
|
const session = bot.session({}, input);
|
|
1324
1324
|
if (input.t === "MESSAGE_CREATE") {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1325
|
+
setupMessageGuildId(session, input.d.guild_id);
|
|
1326
|
+
if (input.d.webhook_id && !session.isDirect) {
|
|
1327
|
+
try {
|
|
1328
|
+
const webhook = await bot.ensureWebhook(input.d.channel_id);
|
|
1329
|
+
if (webhook.id === input.d.webhook_id)
|
|
1330
|
+
return;
|
|
1331
|
+
} catch (e) {
|
|
1329
1332
|
}
|
|
1330
1333
|
}
|
|
1331
1334
|
session.type = "message";
|
|
1332
1335
|
await decodeMessage(bot, input.d, session);
|
|
1333
|
-
setupMessageGuildId(session, input.d.guild_id);
|
|
1334
1336
|
} else if (input.t === "MESSAGE_UPDATE") {
|
|
1335
1337
|
session.type = "message-updated";
|
|
1336
1338
|
const message = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
|
|
@@ -1384,7 +1386,7 @@ async function adaptSession(bot, input) {
|
|
|
1384
1386
|
session.subtype = input.d.guild_id ? "group" : "private";
|
|
1385
1387
|
session.channelId = input.d.channel_id;
|
|
1386
1388
|
session.guildId = input.d.guild_id;
|
|
1387
|
-
session.userId = input.d.member.user.id;
|
|
1389
|
+
session.userId = session.isDirect ? input.d.user.id : input.d.member.user.id;
|
|
1388
1390
|
session.messageId = input.d.id;
|
|
1389
1391
|
session.content = "";
|
|
1390
1392
|
session.data.argv = decodeArgv(data, command);
|
|
@@ -1433,7 +1435,7 @@ var decodeArgv = /* @__PURE__ */ __name((data, command) => {
|
|
|
1433
1435
|
return result;
|
|
1434
1436
|
}, "decodeArgv");
|
|
1435
1437
|
function encodeCommandOptions(cmd) {
|
|
1436
|
-
var _a, _b
|
|
1438
|
+
var _a, _b;
|
|
1437
1439
|
const result = [];
|
|
1438
1440
|
if (cmd.children.length) {
|
|
1439
1441
|
result.push(...cmd.children.map((child) => ({
|
|
@@ -1449,8 +1451,8 @@ function encodeCommandOptions(cmd) {
|
|
|
1449
1451
|
name: arg.name.toLowerCase().replace(/[^a-z0-9]/g, ""),
|
|
1450
1452
|
description: arg.description[""] || arg.name,
|
|
1451
1453
|
description_localizations: (0, import_satori2.pick)(arg.description, Locale3),
|
|
1452
|
-
type: (_a = types[arg.type]) != null ? _a : types.text
|
|
1453
|
-
required:
|
|
1454
|
+
type: (_a = types[arg.type]) != null ? _a : types.text
|
|
1455
|
+
// required: arg.required ?? false,
|
|
1454
1456
|
});
|
|
1455
1457
|
}
|
|
1456
1458
|
for (const option of cmd.options) {
|
|
@@ -1458,8 +1460,8 @@ function encodeCommandOptions(cmd) {
|
|
|
1458
1460
|
name: option.name.toLowerCase(),
|
|
1459
1461
|
description: option.description[""] || option.name,
|
|
1460
1462
|
description_localizations: (0, import_satori2.pick)(option.description, Locale3),
|
|
1461
|
-
type: (
|
|
1462
|
-
required:
|
|
1463
|
+
type: (_b = types[option.type]) != null ? _b : types.text,
|
|
1464
|
+
// required: option.required ?? false,
|
|
1463
1465
|
min_value: option.type === "posint" ? 1 : void 0
|
|
1464
1466
|
});
|
|
1465
1467
|
}
|
|
@@ -2066,7 +2068,8 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2066
2068
|
async updateCommands(commands) {
|
|
2067
2069
|
this.commands = commands;
|
|
2068
2070
|
const local = Object.fromEntries(commands.map((cmd) => [cmd.name, cmd]));
|
|
2069
|
-
const remote = Object.fromEntries((await this.internal.getGlobalApplicationCommands(this.selfId)).filter((cmd) => cmd.type === ApplicationCommand2.Type.CHAT_INPUT).map((cmd) => [cmd.name, cmd]));
|
|
2071
|
+
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]));
|
|
2072
|
+
const updates = [];
|
|
2070
2073
|
for (const key in { ...local, ...remote }) {
|
|
2071
2074
|
if (!local[key]) {
|
|
2072
2075
|
logger3.debug("delete command %s", key);
|
|
@@ -2077,26 +2080,31 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2077
2080
|
logger3.debug(data, remote[key]);
|
|
2078
2081
|
if (!remote[key]) {
|
|
2079
2082
|
logger3.debug("create command: %s", local[key].name);
|
|
2080
|
-
|
|
2081
|
-
} else if (shapeEqual(data, remote[key])) {
|
|
2083
|
+
updates.push(data);
|
|
2084
|
+
} else if (!shapeEqual(data, remote[key])) {
|
|
2082
2085
|
logger3.debug("edit command: %s", local[key].name);
|
|
2083
|
-
|
|
2086
|
+
updates.push(data);
|
|
2084
2087
|
}
|
|
2085
2088
|
}
|
|
2089
|
+
if (updates.length) {
|
|
2090
|
+
await this.internal.bulkOverwriteGlobalApplicationCommands(this.selfId, updates);
|
|
2091
|
+
}
|
|
2086
2092
|
}
|
|
2087
2093
|
};
|
|
2088
2094
|
__name(_DiscordBot, "DiscordBot");
|
|
2089
2095
|
__publicField(_DiscordBot, "MessageEncoder", DiscordMessageEncoder);
|
|
2090
2096
|
var DiscordBot = _DiscordBot;
|
|
2091
|
-
function shapeEqual(a, b
|
|
2097
|
+
function shapeEqual(a, b) {
|
|
2092
2098
|
if (a === b)
|
|
2093
2099
|
return true;
|
|
2094
|
-
if (
|
|
2100
|
+
if ((0, import_satori5.isNullable)(a) && (0, import_satori5.isNullable)(b))
|
|
2095
2101
|
return true;
|
|
2096
2102
|
if (typeof a !== typeof b)
|
|
2097
2103
|
return false;
|
|
2098
2104
|
if (typeof a !== "object")
|
|
2099
2105
|
return false;
|
|
2106
|
+
if (Object.values(a).every(import_satori5.isNullable) && (0, import_satori5.isNullable)(b))
|
|
2107
|
+
return true;
|
|
2100
2108
|
if (!a || !b)
|
|
2101
2109
|
return false;
|
|
2102
2110
|
if (Array.isArray(a)) {
|
|
@@ -2106,7 +2114,7 @@ function shapeEqual(a, b, strict = false) {
|
|
|
2106
2114
|
} else if (Array.isArray(b)) {
|
|
2107
2115
|
return false;
|
|
2108
2116
|
}
|
|
2109
|
-
return Object.keys(a).every((key) => shapeEqual(a[key], b[key]
|
|
2117
|
+
return Object.keys(a).every((key) => shapeEqual(a[key], b[key]));
|
|
2110
2118
|
}
|
|
2111
2119
|
__name(shapeEqual, "shapeEqual");
|
|
2112
2120
|
((DiscordBot2) => {
|