lunibee 0.2.0 → 0.2.2
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 +6 -6
- package/dist/builders/attachment.d.ts +5 -1
- package/dist/builders/commands.d.ts +131 -45
- package/dist/builders/components.d.ts +183 -41
- package/dist/builders/embed.d.ts +12 -8
- package/dist/builders/index.d.ts +9 -4
- package/dist/builders/index.js +234 -110
- package/dist/builders/index.js.map +8 -8
- package/dist/core/events.d.ts +28 -12
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +414 -78
- package/dist/core/index.js.map +18 -18
- package/dist/core/permissions.d.ts +6 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +869 -194
- package/dist/index.js.map +25 -24
- package/dist/managers/guild-resources.d.ts +22 -2
- package/dist/managers/guild.d.ts +3 -1
- package/dist/managers/index.d.ts +7 -3
- package/dist/managers/index.js +167 -33
- package/dist/managers/index.js.map +13 -13
- package/dist/managers/member.d.ts +13 -12
- package/dist/managers/message.d.ts +16 -4
- package/dist/rest/index.js +2 -2
- package/dist/rest/index.js.map +1 -1
- package/dist/sharding/index.js +3 -2
- package/dist/sharding/index.js.map +4 -4
- package/dist/structures/base.d.ts +36 -0
- package/dist/structures/index.d.ts +38 -3
- package/dist/structures/index.js +240 -34
- package/dist/structures/index.js.map +11 -11
- package/dist/structures/interactions.d.ts +110 -12
- package/dist/structures/options.d.ts +2 -0
- package/dist/structures/resources.d.ts +40 -4
- package/dist/types/gateway.d.ts +14 -0
- package/dist/types/index.d.ts +185 -10
- package/dist/types/index.js +37 -10
- package/dist/types/index.js.map +4 -4
- package/dist/utils/args.d.ts +79 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +190 -2
- package/dist/utils/index.js.map +5 -4
- package/dist/ws/index.js +2 -1
- package/dist/ws/index.js.map +4 -4
- package/package.json +14 -14
package/dist/core/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/core/src/permissions.ts
|
|
3
|
-
var
|
|
4
|
-
((
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(
|
|
3
|
+
var PermissionOverwriteEnum;
|
|
4
|
+
((PermissionOverwriteEnum) => {
|
|
5
|
+
PermissionOverwriteEnum[PermissionOverwriteEnum["Role"] = 0] = "Role";
|
|
6
|
+
PermissionOverwriteEnum[PermissionOverwriteEnum["Member"] = 1] = "Member";
|
|
7
|
+
})(PermissionOverwriteEnum ||= {});
|
|
8
|
+
var PermissionOverwriteType = PermissionOverwriteEnum;
|
|
8
9
|
var Permission = {
|
|
9
10
|
createInstantInvite: 1n << 0n,
|
|
10
11
|
kickMembers: 1n << 1n,
|
|
@@ -396,6 +397,11 @@ class PermissionSet {
|
|
|
396
397
|
toArray() {
|
|
397
398
|
return Object.keys(Permission).filter((permission) => this.has(permission));
|
|
398
399
|
}
|
|
400
|
+
static #renamed = {
|
|
401
|
+
ManageEmojisAndStickers: "ManageGuildExpressions",
|
|
402
|
+
ManageEmojis: "ManageGuildExpressions",
|
|
403
|
+
UseSlashCommands: "UseApplicationCommands"
|
|
404
|
+
};
|
|
399
405
|
#resolve(permission) {
|
|
400
406
|
if (typeof permission === "bigint")
|
|
401
407
|
return permission;
|
|
@@ -410,6 +416,9 @@ class PermissionSet {
|
|
|
410
416
|
return bit;
|
|
411
417
|
}
|
|
412
418
|
if (typeof permission === "string") {
|
|
419
|
+
const renamed = PermissionSet.#renamed[permission];
|
|
420
|
+
if (renamed)
|
|
421
|
+
return this.#resolve(renamed);
|
|
413
422
|
if (permission in Permission)
|
|
414
423
|
return Permission[permission];
|
|
415
424
|
if (permission in Permissions)
|
|
@@ -794,7 +803,7 @@ class IntentsBitField {
|
|
|
794
803
|
}
|
|
795
804
|
}
|
|
796
805
|
// packages/types/src/index.ts
|
|
797
|
-
var
|
|
806
|
+
var InteractionResponseEnum = {
|
|
798
807
|
Pong: 1,
|
|
799
808
|
ChannelMessage: 4,
|
|
800
809
|
DeferredChannelMessage: 5,
|
|
@@ -1455,7 +1464,7 @@ class ResourceManager extends Manager {
|
|
|
1455
1464
|
// packages/rest/package.json
|
|
1456
1465
|
var package_default = {
|
|
1457
1466
|
name: "@lunibee/rest",
|
|
1458
|
-
version: "0.2.
|
|
1467
|
+
version: "0.2.2",
|
|
1459
1468
|
type: "module",
|
|
1460
1469
|
module: "./src/index.ts",
|
|
1461
1470
|
types: "./src/index.ts",
|
|
@@ -2263,6 +2272,11 @@ class Channel extends BaseStructure {
|
|
|
2263
2272
|
editTopic(topic) {
|
|
2264
2273
|
return this.edit({ topic });
|
|
2265
2274
|
}
|
|
2275
|
+
editPermissionOverwrite(targetId, changes, options) {
|
|
2276
|
+
if (!this.#context?.editPermissionOverwrite)
|
|
2277
|
+
throw new Error("This channel is not attached to a client.");
|
|
2278
|
+
return this.#context.editPermissionOverwrite(this.id, targetId, changes, options);
|
|
2279
|
+
}
|
|
2266
2280
|
editParent(parentId) {
|
|
2267
2281
|
return this.edit({ parent_id: parentId });
|
|
2268
2282
|
}
|
|
@@ -2397,6 +2411,7 @@ class Guild extends BaseStructure {
|
|
|
2397
2411
|
return this.name;
|
|
2398
2412
|
}
|
|
2399
2413
|
}
|
|
2414
|
+
|
|
2400
2415
|
// packages/structures/src/resources.ts
|
|
2401
2416
|
function toDateOrNull(value) {
|
|
2402
2417
|
if (!value)
|
|
@@ -2412,13 +2427,15 @@ class GuildMember {
|
|
|
2412
2427
|
roleIds;
|
|
2413
2428
|
pending;
|
|
2414
2429
|
joinedAt;
|
|
2415
|
-
permissions;
|
|
2416
2430
|
avatarHash;
|
|
2417
2431
|
premiumSince;
|
|
2418
2432
|
timedOutUntil;
|
|
2419
2433
|
flags;
|
|
2420
|
-
|
|
2434
|
+
#suppliedPermissions;
|
|
2435
|
+
#context;
|
|
2436
|
+
constructor(data, context) {
|
|
2421
2437
|
this.user = new User(data.user);
|
|
2438
|
+
this.#context = context;
|
|
2422
2439
|
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
2423
2440
|
throw new TypeError("Member guild_id must be a valid snowflake.");
|
|
2424
2441
|
this.guildId = data.guild_id;
|
|
@@ -2428,12 +2445,53 @@ class GuildMember {
|
|
|
2428
2445
|
this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
|
|
2429
2446
|
if (this.joinedAt?.toString() === "Invalid Date")
|
|
2430
2447
|
throw new RangeError("Member joined_at must be a valid date.");
|
|
2431
|
-
|
|
2448
|
+
if (data.permissions !== undefined)
|
|
2449
|
+
this.#suppliedPermissions = new PermissionsBitField(data.permissions);
|
|
2432
2450
|
this.avatarHash = data.avatar ?? null;
|
|
2433
2451
|
this.premiumSince = toDateOrNull(data.premium_since);
|
|
2434
2452
|
this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
|
|
2435
2453
|
this.flags = data.flags ?? 0;
|
|
2436
2454
|
}
|
|
2455
|
+
get permissions() {
|
|
2456
|
+
if (this.#suppliedPermissions)
|
|
2457
|
+
return this.#suppliedPermissions;
|
|
2458
|
+
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds) ?? 0n);
|
|
2459
|
+
}
|
|
2460
|
+
permissionsIn(channelId) {
|
|
2461
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId);
|
|
2462
|
+
return computed ? new PermissionsBitField(computed) : null;
|
|
2463
|
+
}
|
|
2464
|
+
#action(name) {
|
|
2465
|
+
const action = this.#context?.[name];
|
|
2466
|
+
if (!action)
|
|
2467
|
+
throw new Error("This member is not attached to a client.");
|
|
2468
|
+
return action;
|
|
2469
|
+
}
|
|
2470
|
+
kick(reason) {
|
|
2471
|
+
return this.#action("kickMember")(this.guildId, this.user.id, reason);
|
|
2472
|
+
}
|
|
2473
|
+
ban(options = {}) {
|
|
2474
|
+
return this.#action("banMember")(this.guildId, this.user.id, options);
|
|
2475
|
+
}
|
|
2476
|
+
edit(options, reason) {
|
|
2477
|
+
return this.#action("editMember")(this.guildId, this.user.id, options, reason);
|
|
2478
|
+
}
|
|
2479
|
+
timeout(milliseconds, reason) {
|
|
2480
|
+
if (milliseconds !== null && !(milliseconds > 0))
|
|
2481
|
+
throw new RangeError("Timeout length must be a positive number of milliseconds.");
|
|
2482
|
+
return this.edit({
|
|
2483
|
+
communication_disabled_until: milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString()
|
|
2484
|
+
}, reason);
|
|
2485
|
+
}
|
|
2486
|
+
setNickname(nickname, reason) {
|
|
2487
|
+
return this.edit({ nick: nickname }, reason);
|
|
2488
|
+
}
|
|
2489
|
+
addRole(roleId, reason) {
|
|
2490
|
+
return this.#action("addMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
2491
|
+
}
|
|
2492
|
+
removeRole(roleId, reason) {
|
|
2493
|
+
return this.#action("removeMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
2494
|
+
}
|
|
2437
2495
|
get displayName() {
|
|
2438
2496
|
return this.nickname ?? this.user.displayName;
|
|
2439
2497
|
}
|
|
@@ -2827,6 +2885,17 @@ class CommandOptions {
|
|
|
2827
2885
|
throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
|
|
2828
2886
|
return resolved;
|
|
2829
2887
|
}
|
|
2888
|
+
getMentionableType(name) {
|
|
2889
|
+
const opt = this.#get(name);
|
|
2890
|
+
if (!opt || opt.type !== OptionType.Mentionable)
|
|
2891
|
+
return null;
|
|
2892
|
+
const id = String(opt.value);
|
|
2893
|
+
if (this.#resolved?.users?.[id])
|
|
2894
|
+
return "user";
|
|
2895
|
+
if (this.#resolved?.roles?.[id])
|
|
2896
|
+
return "role";
|
|
2897
|
+
return null;
|
|
2898
|
+
}
|
|
2830
2899
|
getAttachment(name, required = false) {
|
|
2831
2900
|
const opt = this.#get(name);
|
|
2832
2901
|
if (!opt || opt.type !== OptionType.Attachment) {
|
|
@@ -2845,7 +2914,7 @@ class CommandOptions {
|
|
|
2845
2914
|
}
|
|
2846
2915
|
}
|
|
2847
2916
|
// packages/structures/src/interactions.ts
|
|
2848
|
-
var
|
|
2917
|
+
var InteractionEnum = {
|
|
2849
2918
|
Ping: 1,
|
|
2850
2919
|
ApplicationCommand: 2,
|
|
2851
2920
|
MessageComponent: 3,
|
|
@@ -2853,8 +2922,17 @@ var InteractionType = {
|
|
|
2853
2922
|
ModalSubmit: 5
|
|
2854
2923
|
};
|
|
2855
2924
|
var EPHEMERAL = 64;
|
|
2925
|
+
var COMMAND_CHAT_INPUT = 1;
|
|
2926
|
+
var COMMAND_USER = 2;
|
|
2927
|
+
var COMMAND_MESSAGE = 3;
|
|
2856
2928
|
var TOKEN_LIFETIME_MS = 15 * 60000;
|
|
2857
2929
|
var DISCORD_EPOCH = 1420070400000n;
|
|
2930
|
+
function splitWithResponse(options) {
|
|
2931
|
+
if (typeof options === "string")
|
|
2932
|
+
return { withResponse: false, rest: options };
|
|
2933
|
+
const { withResponse, ...rest } = options;
|
|
2934
|
+
return { withResponse: withResponse === true, rest };
|
|
2935
|
+
}
|
|
2858
2936
|
function toMessageData(options) {
|
|
2859
2937
|
if (typeof options === "string")
|
|
2860
2938
|
return { content: options };
|
|
@@ -2867,6 +2945,7 @@ function toMessageData(options) {
|
|
|
2867
2945
|
class InteractionResponse {
|
|
2868
2946
|
type;
|
|
2869
2947
|
data;
|
|
2948
|
+
withResponse = false;
|
|
2870
2949
|
constructor(type, data) {
|
|
2871
2950
|
if (!Number.isFinite(type))
|
|
2872
2951
|
throw new TypeError("Interaction response type must be finite.");
|
|
@@ -2877,13 +2956,13 @@ class InteractionResponse {
|
|
|
2877
2956
|
return this.data === undefined ? { type: this.type } : { type: this.type, data: this.data };
|
|
2878
2957
|
}
|
|
2879
2958
|
static message(options) {
|
|
2880
|
-
return new InteractionResponse(
|
|
2959
|
+
return new InteractionResponse(InteractionResponseEnum.ChannelMessage, toMessageData(options));
|
|
2881
2960
|
}
|
|
2882
2961
|
static defer(ephemeral = false) {
|
|
2883
|
-
return new InteractionResponse(
|
|
2962
|
+
return new InteractionResponse(InteractionResponseEnum.DeferredChannelMessage, ephemeral ? { flags: EPHEMERAL } : undefined);
|
|
2884
2963
|
}
|
|
2885
2964
|
static pong() {
|
|
2886
|
-
return new InteractionResponse(
|
|
2965
|
+
return new InteractionResponse(InteractionResponseEnum.Pong);
|
|
2887
2966
|
}
|
|
2888
2967
|
}
|
|
2889
2968
|
|
|
@@ -2911,17 +2990,53 @@ class Interaction {
|
|
|
2911
2990
|
this.type = data.type;
|
|
2912
2991
|
this.data = data;
|
|
2913
2992
|
}
|
|
2993
|
+
#commandType() {
|
|
2994
|
+
if (this.type !== InteractionEnum.ApplicationCommand)
|
|
2995
|
+
return 0;
|
|
2996
|
+
const type = this.data.data?.type;
|
|
2997
|
+
return typeof type === "number" ? type : COMMAND_CHAT_INPUT;
|
|
2998
|
+
}
|
|
2999
|
+
isCommand() {
|
|
3000
|
+
return this.type === InteractionEnum.ApplicationCommand;
|
|
3001
|
+
}
|
|
2914
3002
|
isChatInputCommand() {
|
|
2915
|
-
return this
|
|
3003
|
+
return this.#commandType() === COMMAND_CHAT_INPUT;
|
|
3004
|
+
}
|
|
3005
|
+
isContextMenuCommand() {
|
|
3006
|
+
const type = this.#commandType();
|
|
3007
|
+
return type === COMMAND_USER || type === COMMAND_MESSAGE;
|
|
3008
|
+
}
|
|
3009
|
+
isUserContextMenuCommand() {
|
|
3010
|
+
return this.#commandType() === COMMAND_USER;
|
|
3011
|
+
}
|
|
3012
|
+
isMessageContextMenuCommand() {
|
|
3013
|
+
return this.#commandType() === COMMAND_MESSAGE;
|
|
3014
|
+
}
|
|
3015
|
+
get resourceContext() {
|
|
3016
|
+
return this.#client.resourceContext;
|
|
3017
|
+
}
|
|
3018
|
+
awaitModalSubmit(options) {
|
|
3019
|
+
const collect = this.#client.resourceContext?.collectInteractions;
|
|
3020
|
+
if (!collect)
|
|
3021
|
+
return Promise.reject(new Error("This interaction is not attached to a client."));
|
|
3022
|
+
if (!(options.time > 0))
|
|
3023
|
+
return Promise.reject(new RangeError("awaitModalSubmit needs a positive time."));
|
|
3024
|
+
const userId = this.user?.id;
|
|
3025
|
+
const collector = collect({
|
|
3026
|
+
time: options.time,
|
|
3027
|
+
max: 1,
|
|
3028
|
+
filter: async (interaction) => interaction.isModalSubmit() && interaction.user?.id === userId && (options.customId === undefined || interaction.customId === options.customId) && (options.filter ? await options.filter(interaction) : true)
|
|
3029
|
+
});
|
|
3030
|
+
return collector.next();
|
|
2916
3031
|
}
|
|
2917
3032
|
isMessageComponent() {
|
|
2918
|
-
return this.type ===
|
|
3033
|
+
return this.type === InteractionEnum.MessageComponent;
|
|
2919
3034
|
}
|
|
2920
3035
|
isModalSubmit() {
|
|
2921
|
-
return this.type ===
|
|
3036
|
+
return this.type === InteractionEnum.ModalSubmit;
|
|
2922
3037
|
}
|
|
2923
3038
|
isAutocomplete() {
|
|
2924
|
-
return this.type ===
|
|
3039
|
+
return this.type === InteractionEnum.ApplicationCommandAutocomplete;
|
|
2925
3040
|
}
|
|
2926
3041
|
#componentType() {
|
|
2927
3042
|
return this.isMessageComponent() ? this.data.data?.component_type ?? 0 : 0;
|
|
@@ -2973,7 +3088,7 @@ class Interaction {
|
|
|
2973
3088
|
return new GuildMember({
|
|
2974
3089
|
...raw,
|
|
2975
3090
|
guild_id: this.guildId
|
|
2976
|
-
});
|
|
3091
|
+
}, this.#client.resourceContext);
|
|
2977
3092
|
}
|
|
2978
3093
|
get createdTimestamp() {
|
|
2979
3094
|
return Number((BigInt(this.id) >> 22n) + DISCORD_EPOCH);
|
|
@@ -3006,11 +3121,24 @@ class Interaction {
|
|
|
3006
3121
|
postResponse(response) {
|
|
3007
3122
|
return this.#client.postInteractionResponse(this.id, this.token, response);
|
|
3008
3123
|
}
|
|
3009
|
-
async
|
|
3010
|
-
|
|
3124
|
+
async acknowledgeWith(response, state, withResponse) {
|
|
3125
|
+
response.withResponse = withResponse;
|
|
3126
|
+
const result = await this.acknowledge(response, state);
|
|
3127
|
+
if (!withResponse)
|
|
3128
|
+
return result;
|
|
3129
|
+
const message = result?.resource?.message;
|
|
3130
|
+
return message ? new Message(message, this.#client.resourceContext) : null;
|
|
3011
3131
|
}
|
|
3012
|
-
async
|
|
3013
|
-
|
|
3132
|
+
async reply(options) {
|
|
3133
|
+
const { withResponse, rest } = splitWithResponse(options);
|
|
3134
|
+
return this.acknowledgeWith(InteractionResponse.message(toMessageData(rest)), "replied", withResponse);
|
|
3135
|
+
}
|
|
3136
|
+
async deferReply(options = false) {
|
|
3137
|
+
const ephemeral = typeof options === "boolean" ? options : options.ephemeral === true;
|
|
3138
|
+
const withResponse = typeof options === "object" && options.withResponse === true;
|
|
3139
|
+
const result = await this.acknowledgeWith(InteractionResponse.defer(ephemeral), "deferred", withResponse);
|
|
3140
|
+
if (withResponse)
|
|
3141
|
+
return result;
|
|
3014
3142
|
}
|
|
3015
3143
|
editReply(options) {
|
|
3016
3144
|
this.assertAcknowledged();
|
|
@@ -3024,10 +3152,12 @@ class Interaction {
|
|
|
3024
3152
|
return this.#client.followUpInteraction(this.token, toMessageData(options));
|
|
3025
3153
|
}
|
|
3026
3154
|
async update(options) {
|
|
3027
|
-
|
|
3155
|
+
const { withResponse, rest } = splitWithResponse(options);
|
|
3156
|
+
return this.acknowledgeWith(new InteractionResponse(InteractionResponseEnum.MessageUpdate, toMessageData(rest)), "replied", withResponse);
|
|
3028
3157
|
}
|
|
3029
3158
|
async showModal(modal) {
|
|
3030
|
-
|
|
3159
|
+
const data = "toJSON" in modal && typeof modal.toJSON === "function" ? modal.toJSON() : modal;
|
|
3160
|
+
return this.acknowledge(new InteractionResponse(InteractionResponseEnum.Modal, data), "replied");
|
|
3031
3161
|
}
|
|
3032
3162
|
}
|
|
3033
3163
|
|
|
@@ -3044,21 +3174,56 @@ class CommandInteraction extends Interaction {
|
|
|
3044
3174
|
}
|
|
3045
3175
|
}
|
|
3046
3176
|
|
|
3177
|
+
class ContextMenuCommandInteraction extends CommandInteraction {
|
|
3178
|
+
#resolved() {
|
|
3179
|
+
return this.data.data?.resolved ?? {};
|
|
3180
|
+
}
|
|
3181
|
+
get targetId() {
|
|
3182
|
+
const id = this.data.data?.target_id;
|
|
3183
|
+
return typeof id === "string" ? id : null;
|
|
3184
|
+
}
|
|
3185
|
+
get targetUser() {
|
|
3186
|
+
const id = this.targetId;
|
|
3187
|
+
const raw = id ? this.#resolved().users?.[id] : undefined;
|
|
3188
|
+
return raw ? new User(raw) : null;
|
|
3189
|
+
}
|
|
3190
|
+
get targetMember() {
|
|
3191
|
+
const id = this.targetId;
|
|
3192
|
+
const raw = id ? this.#resolved().members?.[id] : undefined;
|
|
3193
|
+
const user = id ? this.#resolved().users?.[id] : undefined;
|
|
3194
|
+
if (!raw || !user || !this.guildId)
|
|
3195
|
+
return null;
|
|
3196
|
+
return new GuildMember({
|
|
3197
|
+
...raw,
|
|
3198
|
+
user,
|
|
3199
|
+
guild_id: this.guildId
|
|
3200
|
+
}, this.resourceContext);
|
|
3201
|
+
}
|
|
3202
|
+
get targetMessage() {
|
|
3203
|
+
const id = this.targetId;
|
|
3204
|
+
const raw = id ? this.#resolved().messages?.[id] : undefined;
|
|
3205
|
+
return raw ? new Message(raw, this.resourceContext) : null;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3047
3209
|
class ComponentInteraction extends Interaction {
|
|
3048
3210
|
get customId() {
|
|
3049
3211
|
return this.data?.data?.custom_id ?? "";
|
|
3050
3212
|
}
|
|
3213
|
+
get messageId() {
|
|
3214
|
+
return this.data?.message?.id;
|
|
3215
|
+
}
|
|
3051
3216
|
get componentType() {
|
|
3052
3217
|
return this.data?.data?.component_type ?? 0;
|
|
3053
3218
|
}
|
|
3054
3219
|
get values() {
|
|
3055
3220
|
return this.data?.data?.values ?? [];
|
|
3056
3221
|
}
|
|
3057
|
-
async deferUpdate() {
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3222
|
+
async deferUpdate(options = {}) {
|
|
3223
|
+
const withResponse = options.withResponse === true;
|
|
3224
|
+
const result = await this.acknowledgeWith(new InteractionResponse(InteractionResponseEnum.DeferredMessageUpdate), "deferred", withResponse);
|
|
3225
|
+
if (withResponse)
|
|
3226
|
+
return result;
|
|
3062
3227
|
}
|
|
3063
3228
|
}
|
|
3064
3229
|
|
|
@@ -3100,7 +3265,7 @@ class AutocompleteInteraction extends Interaction {
|
|
|
3100
3265
|
async respond(choices) {
|
|
3101
3266
|
if (!Array.isArray(choices))
|
|
3102
3267
|
throw new TypeError("Autocomplete choices must be an array.");
|
|
3103
|
-
const response = new InteractionResponse(
|
|
3268
|
+
const response = new InteractionResponse(InteractionResponseEnum.Autocomplete, { choices });
|
|
3104
3269
|
await this.acknowledge(response, "replied");
|
|
3105
3270
|
}
|
|
3106
3271
|
}
|
|
@@ -3118,13 +3283,15 @@ function findFocused(options) {
|
|
|
3118
3283
|
}
|
|
3119
3284
|
function createInteraction(client, data) {
|
|
3120
3285
|
switch (data.type) {
|
|
3121
|
-
case
|
|
3122
|
-
|
|
3123
|
-
|
|
3286
|
+
case InteractionEnum.ApplicationCommand: {
|
|
3287
|
+
const commandType = data.data?.type;
|
|
3288
|
+
return commandType === COMMAND_USER || commandType === COMMAND_MESSAGE ? new ContextMenuCommandInteraction(client, data) : new CommandInteraction(client, data);
|
|
3289
|
+
}
|
|
3290
|
+
case InteractionEnum.ApplicationCommandAutocomplete:
|
|
3124
3291
|
return new AutocompleteInteraction(client, data);
|
|
3125
|
-
case
|
|
3292
|
+
case InteractionEnum.MessageComponent:
|
|
3126
3293
|
return new ComponentInteraction(client, data);
|
|
3127
|
-
case
|
|
3294
|
+
case InteractionEnum.ModalSubmit:
|
|
3128
3295
|
return new ModalSubmitInteraction(client, data);
|
|
3129
3296
|
default:
|
|
3130
3297
|
return new Interaction(client, data);
|
|
@@ -3132,6 +3299,7 @@ function createInteraction(client, data) {
|
|
|
3132
3299
|
}
|
|
3133
3300
|
|
|
3134
3301
|
// packages/structures/src/index.ts
|
|
3302
|
+
var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
|
|
3135
3303
|
var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
|
|
3136
3304
|
|
|
3137
3305
|
class Message extends BaseStructure {
|
|
@@ -3152,6 +3320,10 @@ class Message extends BaseStructure {
|
|
|
3152
3320
|
reference;
|
|
3153
3321
|
components;
|
|
3154
3322
|
referencedMessage;
|
|
3323
|
+
stickers;
|
|
3324
|
+
poll;
|
|
3325
|
+
messageSnapshots;
|
|
3326
|
+
member;
|
|
3155
3327
|
#context;
|
|
3156
3328
|
constructor(data, context) {
|
|
3157
3329
|
super(data.id);
|
|
@@ -3172,8 +3344,20 @@ class Message extends BaseStructure {
|
|
|
3172
3344
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
3173
3345
|
this.type = data.type ?? 0;
|
|
3174
3346
|
this.reference = data.message_reference;
|
|
3347
|
+
this.stickers = data.sticker_items ?? (data.stickers ?? []).map(({ id, name, format_type }) => ({
|
|
3348
|
+
id,
|
|
3349
|
+
name,
|
|
3350
|
+
format_type
|
|
3351
|
+
}));
|
|
3352
|
+
this.poll = data.poll ?? null;
|
|
3353
|
+
this.messageSnapshots = data.message_snapshots ?? [];
|
|
3175
3354
|
this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
|
|
3176
3355
|
this.#context = context;
|
|
3356
|
+
this.member = data.member && data.guild_id ? new GuildMember({
|
|
3357
|
+
...data.member,
|
|
3358
|
+
user: data.member.user ?? data.author,
|
|
3359
|
+
guild_id: data.guild_id
|
|
3360
|
+
}, context) : null;
|
|
3177
3361
|
this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
|
|
3178
3362
|
}
|
|
3179
3363
|
get embedsSuppressed() {
|
|
@@ -3214,6 +3398,20 @@ class Message extends BaseStructure {
|
|
|
3214
3398
|
throw new Error("This message is not attached to a client.");
|
|
3215
3399
|
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
3216
3400
|
}
|
|
3401
|
+
createComponentCollector(options = {}) {
|
|
3402
|
+
const collect = this.#context?.collectInteractions;
|
|
3403
|
+
if (!collect)
|
|
3404
|
+
throw new Error("This message is not attached to a client.");
|
|
3405
|
+
const { componentType, filter, ...rest } = options;
|
|
3406
|
+
return collect({
|
|
3407
|
+
...rest,
|
|
3408
|
+
time: rest.time ?? (rest.idle ? undefined : COMPONENT_COLLECTOR_DEFAULT_TIME),
|
|
3409
|
+
filter: async (interaction) => interaction.isMessageComponent() && interaction.messageId === this.id && (componentType === undefined || interaction.componentType === componentType) && (filter ? await filter(interaction) : true)
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
awaitComponent(options = {}) {
|
|
3413
|
+
return this.createComponentCollector({ ...options, max: 1 }).next();
|
|
3414
|
+
}
|
|
3217
3415
|
react(emoji) {
|
|
3218
3416
|
if (!this.#context?.addReaction)
|
|
3219
3417
|
throw new Error("This message is not attached to a client.");
|
|
@@ -3287,15 +3485,33 @@ class Message extends BaseStructure {
|
|
|
3287
3485
|
}
|
|
3288
3486
|
|
|
3289
3487
|
// packages/managers/src/message.ts
|
|
3488
|
+
function toRequest(options, allowedMentions) {
|
|
3489
|
+
const { files, ...body } = options;
|
|
3490
|
+
if (allowedMentions !== undefined && body.allowed_mentions === undefined)
|
|
3491
|
+
body.allowed_mentions = allowedMentions;
|
|
3492
|
+
if (!files?.length)
|
|
3493
|
+
return body;
|
|
3494
|
+
return {
|
|
3495
|
+
body,
|
|
3496
|
+
files: files.map((file) => ({
|
|
3497
|
+
name: file.name,
|
|
3498
|
+
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
3499
|
+
contentType: file.contentType
|
|
3500
|
+
}))
|
|
3501
|
+
};
|
|
3502
|
+
}
|
|
3503
|
+
|
|
3290
3504
|
class MessageManager {
|
|
3291
3505
|
cache;
|
|
3292
3506
|
#caching;
|
|
3293
3507
|
#rest;
|
|
3294
3508
|
#context;
|
|
3295
3509
|
#channelId;
|
|
3296
|
-
|
|
3510
|
+
#allowedMentions;
|
|
3511
|
+
constructor(rest, context, channelId, cache, allowedMentions) {
|
|
3297
3512
|
if (!channelId)
|
|
3298
3513
|
throw new TypeError("Channel ID is required.");
|
|
3514
|
+
this.#allowedMentions = allowedMentions;
|
|
3299
3515
|
this.#rest = rest;
|
|
3300
3516
|
this.#context = context;
|
|
3301
3517
|
this.#channelId = channelId;
|
|
@@ -3309,7 +3525,7 @@ class MessageManager {
|
|
|
3309
3525
|
return this.cache.get(messageId) ?? this.fetch(messageId);
|
|
3310
3526
|
}
|
|
3311
3527
|
async send(options) {
|
|
3312
|
-
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), options);
|
|
3528
|
+
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), toRequest(options, this.#allowedMentions));
|
|
3313
3529
|
return this.upsert(data);
|
|
3314
3530
|
}
|
|
3315
3531
|
async fetch(messageId) {
|
|
@@ -3590,14 +3806,20 @@ class MonetizationManager extends Manager {
|
|
|
3590
3806
|
// packages/managers/src/member.ts
|
|
3591
3807
|
class GuildMemberManager extends ResourceManager {
|
|
3592
3808
|
#rest;
|
|
3809
|
+
#context;
|
|
3593
3810
|
guildId;
|
|
3594
|
-
constructor(guildId, rest) {
|
|
3595
|
-
|
|
3811
|
+
constructor(guildId, rest, context = () => {
|
|
3812
|
+
return;
|
|
3813
|
+
}) {
|
|
3814
|
+
super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id);
|
|
3596
3815
|
this.guildId = guildId;
|
|
3597
3816
|
this.#rest = rest;
|
|
3817
|
+
this.#context = context;
|
|
3598
3818
|
}
|
|
3599
|
-
async kick(userId) {
|
|
3600
|
-
await this.#rest.delete(Routes.guildMember(this.guildId, userId)
|
|
3819
|
+
async kick(userId, reason) {
|
|
3820
|
+
await this.#rest.delete(Routes.guildMember(this.guildId, userId), {
|
|
3821
|
+
reason
|
|
3822
|
+
});
|
|
3601
3823
|
this.delete(userId);
|
|
3602
3824
|
}
|
|
3603
3825
|
async ban(userId, options = {}) {
|
|
@@ -3607,21 +3829,21 @@ class GuildMemberManager extends ResourceManager {
|
|
|
3607
3829
|
async unban(userId) {
|
|
3608
3830
|
await this.#rest.delete(Routes.guildBan(this.guildId, userId));
|
|
3609
3831
|
}
|
|
3610
|
-
async edit(userId, options) {
|
|
3611
|
-
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options);
|
|
3612
|
-
const member = new GuildMember({ ...data, guild_id: this.guildId });
|
|
3832
|
+
async edit(userId, options, reason) {
|
|
3833
|
+
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options, { reason });
|
|
3834
|
+
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
3613
3835
|
this.set(member.user.id, member);
|
|
3614
3836
|
return member;
|
|
3615
3837
|
}
|
|
3616
|
-
async addRole(userId, roleId) {
|
|
3617
|
-
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
3838
|
+
async addRole(userId, roleId, reason) {
|
|
3839
|
+
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId), undefined, { reason });
|
|
3618
3840
|
}
|
|
3619
|
-
async removeRole(userId, roleId) {
|
|
3620
|
-
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
3841
|
+
async removeRole(userId, roleId, reason) {
|
|
3842
|
+
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId), { reason });
|
|
3621
3843
|
}
|
|
3622
|
-
async timeout(userId, milliseconds) {
|
|
3844
|
+
async timeout(userId, milliseconds, reason) {
|
|
3623
3845
|
const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
|
|
3624
|
-
return this.edit(userId, { communication_disabled_until: timeoutDate });
|
|
3846
|
+
return this.edit(userId, { communication_disabled_until: timeoutDate }, reason);
|
|
3625
3847
|
}
|
|
3626
3848
|
}
|
|
3627
3849
|
|
|
@@ -3792,10 +4014,25 @@ class StageInstanceManager extends Manager {
|
|
|
3792
4014
|
|
|
3793
4015
|
class PermissionOverwriteManager {
|
|
3794
4016
|
#rest;
|
|
4017
|
+
#current;
|
|
3795
4018
|
channelId;
|
|
3796
|
-
constructor(rest, channelId) {
|
|
4019
|
+
constructor(rest, channelId, current = () => {
|
|
4020
|
+
return;
|
|
4021
|
+
}) {
|
|
3797
4022
|
this.#rest = rest;
|
|
3798
4023
|
this.channelId = channelId;
|
|
4024
|
+
this.#current = current;
|
|
4025
|
+
}
|
|
4026
|
+
async update(overwriteId, changes, options = {}) {
|
|
4027
|
+
const overwrites = this.#current() ?? (await this.#rest.get(Routes.channel(this.channelId))).permission_overwrites ?? [];
|
|
4028
|
+
const existing = overwrites.find((entry) => entry.id === overwriteId);
|
|
4029
|
+
const type = existing?.type ?? options.type;
|
|
4030
|
+
if (type !== 0 && type !== 1)
|
|
4031
|
+
throw new TypeError("A new permission overwrite needs a type: 0 for a role, 1 for a member.");
|
|
4032
|
+
const touched = (changes.allow ?? 0n) | (changes.deny ?? 0n) | (changes.inherit ?? 0n);
|
|
4033
|
+
const allow = BigInt(existing?.allow ?? 0) & ~touched | (changes.allow ?? 0n);
|
|
4034
|
+
const deny = BigInt(existing?.deny ?? 0) & ~touched | (changes.deny ?? 0n);
|
|
4035
|
+
await this.edit(overwriteId, { type, allow, deny }, options.reason);
|
|
3799
4036
|
}
|
|
3800
4037
|
async edit(overwriteId, options, reason) {
|
|
3801
4038
|
await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
|
|
@@ -3827,6 +4064,10 @@ class GuildManager extends ResourceManager {
|
|
|
3827
4064
|
#voiceStates = new Map;
|
|
3828
4065
|
#autoModerationRules = new Map;
|
|
3829
4066
|
#invites = new Map;
|
|
4067
|
+
#context;
|
|
4068
|
+
attachContext(context) {
|
|
4069
|
+
this.#context = context;
|
|
4070
|
+
}
|
|
3830
4071
|
#perGuild(map, guildId, create) {
|
|
3831
4072
|
let manager = map.get(guildId);
|
|
3832
4073
|
if (!manager)
|
|
@@ -3852,7 +4093,7 @@ class GuildManager extends ResourceManager {
|
|
|
3852
4093
|
members(guildId) {
|
|
3853
4094
|
let manager = this.#members.get(guildId);
|
|
3854
4095
|
if (!manager)
|
|
3855
|
-
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest));
|
|
4096
|
+
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context));
|
|
3856
4097
|
return manager;
|
|
3857
4098
|
}
|
|
3858
4099
|
roles(guildId) {
|
|
@@ -4027,10 +4268,12 @@ class ChannelManager extends Manager {
|
|
|
4027
4268
|
#context;
|
|
4028
4269
|
#messageManagers = new Map;
|
|
4029
4270
|
#messageCache;
|
|
4271
|
+
#allowedMentions;
|
|
4030
4272
|
constructor(rest, options = {}) {
|
|
4031
4273
|
super();
|
|
4032
4274
|
this.#rest = rest;
|
|
4033
4275
|
this.#messageCache = options.messageCache;
|
|
4276
|
+
this.#allowedMentions = options.allowedMentions;
|
|
4034
4277
|
this.#context = {
|
|
4035
4278
|
sendMessage: (channelId, options) => this.send(channelId, options),
|
|
4036
4279
|
editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
|
|
@@ -4049,13 +4292,13 @@ class ChannelManager extends Manager {
|
|
|
4049
4292
|
messages(channelId) {
|
|
4050
4293
|
let manager = this.#messageManagers.get(channelId);
|
|
4051
4294
|
if (!manager) {
|
|
4052
|
-
manager = new MessageManager(this.#rest, this.#context, channelId, this.#messageCache);
|
|
4295
|
+
manager = new MessageManager(this.#rest, this.#context, channelId, this.#messageCache, this.#allowedMentions);
|
|
4053
4296
|
this.#messageManagers.set(channelId, manager);
|
|
4054
4297
|
}
|
|
4055
4298
|
return manager;
|
|
4056
4299
|
}
|
|
4057
4300
|
permissionOverwrites(channelId) {
|
|
4058
|
-
return new PermissionOverwriteManager(this.#rest, channelId);
|
|
4301
|
+
return new PermissionOverwriteManager(this.#rest, channelId, () => this.get(channelId)?.permissionOverwrites);
|
|
4059
4302
|
}
|
|
4060
4303
|
threads(channelId) {
|
|
4061
4304
|
return new ThreadManager(this.#rest, this.#context, channelId);
|
|
@@ -4155,7 +4398,7 @@ class ChannelManager extends Manager {
|
|
|
4155
4398
|
return this.messages(data.channel_id).upsert(data);
|
|
4156
4399
|
}
|
|
4157
4400
|
async editMessage(channelId, messageId, options) {
|
|
4158
|
-
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), options));
|
|
4401
|
+
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
|
|
4159
4402
|
}
|
|
4160
4403
|
async deleteMessage(channelId, messageId) {
|
|
4161
4404
|
await this.#rest.delete(Routes.message(channelId, messageId));
|
|
@@ -5192,6 +5435,7 @@ class Gateway {
|
|
|
5192
5435
|
#message(raw, token) {
|
|
5193
5436
|
if (!this.#session.owns(token))
|
|
5194
5437
|
return;
|
|
5438
|
+
this.#heartbeat.receivedMessage();
|
|
5195
5439
|
const { sequence, action } = classifyFrame(raw);
|
|
5196
5440
|
if (sequence !== null)
|
|
5197
5441
|
this.#session.recordSequence(sequence, token);
|
|
@@ -5460,7 +5704,8 @@ class Client extends EventEmitter2 {
|
|
|
5460
5704
|
this.users = new UserManager(this.rest);
|
|
5461
5705
|
this.guilds = new GuildManager(this.rest);
|
|
5462
5706
|
this.channels = new ChannelManager(this.rest, {
|
|
5463
|
-
messageCache: options.messageCache
|
|
5707
|
+
messageCache: options.messageCache,
|
|
5708
|
+
allowedMentions: options.allowedMentions
|
|
5464
5709
|
});
|
|
5465
5710
|
this.stageInstances = new StageInstanceManager(this.rest);
|
|
5466
5711
|
const placeholderAppCommands = new ApplicationCommandManager(this.rest, "0");
|
|
@@ -5477,8 +5722,32 @@ class Client extends EventEmitter2 {
|
|
|
5477
5722
|
removeReaction: (channelId, messageId, emoji, userId) => this.channels.removeReaction(channelId, messageId, emoji, userId),
|
|
5478
5723
|
removeAllReactions: (channelId, messageId) => this.channels.removeAllReactions(channelId, messageId),
|
|
5479
5724
|
pinMessage: (channelId, messageId) => this.channels.pinMessage(channelId, messageId),
|
|
5480
|
-
unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId)
|
|
5725
|
+
unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId),
|
|
5726
|
+
collectInteractions: (options) => this.createCollector("interactionCreate" /* InteractionCreate */, options),
|
|
5727
|
+
memberPermissions: (guildId, memberId, roleIds, channelId) => this.#memberPermissions(guildId, memberId, roleIds, channelId),
|
|
5728
|
+
kickMember: (guildId, userId, reason) => this.guilds.members(guildId).kick(userId, reason),
|
|
5729
|
+
banMember: (guildId, userId, options) => this.guilds.members(guildId).ban(userId, options),
|
|
5730
|
+
editMember: (guildId, userId, options, reason) => this.guilds.members(guildId).edit(userId, options, reason),
|
|
5731
|
+
addMemberRole: (guildId, userId, roleId, reason) => this.guilds.members(guildId).addRole(userId, roleId, reason),
|
|
5732
|
+
removeMemberRole: (guildId, userId, roleId, reason) => this.guilds.members(guildId).removeRole(userId, roleId, reason),
|
|
5733
|
+
editPermissionOverwrite: async (channelId, targetId, changes, options) => {
|
|
5734
|
+
const bits = { allow: 0n, deny: 0n, inherit: 0n };
|
|
5735
|
+
for (const [name, value] of Object.entries(changes)) {
|
|
5736
|
+
if (!/^[A-Za-z]+$/.test(name))
|
|
5737
|
+
throw new TypeError(`Unknown permission: ${name}`);
|
|
5738
|
+
let bit;
|
|
5739
|
+
try {
|
|
5740
|
+
bit = new PermissionSet(name).bitfield;
|
|
5741
|
+
} catch {
|
|
5742
|
+
throw new TypeError(`Unknown permission: ${name}`);
|
|
5743
|
+
}
|
|
5744
|
+
const key = value === true ? "allow" : value === false ? "deny" : "inherit";
|
|
5745
|
+
bits[key] |= bit;
|
|
5746
|
+
}
|
|
5747
|
+
return this.channels.permissionOverwrites(channelId).update(targetId, bits, options);
|
|
5748
|
+
}
|
|
5481
5749
|
};
|
|
5750
|
+
this.guilds.attachContext(this.#resourceContext);
|
|
5482
5751
|
this.#gateway = new Gateway({
|
|
5483
5752
|
token: options.token,
|
|
5484
5753
|
intents: options.intents,
|
|
@@ -5510,8 +5779,14 @@ class Client extends EventEmitter2 {
|
|
|
5510
5779
|
this.emit("close" /* Close */, data);
|
|
5511
5780
|
});
|
|
5512
5781
|
this.#gateway.on("MESSAGE_CREATE", (data) => {
|
|
5513
|
-
const
|
|
5782
|
+
const payload = data;
|
|
5783
|
+
const message = new Message(payload, this.#resourceContext);
|
|
5514
5784
|
this.#observeMessage(message);
|
|
5785
|
+
if (payload.member && payload.guild_id && this.guilds.has(payload.guild_id))
|
|
5786
|
+
this.#upsertMember(payload.guild_id, {
|
|
5787
|
+
...payload.member,
|
|
5788
|
+
user: payload.member.user ?? payload.author
|
|
5789
|
+
});
|
|
5515
5790
|
const cached = this.options.messageCache ? this.channels.messages(message.channelId).upsert(data) : message;
|
|
5516
5791
|
this.emit("messageCreate" /* MessageCreate */, cached);
|
|
5517
5792
|
});
|
|
@@ -5577,8 +5852,11 @@ class Client extends EventEmitter2 {
|
|
|
5577
5852
|
this.emit(wasCached ? "guildAvailable" /* GuildAvailable */ : "guildCreate" /* GuildCreate */, payload);
|
|
5578
5853
|
});
|
|
5579
5854
|
this.#gateway.on("GUILD_UPDATE", (data) => {
|
|
5580
|
-
|
|
5581
|
-
this.
|
|
5855
|
+
const payload = data;
|
|
5856
|
+
const cached = this.guilds.get(payload.id);
|
|
5857
|
+
const previous = cached ? this.#snapshot(cached) : null;
|
|
5858
|
+
this.guilds.patch(payload);
|
|
5859
|
+
this.emit("guildUpdate" /* GuildUpdate */, payload, previous);
|
|
5582
5860
|
});
|
|
5583
5861
|
this.#gateway.on("GUILD_DELETE", (data) => {
|
|
5584
5862
|
const payload = data;
|
|
@@ -5597,8 +5875,10 @@ class Client extends EventEmitter2 {
|
|
|
5597
5875
|
});
|
|
5598
5876
|
this.#gateway.on("GUILD_MEMBER_UPDATE", (data) => {
|
|
5599
5877
|
const member = data;
|
|
5878
|
+
const cached = this.#cache.members ? this.guilds.members(member.guild_id).get(member.user.id) : undefined;
|
|
5879
|
+
const previous = cached ? this.#snapshot(cached, new GuildMember({ user: member.user, guild_id: member.guild_id }, this.#resourceContext)) : null;
|
|
5600
5880
|
this.#upsertMember(member.guild_id, member);
|
|
5601
|
-
this.emit("guildMemberUpdate" /* GuildMemberUpdate */, member);
|
|
5881
|
+
this.emit("guildMemberUpdate" /* GuildMemberUpdate */, member, previous);
|
|
5602
5882
|
});
|
|
5603
5883
|
this.#gateway.on("GUILD_MEMBER_REMOVE", (data) => {
|
|
5604
5884
|
const member = data;
|
|
@@ -5633,18 +5913,24 @@ class Client extends EventEmitter2 {
|
|
|
5633
5913
|
});
|
|
5634
5914
|
this.#gateway.on("GUILD_ROLE_UPDATE", (data) => {
|
|
5635
5915
|
const event = data;
|
|
5916
|
+
const cached = this.#cache.roles ? this.guilds.roles(event.guild_id).get(event.role.id) : undefined;
|
|
5917
|
+
const previous = cached ? this.#snapshot(cached) : null;
|
|
5636
5918
|
this.#upsertRole(event.guild_id, event.role);
|
|
5637
|
-
this.emit("guildRoleUpdate" /* GuildRoleUpdate */, event);
|
|
5919
|
+
this.emit("guildRoleUpdate" /* GuildRoleUpdate */, event, previous);
|
|
5638
5920
|
});
|
|
5639
5921
|
this.#gateway.on("GUILD_ROLE_DELETE", (data) => {
|
|
5640
5922
|
const event = data;
|
|
5641
|
-
this.guilds.roles(event.guild_id)
|
|
5642
|
-
|
|
5923
|
+
const roles = this.guilds.roles(event.guild_id);
|
|
5924
|
+
const removed = roles.get(event.role_id) ?? null;
|
|
5925
|
+
roles.delete(event.role_id);
|
|
5926
|
+
this.emit("guildRoleDelete" /* GuildRoleDelete */, event, removed);
|
|
5643
5927
|
});
|
|
5644
5928
|
this.#gateway.on("GUILD_EMOJIS_UPDATE", (data) => {
|
|
5645
5929
|
const event = data;
|
|
5930
|
+
let previous = null;
|
|
5646
5931
|
if (this.#cache.emojis) {
|
|
5647
5932
|
const emojis = this.guilds.emojis(event.guild_id);
|
|
5933
|
+
previous = [...emojis.cache.values()].map((emoji) => this.#snapshot(emoji));
|
|
5648
5934
|
const current = new Set(event.emojis.map((emoji) => emoji.id));
|
|
5649
5935
|
for (const id of [...emojis.cache.keys()])
|
|
5650
5936
|
if (!current.has(id))
|
|
@@ -5652,12 +5938,14 @@ class Client extends EventEmitter2 {
|
|
|
5652
5938
|
for (const emoji of event.emojis)
|
|
5653
5939
|
emojis.upsert(emoji);
|
|
5654
5940
|
}
|
|
5655
|
-
this.emit("guildEmojisUpdate" /* GuildEmojisUpdate */, event);
|
|
5941
|
+
this.emit("guildEmojisUpdate" /* GuildEmojisUpdate */, event, previous);
|
|
5656
5942
|
});
|
|
5657
5943
|
this.#gateway.on("GUILD_STICKERS_UPDATE", (data) => {
|
|
5658
5944
|
const event = data;
|
|
5659
|
-
this.guilds.stickers(event.guild_id)
|
|
5660
|
-
|
|
5945
|
+
const stickers = this.guilds.stickers(event.guild_id);
|
|
5946
|
+
const previous = [...stickers.cache.values()];
|
|
5947
|
+
stickers.sync(event.stickers);
|
|
5948
|
+
this.emit("guildStickersUpdate" /* GuildStickersUpdate */, event, previous);
|
|
5661
5949
|
});
|
|
5662
5950
|
this.#gateway.on("GUILD_SOUNDBOARD_SOUND_CREATE", (data) => {
|
|
5663
5951
|
const sound = data;
|
|
@@ -5738,13 +6026,15 @@ class Client extends EventEmitter2 {
|
|
|
5738
6026
|
this.emit("channelCreate" /* ChannelCreate */, channel);
|
|
5739
6027
|
});
|
|
5740
6028
|
this.#gateway.on("CHANNEL_UPDATE", (data) => {
|
|
6029
|
+
const previous = this.#previousChannel(data);
|
|
5741
6030
|
const channel = this.channels.upsert(data);
|
|
5742
|
-
this.emit("channelUpdate" /* ChannelUpdate */, channel);
|
|
6031
|
+
this.emit("channelUpdate" /* ChannelUpdate */, channel, previous);
|
|
5743
6032
|
});
|
|
5744
6033
|
this.#gateway.on("CHANNEL_DELETE", (data) => {
|
|
5745
6034
|
const payload = data;
|
|
6035
|
+
const removed = this.channels.get(payload.id) ?? null;
|
|
5746
6036
|
this.channels.delete(payload.id);
|
|
5747
|
-
this.emit("channelDelete" /* ChannelDelete */, payload);
|
|
6037
|
+
this.emit("channelDelete" /* ChannelDelete */, payload, removed);
|
|
5748
6038
|
});
|
|
5749
6039
|
this.#gateway.on("CHANNEL_PINS_UPDATE", (data) => this.emit("channelPinsUpdate" /* ChannelPinsUpdate */, data));
|
|
5750
6040
|
this.#gateway.on("THREAD_CREATE", (data) => {
|
|
@@ -5752,13 +6042,15 @@ class Client extends EventEmitter2 {
|
|
|
5752
6042
|
this.emit("threadCreate" /* ThreadCreate */, channel);
|
|
5753
6043
|
});
|
|
5754
6044
|
this.#gateway.on("THREAD_UPDATE", (data) => {
|
|
6045
|
+
const previous = this.#previousChannel(data);
|
|
5755
6046
|
const channel = this.channels.upsert(data);
|
|
5756
|
-
this.emit("threadUpdate" /* ThreadUpdate */, channel);
|
|
6047
|
+
this.emit("threadUpdate" /* ThreadUpdate */, channel, previous);
|
|
5757
6048
|
});
|
|
5758
6049
|
this.#gateway.on("THREAD_DELETE", (data) => {
|
|
5759
6050
|
const payload = data;
|
|
6051
|
+
const removed = this.channels.get(payload.id) ?? null;
|
|
5760
6052
|
this.channels.delete(payload.id);
|
|
5761
|
-
this.emit("threadDelete" /* ThreadDelete */, payload);
|
|
6053
|
+
this.emit("threadDelete" /* ThreadDelete */, payload, removed);
|
|
5762
6054
|
});
|
|
5763
6055
|
this.#gateway.on("THREAD_LIST_SYNC", (data) => {
|
|
5764
6056
|
const sync = data;
|
|
@@ -5816,7 +6108,7 @@ class Client extends EventEmitter2 {
|
|
|
5816
6108
|
this.#merge(this.users, message.author.id, message.author);
|
|
5817
6109
|
}
|
|
5818
6110
|
#upsertMember(guildId, data) {
|
|
5819
|
-
const member = new GuildMember({ ...data, guild_id: guildId });
|
|
6111
|
+
const member = new GuildMember({ ...data, guild_id: guildId }, this.#resourceContext);
|
|
5820
6112
|
if (this.#cache.users)
|
|
5821
6113
|
this.#merge(this.users, member.user.id, member.user);
|
|
5822
6114
|
if (!this.#cache.members)
|
|
@@ -5835,6 +6127,15 @@ class Client extends EventEmitter2 {
|
|
|
5835
6127
|
return new Role(data);
|
|
5836
6128
|
return this.#merge(this.guilds.roles(guildId), data.id, new Role(data));
|
|
5837
6129
|
}
|
|
6130
|
+
#snapshot(cached, blank = Object.create(Object.getPrototypeOf(cached))) {
|
|
6131
|
+
return Object.assign(blank, cached);
|
|
6132
|
+
}
|
|
6133
|
+
#previousChannel(data) {
|
|
6134
|
+
const cached = this.channels.get(data.id);
|
|
6135
|
+
if (!cached)
|
|
6136
|
+
return null;
|
|
6137
|
+
return this.#snapshot(cached, createChannel({ id: cached.id, type: cached.type, guild_id: cached.guildId }, this.#resourceContext));
|
|
6138
|
+
}
|
|
5838
6139
|
#merge(manager, id, next) {
|
|
5839
6140
|
const existing = manager.get(id);
|
|
5840
6141
|
if (!existing) {
|
|
@@ -5859,6 +6160,29 @@ class Client extends EventEmitter2 {
|
|
|
5859
6160
|
collector.onDispose(() => this.off(event, listener));
|
|
5860
6161
|
return collector;
|
|
5861
6162
|
}
|
|
6163
|
+
get resourceContext() {
|
|
6164
|
+
return this.#resourceContext;
|
|
6165
|
+
}
|
|
6166
|
+
#memberPermissions(guildId, memberId, roleIds, channelId) {
|
|
6167
|
+
const guild = this.guilds.get(guildId);
|
|
6168
|
+
if (!guild)
|
|
6169
|
+
return null;
|
|
6170
|
+
let channel = channelId ? this.channels.get(channelId) : undefined;
|
|
6171
|
+
if (channelId) {
|
|
6172
|
+
if (channel?.isThread())
|
|
6173
|
+
channel = channel.parentId ? this.channels.get(channel.parentId) : undefined;
|
|
6174
|
+
if (!channel || channel.guildId !== guildId)
|
|
6175
|
+
return null;
|
|
6176
|
+
}
|
|
6177
|
+
return computePermissions({
|
|
6178
|
+
guildId,
|
|
6179
|
+
ownerId: guild.ownerId,
|
|
6180
|
+
memberId,
|
|
6181
|
+
memberRoleIds: [...roleIds],
|
|
6182
|
+
roles: this.guilds.roles(guildId).values(),
|
|
6183
|
+
overwrites: channel?.permissionOverwrites
|
|
6184
|
+
});
|
|
6185
|
+
}
|
|
5862
6186
|
permissionsFor(memberId, guildOrChannelId) {
|
|
5863
6187
|
let channel = this.channels.get(guildOrChannelId);
|
|
5864
6188
|
if (channel?.isThread()) {
|
|
@@ -5902,12 +6226,23 @@ class Client extends EventEmitter2 {
|
|
|
5902
6226
|
this.#gateway.close();
|
|
5903
6227
|
}
|
|
5904
6228
|
postInteractionResponse(id, token, response) {
|
|
5905
|
-
|
|
6229
|
+
const json = response.toJSON();
|
|
6230
|
+
const callback = response.withResponse ? `${Routes.interactionCallback(id, token)}?with_response=true` : Routes.interactionCallback(id, token);
|
|
6231
|
+
const carriesMessage = json.type === 4 || json.type === 7;
|
|
6232
|
+
const upload = json.data ? toRequest(json.data, carriesMessage ? this.options.allowedMentions : undefined) : undefined;
|
|
6233
|
+
if (upload && typeof upload === "object" && "files" in upload) {
|
|
6234
|
+
const { body, files } = upload;
|
|
6235
|
+
return this.rest.post(callback, {
|
|
6236
|
+
body: { ...json, data: body },
|
|
6237
|
+
files
|
|
6238
|
+
});
|
|
6239
|
+
}
|
|
6240
|
+
return this.rest.post(callback, upload === undefined ? json : { ...json, data: upload });
|
|
5906
6241
|
}
|
|
5907
6242
|
editInteractionReply(token, data) {
|
|
5908
6243
|
if (!this.user)
|
|
5909
6244
|
return Promise.reject(new Error("Client is unauthenticated."));
|
|
5910
|
-
return this.rest.patch(Routes.interactionOriginalResponse(this.user.id, token), data);
|
|
6245
|
+
return this.rest.patch(Routes.interactionOriginalResponse(this.user.id, token), toRequest(data, this.options.allowedMentions));
|
|
5911
6246
|
}
|
|
5912
6247
|
deleteInteractionReply(token) {
|
|
5913
6248
|
if (!this.user)
|
|
@@ -5917,14 +6252,14 @@ class Client extends EventEmitter2 {
|
|
|
5917
6252
|
followUpInteraction(token, data) {
|
|
5918
6253
|
if (!this.user)
|
|
5919
6254
|
return Promise.reject(new Error("Client is unauthenticated."));
|
|
5920
|
-
return this.rest.post(`/webhooks/${this.user.id}/${token}`, data);
|
|
6255
|
+
return this.rest.post(`/webhooks/${this.user.id}/${token}`, toRequest(data, this.options.allowedMentions));
|
|
5921
6256
|
}
|
|
5922
6257
|
interactionWebhookMessage(method, applicationId, token, messageId, data) {
|
|
5923
6258
|
const path = messageId === "@original" ? Routes.interactionOriginalResponse(applicationId, token) : Routes.webhookMessage(applicationId, token, messageId);
|
|
5924
6259
|
if (method === "GET")
|
|
5925
6260
|
return this.rest.get(path);
|
|
5926
6261
|
if (method === "PATCH")
|
|
5927
|
-
return this.rest.patch(path, data);
|
|
6262
|
+
return this.rest.patch(path, data ? toRequest(data, this.options.allowedMentions) : data);
|
|
5928
6263
|
return this.rest.delete(path);
|
|
5929
6264
|
}
|
|
5930
6265
|
fetchWebhook(id, token) {
|
|
@@ -5980,6 +6315,7 @@ export {
|
|
|
5980
6315
|
IntentsBitField,
|
|
5981
6316
|
Permission,
|
|
5982
6317
|
PermissionFlagsBits,
|
|
6318
|
+
PermissionOverwriteEnum,
|
|
5983
6319
|
PermissionOverwriteType,
|
|
5984
6320
|
PermissionSet,
|
|
5985
6321
|
Permissions,
|
|
@@ -5988,4 +6324,4 @@ export {
|
|
|
5988
6324
|
resolveGatewayIntents
|
|
5989
6325
|
};
|
|
5990
6326
|
|
|
5991
|
-
//# debugId=
|
|
6327
|
+
//# debugId=A5606C420611230B64756E2164756E21
|