lunibee 0.2.0 → 0.2.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/dist/builders/components.d.ts +25 -2
- package/dist/builders/embed.d.ts +7 -7
- package/dist/builders/index.d.ts +1 -1
- package/dist/builders/index.js +39 -7
- package/dist/builders/index.js.map +5 -5
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +241 -32
- package/dist/core/index.js.map +15 -15
- package/dist/index.js +468 -38
- package/dist/index.js.map +20 -19
- package/dist/managers/guild-resources.d.ts +22 -2
- package/dist/managers/guild.d.ts +3 -1
- package/dist/managers/index.d.ts +2 -2
- package/dist/managers/index.js +142 -24
- package/dist/managers/index.js.map +12 -12
- package/dist/managers/member.d.ts +13 -12
- package/dist/managers/message.d.ts +11 -3
- package/dist/rest/index.js +2 -2
- package/dist/rest/index.js.map +1 -1
- package/dist/sharding/index.js +2 -2
- package/dist/sharding/index.js.map +1 -1
- package/dist/structures/base.d.ts +36 -0
- package/dist/structures/index.d.ts +29 -0
- package/dist/structures/index.js +116 -8
- package/dist/structures/index.js.map +10 -10
- package/dist/structures/interactions.d.ts +26 -2
- package/dist/structures/options.d.ts +2 -0
- package/dist/structures/resources.d.ts +29 -3
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js.map +2 -2
- 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/package.json +14 -14
package/dist/core/index.js
CHANGED
|
@@ -396,6 +396,11 @@ class PermissionSet {
|
|
|
396
396
|
toArray() {
|
|
397
397
|
return Object.keys(Permission).filter((permission) => this.has(permission));
|
|
398
398
|
}
|
|
399
|
+
static #renamed = {
|
|
400
|
+
ManageEmojisAndStickers: "ManageGuildExpressions",
|
|
401
|
+
ManageEmojis: "ManageGuildExpressions",
|
|
402
|
+
UseSlashCommands: "UseApplicationCommands"
|
|
403
|
+
};
|
|
399
404
|
#resolve(permission) {
|
|
400
405
|
if (typeof permission === "bigint")
|
|
401
406
|
return permission;
|
|
@@ -410,6 +415,9 @@ class PermissionSet {
|
|
|
410
415
|
return bit;
|
|
411
416
|
}
|
|
412
417
|
if (typeof permission === "string") {
|
|
418
|
+
const renamed = PermissionSet.#renamed[permission];
|
|
419
|
+
if (renamed)
|
|
420
|
+
return this.#resolve(renamed);
|
|
413
421
|
if (permission in Permission)
|
|
414
422
|
return Permission[permission];
|
|
415
423
|
if (permission in Permissions)
|
|
@@ -1455,7 +1463,7 @@ class ResourceManager extends Manager {
|
|
|
1455
1463
|
// packages/rest/package.json
|
|
1456
1464
|
var package_default = {
|
|
1457
1465
|
name: "@lunibee/rest",
|
|
1458
|
-
version: "0.2.
|
|
1466
|
+
version: "0.2.1",
|
|
1459
1467
|
type: "module",
|
|
1460
1468
|
module: "./src/index.ts",
|
|
1461
1469
|
types: "./src/index.ts",
|
|
@@ -2263,6 +2271,11 @@ class Channel extends BaseStructure {
|
|
|
2263
2271
|
editTopic(topic) {
|
|
2264
2272
|
return this.edit({ topic });
|
|
2265
2273
|
}
|
|
2274
|
+
editPermissionOverwrite(targetId, changes, options) {
|
|
2275
|
+
if (!this.#context?.editPermissionOverwrite)
|
|
2276
|
+
throw new Error("This channel is not attached to a client.");
|
|
2277
|
+
return this.#context.editPermissionOverwrite(this.id, targetId, changes, options);
|
|
2278
|
+
}
|
|
2266
2279
|
editParent(parentId) {
|
|
2267
2280
|
return this.edit({ parent_id: parentId });
|
|
2268
2281
|
}
|
|
@@ -2397,6 +2410,7 @@ class Guild extends BaseStructure {
|
|
|
2397
2410
|
return this.name;
|
|
2398
2411
|
}
|
|
2399
2412
|
}
|
|
2413
|
+
|
|
2400
2414
|
// packages/structures/src/resources.ts
|
|
2401
2415
|
function toDateOrNull(value) {
|
|
2402
2416
|
if (!value)
|
|
@@ -2412,13 +2426,15 @@ class GuildMember {
|
|
|
2412
2426
|
roleIds;
|
|
2413
2427
|
pending;
|
|
2414
2428
|
joinedAt;
|
|
2415
|
-
permissions;
|
|
2416
2429
|
avatarHash;
|
|
2417
2430
|
premiumSince;
|
|
2418
2431
|
timedOutUntil;
|
|
2419
2432
|
flags;
|
|
2420
|
-
|
|
2433
|
+
#suppliedPermissions;
|
|
2434
|
+
#context;
|
|
2435
|
+
constructor(data, context) {
|
|
2421
2436
|
this.user = new User(data.user);
|
|
2437
|
+
this.#context = context;
|
|
2422
2438
|
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
2423
2439
|
throw new TypeError("Member guild_id must be a valid snowflake.");
|
|
2424
2440
|
this.guildId = data.guild_id;
|
|
@@ -2428,12 +2444,53 @@ class GuildMember {
|
|
|
2428
2444
|
this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
|
|
2429
2445
|
if (this.joinedAt?.toString() === "Invalid Date")
|
|
2430
2446
|
throw new RangeError("Member joined_at must be a valid date.");
|
|
2431
|
-
|
|
2447
|
+
if (data.permissions !== undefined)
|
|
2448
|
+
this.#suppliedPermissions = new PermissionsBitField(data.permissions);
|
|
2432
2449
|
this.avatarHash = data.avatar ?? null;
|
|
2433
2450
|
this.premiumSince = toDateOrNull(data.premium_since);
|
|
2434
2451
|
this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
|
|
2435
2452
|
this.flags = data.flags ?? 0;
|
|
2436
2453
|
}
|
|
2454
|
+
get permissions() {
|
|
2455
|
+
if (this.#suppliedPermissions)
|
|
2456
|
+
return this.#suppliedPermissions;
|
|
2457
|
+
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds) ?? 0n);
|
|
2458
|
+
}
|
|
2459
|
+
permissionsIn(channelId) {
|
|
2460
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId);
|
|
2461
|
+
return computed ? new PermissionsBitField(computed) : null;
|
|
2462
|
+
}
|
|
2463
|
+
#action(name) {
|
|
2464
|
+
const action = this.#context?.[name];
|
|
2465
|
+
if (!action)
|
|
2466
|
+
throw new Error("This member is not attached to a client.");
|
|
2467
|
+
return action;
|
|
2468
|
+
}
|
|
2469
|
+
kick(reason) {
|
|
2470
|
+
return this.#action("kickMember")(this.guildId, this.user.id, reason);
|
|
2471
|
+
}
|
|
2472
|
+
ban(options = {}) {
|
|
2473
|
+
return this.#action("banMember")(this.guildId, this.user.id, options);
|
|
2474
|
+
}
|
|
2475
|
+
edit(options, reason) {
|
|
2476
|
+
return this.#action("editMember")(this.guildId, this.user.id, options, reason);
|
|
2477
|
+
}
|
|
2478
|
+
timeout(milliseconds, reason) {
|
|
2479
|
+
if (milliseconds !== null && !(milliseconds > 0))
|
|
2480
|
+
throw new RangeError("Timeout length must be a positive number of milliseconds.");
|
|
2481
|
+
return this.edit({
|
|
2482
|
+
communication_disabled_until: milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString()
|
|
2483
|
+
}, reason);
|
|
2484
|
+
}
|
|
2485
|
+
setNickname(nickname, reason) {
|
|
2486
|
+
return this.edit({ nick: nickname }, reason);
|
|
2487
|
+
}
|
|
2488
|
+
addRole(roleId, reason) {
|
|
2489
|
+
return this.#action("addMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
2490
|
+
}
|
|
2491
|
+
removeRole(roleId, reason) {
|
|
2492
|
+
return this.#action("removeMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
2493
|
+
}
|
|
2437
2494
|
get displayName() {
|
|
2438
2495
|
return this.nickname ?? this.user.displayName;
|
|
2439
2496
|
}
|
|
@@ -2827,6 +2884,17 @@ class CommandOptions {
|
|
|
2827
2884
|
throw new TypeError(`Resolved mentionable for option "${name}" is missing.`);
|
|
2828
2885
|
return resolved;
|
|
2829
2886
|
}
|
|
2887
|
+
getMentionableType(name) {
|
|
2888
|
+
const opt = this.#get(name);
|
|
2889
|
+
if (!opt || opt.type !== OptionType.Mentionable)
|
|
2890
|
+
return null;
|
|
2891
|
+
const id = String(opt.value);
|
|
2892
|
+
if (this.#resolved?.users?.[id])
|
|
2893
|
+
return "user";
|
|
2894
|
+
if (this.#resolved?.roles?.[id])
|
|
2895
|
+
return "role";
|
|
2896
|
+
return null;
|
|
2897
|
+
}
|
|
2830
2898
|
getAttachment(name, required = false) {
|
|
2831
2899
|
const opt = this.#get(name);
|
|
2832
2900
|
if (!opt || opt.type !== OptionType.Attachment) {
|
|
@@ -2914,6 +2982,20 @@ class Interaction {
|
|
|
2914
2982
|
isChatInputCommand() {
|
|
2915
2983
|
return this.type === InteractionType.ApplicationCommand;
|
|
2916
2984
|
}
|
|
2985
|
+
awaitModalSubmit(options) {
|
|
2986
|
+
const collect = this.#client.resourceContext?.collectInteractions;
|
|
2987
|
+
if (!collect)
|
|
2988
|
+
return Promise.reject(new Error("This interaction is not attached to a client."));
|
|
2989
|
+
if (!(options.time > 0))
|
|
2990
|
+
return Promise.reject(new RangeError("awaitModalSubmit needs a positive time."));
|
|
2991
|
+
const userId = this.user?.id;
|
|
2992
|
+
const collector = collect({
|
|
2993
|
+
time: options.time,
|
|
2994
|
+
max: 1,
|
|
2995
|
+
filter: async (interaction) => interaction.isModalSubmit() && interaction.user?.id === userId && (options.customId === undefined || interaction.customId === options.customId) && (options.filter ? await options.filter(interaction) : true)
|
|
2996
|
+
});
|
|
2997
|
+
return collector.next();
|
|
2998
|
+
}
|
|
2917
2999
|
isMessageComponent() {
|
|
2918
3000
|
return this.type === InteractionType.MessageComponent;
|
|
2919
3001
|
}
|
|
@@ -2973,7 +3055,7 @@ class Interaction {
|
|
|
2973
3055
|
return new GuildMember({
|
|
2974
3056
|
...raw,
|
|
2975
3057
|
guild_id: this.guildId
|
|
2976
|
-
});
|
|
3058
|
+
}, this.#client.resourceContext);
|
|
2977
3059
|
}
|
|
2978
3060
|
get createdTimestamp() {
|
|
2979
3061
|
return Number((BigInt(this.id) >> 22n) + DISCORD_EPOCH);
|
|
@@ -3009,7 +3091,8 @@ class Interaction {
|
|
|
3009
3091
|
async reply(options) {
|
|
3010
3092
|
return this.acknowledge(InteractionResponse.message(toMessageData(options)), "replied");
|
|
3011
3093
|
}
|
|
3012
|
-
async deferReply(
|
|
3094
|
+
async deferReply(options = false) {
|
|
3095
|
+
const ephemeral = typeof options === "boolean" ? options : options.ephemeral === true;
|
|
3013
3096
|
await this.acknowledge(InteractionResponse.defer(ephemeral), "deferred");
|
|
3014
3097
|
}
|
|
3015
3098
|
editReply(options) {
|
|
@@ -3027,7 +3110,8 @@ class Interaction {
|
|
|
3027
3110
|
return this.acknowledge(new InteractionResponse(InteractionResponseType.MessageUpdate, toMessageData(options)), "replied");
|
|
3028
3111
|
}
|
|
3029
3112
|
async showModal(modal) {
|
|
3030
|
-
|
|
3113
|
+
const data = "toJSON" in modal && typeof modal.toJSON === "function" ? modal.toJSON() : modal;
|
|
3114
|
+
return this.acknowledge(new InteractionResponse(InteractionResponseType.Modal, data), "replied");
|
|
3031
3115
|
}
|
|
3032
3116
|
}
|
|
3033
3117
|
|
|
@@ -3048,6 +3132,9 @@ class ComponentInteraction extends Interaction {
|
|
|
3048
3132
|
get customId() {
|
|
3049
3133
|
return this.data?.data?.custom_id ?? "";
|
|
3050
3134
|
}
|
|
3135
|
+
get messageId() {
|
|
3136
|
+
return this.data?.message?.id;
|
|
3137
|
+
}
|
|
3051
3138
|
get componentType() {
|
|
3052
3139
|
return this.data?.data?.component_type ?? 0;
|
|
3053
3140
|
}
|
|
@@ -3132,6 +3219,7 @@ function createInteraction(client, data) {
|
|
|
3132
3219
|
}
|
|
3133
3220
|
|
|
3134
3221
|
// packages/structures/src/index.ts
|
|
3222
|
+
var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
|
|
3135
3223
|
var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
|
|
3136
3224
|
|
|
3137
3225
|
class Message extends BaseStructure {
|
|
@@ -3152,6 +3240,7 @@ class Message extends BaseStructure {
|
|
|
3152
3240
|
reference;
|
|
3153
3241
|
components;
|
|
3154
3242
|
referencedMessage;
|
|
3243
|
+
member;
|
|
3155
3244
|
#context;
|
|
3156
3245
|
constructor(data, context) {
|
|
3157
3246
|
super(data.id);
|
|
@@ -3174,6 +3263,11 @@ class Message extends BaseStructure {
|
|
|
3174
3263
|
this.reference = data.message_reference;
|
|
3175
3264
|
this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
|
|
3176
3265
|
this.#context = context;
|
|
3266
|
+
this.member = data.member && data.guild_id ? new GuildMember({
|
|
3267
|
+
...data.member,
|
|
3268
|
+
user: data.member.user ?? data.author,
|
|
3269
|
+
guild_id: data.guild_id
|
|
3270
|
+
}, context) : null;
|
|
3177
3271
|
this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
|
|
3178
3272
|
}
|
|
3179
3273
|
get embedsSuppressed() {
|
|
@@ -3214,6 +3308,20 @@ class Message extends BaseStructure {
|
|
|
3214
3308
|
throw new Error("This message is not attached to a client.");
|
|
3215
3309
|
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
3216
3310
|
}
|
|
3311
|
+
createComponentCollector(options = {}) {
|
|
3312
|
+
const collect = this.#context?.collectInteractions;
|
|
3313
|
+
if (!collect)
|
|
3314
|
+
throw new Error("This message is not attached to a client.");
|
|
3315
|
+
const { componentType, filter, ...rest } = options;
|
|
3316
|
+
return collect({
|
|
3317
|
+
...rest,
|
|
3318
|
+
time: rest.time ?? (rest.idle ? undefined : COMPONENT_COLLECTOR_DEFAULT_TIME),
|
|
3319
|
+
filter: async (interaction) => interaction.isMessageComponent() && interaction.messageId === this.id && (componentType === undefined || interaction.componentType === componentType) && (filter ? await filter(interaction) : true)
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
awaitComponent(options = {}) {
|
|
3323
|
+
return this.createComponentCollector({ ...options, max: 1 }).next();
|
|
3324
|
+
}
|
|
3217
3325
|
react(emoji) {
|
|
3218
3326
|
if (!this.#context?.addReaction)
|
|
3219
3327
|
throw new Error("This message is not attached to a client.");
|
|
@@ -3287,6 +3395,20 @@ class Message extends BaseStructure {
|
|
|
3287
3395
|
}
|
|
3288
3396
|
|
|
3289
3397
|
// packages/managers/src/message.ts
|
|
3398
|
+
function toRequest(options) {
|
|
3399
|
+
const { files, ...body } = options;
|
|
3400
|
+
if (!files?.length)
|
|
3401
|
+
return body;
|
|
3402
|
+
return {
|
|
3403
|
+
body,
|
|
3404
|
+
files: files.map((file) => ({
|
|
3405
|
+
name: file.name,
|
|
3406
|
+
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
3407
|
+
contentType: file.contentType
|
|
3408
|
+
}))
|
|
3409
|
+
};
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3290
3412
|
class MessageManager {
|
|
3291
3413
|
cache;
|
|
3292
3414
|
#caching;
|
|
@@ -3309,7 +3431,7 @@ class MessageManager {
|
|
|
3309
3431
|
return this.cache.get(messageId) ?? this.fetch(messageId);
|
|
3310
3432
|
}
|
|
3311
3433
|
async send(options) {
|
|
3312
|
-
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), options);
|
|
3434
|
+
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), toRequest(options));
|
|
3313
3435
|
return this.upsert(data);
|
|
3314
3436
|
}
|
|
3315
3437
|
async fetch(messageId) {
|
|
@@ -3590,14 +3712,20 @@ class MonetizationManager extends Manager {
|
|
|
3590
3712
|
// packages/managers/src/member.ts
|
|
3591
3713
|
class GuildMemberManager extends ResourceManager {
|
|
3592
3714
|
#rest;
|
|
3715
|
+
#context;
|
|
3593
3716
|
guildId;
|
|
3594
|
-
constructor(guildId, rest) {
|
|
3595
|
-
|
|
3717
|
+
constructor(guildId, rest, context = () => {
|
|
3718
|
+
return;
|
|
3719
|
+
}) {
|
|
3720
|
+
super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id);
|
|
3596
3721
|
this.guildId = guildId;
|
|
3597
3722
|
this.#rest = rest;
|
|
3723
|
+
this.#context = context;
|
|
3598
3724
|
}
|
|
3599
|
-
async kick(userId) {
|
|
3600
|
-
await this.#rest.delete(Routes.guildMember(this.guildId, userId)
|
|
3725
|
+
async kick(userId, reason) {
|
|
3726
|
+
await this.#rest.delete(Routes.guildMember(this.guildId, userId), {
|
|
3727
|
+
reason
|
|
3728
|
+
});
|
|
3601
3729
|
this.delete(userId);
|
|
3602
3730
|
}
|
|
3603
3731
|
async ban(userId, options = {}) {
|
|
@@ -3607,21 +3735,21 @@ class GuildMemberManager extends ResourceManager {
|
|
|
3607
3735
|
async unban(userId) {
|
|
3608
3736
|
await this.#rest.delete(Routes.guildBan(this.guildId, userId));
|
|
3609
3737
|
}
|
|
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 });
|
|
3738
|
+
async edit(userId, options, reason) {
|
|
3739
|
+
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options, { reason });
|
|
3740
|
+
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
3613
3741
|
this.set(member.user.id, member);
|
|
3614
3742
|
return member;
|
|
3615
3743
|
}
|
|
3616
|
-
async addRole(userId, roleId) {
|
|
3617
|
-
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
3744
|
+
async addRole(userId, roleId, reason) {
|
|
3745
|
+
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId), undefined, { reason });
|
|
3618
3746
|
}
|
|
3619
|
-
async removeRole(userId, roleId) {
|
|
3620
|
-
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
3747
|
+
async removeRole(userId, roleId, reason) {
|
|
3748
|
+
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId), { reason });
|
|
3621
3749
|
}
|
|
3622
|
-
async timeout(userId, milliseconds) {
|
|
3750
|
+
async timeout(userId, milliseconds, reason) {
|
|
3623
3751
|
const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
|
|
3624
|
-
return this.edit(userId, { communication_disabled_until: timeoutDate });
|
|
3752
|
+
return this.edit(userId, { communication_disabled_until: timeoutDate }, reason);
|
|
3625
3753
|
}
|
|
3626
3754
|
}
|
|
3627
3755
|
|
|
@@ -3792,10 +3920,25 @@ class StageInstanceManager extends Manager {
|
|
|
3792
3920
|
|
|
3793
3921
|
class PermissionOverwriteManager {
|
|
3794
3922
|
#rest;
|
|
3923
|
+
#current;
|
|
3795
3924
|
channelId;
|
|
3796
|
-
constructor(rest, channelId) {
|
|
3925
|
+
constructor(rest, channelId, current = () => {
|
|
3926
|
+
return;
|
|
3927
|
+
}) {
|
|
3797
3928
|
this.#rest = rest;
|
|
3798
3929
|
this.channelId = channelId;
|
|
3930
|
+
this.#current = current;
|
|
3931
|
+
}
|
|
3932
|
+
async update(overwriteId, changes, options = {}) {
|
|
3933
|
+
const overwrites = this.#current() ?? (await this.#rest.get(Routes.channel(this.channelId))).permission_overwrites ?? [];
|
|
3934
|
+
const existing = overwrites.find((entry) => entry.id === overwriteId);
|
|
3935
|
+
const type = existing?.type ?? options.type;
|
|
3936
|
+
if (type !== 0 && type !== 1)
|
|
3937
|
+
throw new TypeError("A new permission overwrite needs a type: 0 for a role, 1 for a member.");
|
|
3938
|
+
const touched = (changes.allow ?? 0n) | (changes.deny ?? 0n) | (changes.inherit ?? 0n);
|
|
3939
|
+
const allow = BigInt(existing?.allow ?? 0) & ~touched | (changes.allow ?? 0n);
|
|
3940
|
+
const deny = BigInt(existing?.deny ?? 0) & ~touched | (changes.deny ?? 0n);
|
|
3941
|
+
await this.edit(overwriteId, { type, allow, deny }, options.reason);
|
|
3799
3942
|
}
|
|
3800
3943
|
async edit(overwriteId, options, reason) {
|
|
3801
3944
|
await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
|
|
@@ -3827,6 +3970,10 @@ class GuildManager extends ResourceManager {
|
|
|
3827
3970
|
#voiceStates = new Map;
|
|
3828
3971
|
#autoModerationRules = new Map;
|
|
3829
3972
|
#invites = new Map;
|
|
3973
|
+
#context;
|
|
3974
|
+
attachContext(context) {
|
|
3975
|
+
this.#context = context;
|
|
3976
|
+
}
|
|
3830
3977
|
#perGuild(map, guildId, create) {
|
|
3831
3978
|
let manager = map.get(guildId);
|
|
3832
3979
|
if (!manager)
|
|
@@ -3852,7 +3999,7 @@ class GuildManager extends ResourceManager {
|
|
|
3852
3999
|
members(guildId) {
|
|
3853
4000
|
let manager = this.#members.get(guildId);
|
|
3854
4001
|
if (!manager)
|
|
3855
|
-
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest));
|
|
4002
|
+
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context));
|
|
3856
4003
|
return manager;
|
|
3857
4004
|
}
|
|
3858
4005
|
roles(guildId) {
|
|
@@ -4055,7 +4202,7 @@ class ChannelManager extends Manager {
|
|
|
4055
4202
|
return manager;
|
|
4056
4203
|
}
|
|
4057
4204
|
permissionOverwrites(channelId) {
|
|
4058
|
-
return new PermissionOverwriteManager(this.#rest, channelId);
|
|
4205
|
+
return new PermissionOverwriteManager(this.#rest, channelId, () => this.get(channelId)?.permissionOverwrites);
|
|
4059
4206
|
}
|
|
4060
4207
|
threads(channelId) {
|
|
4061
4208
|
return new ThreadManager(this.#rest, this.#context, channelId);
|
|
@@ -4155,7 +4302,7 @@ class ChannelManager extends Manager {
|
|
|
4155
4302
|
return this.messages(data.channel_id).upsert(data);
|
|
4156
4303
|
}
|
|
4157
4304
|
async editMessage(channelId, messageId, options) {
|
|
4158
|
-
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), options));
|
|
4305
|
+
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options)));
|
|
4159
4306
|
}
|
|
4160
4307
|
async deleteMessage(channelId, messageId) {
|
|
4161
4308
|
await this.#rest.delete(Routes.message(channelId, messageId));
|
|
@@ -5477,8 +5624,32 @@ class Client extends EventEmitter2 {
|
|
|
5477
5624
|
removeReaction: (channelId, messageId, emoji, userId) => this.channels.removeReaction(channelId, messageId, emoji, userId),
|
|
5478
5625
|
removeAllReactions: (channelId, messageId) => this.channels.removeAllReactions(channelId, messageId),
|
|
5479
5626
|
pinMessage: (channelId, messageId) => this.channels.pinMessage(channelId, messageId),
|
|
5480
|
-
unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId)
|
|
5627
|
+
unpinMessage: (channelId, messageId) => this.channels.unpinMessage(channelId, messageId),
|
|
5628
|
+
collectInteractions: (options) => this.createCollector("interactionCreate" /* InteractionCreate */, options),
|
|
5629
|
+
memberPermissions: (guildId, memberId, roleIds, channelId) => this.#memberPermissions(guildId, memberId, roleIds, channelId),
|
|
5630
|
+
kickMember: (guildId, userId, reason) => this.guilds.members(guildId).kick(userId, reason),
|
|
5631
|
+
banMember: (guildId, userId, options) => this.guilds.members(guildId).ban(userId, options),
|
|
5632
|
+
editMember: (guildId, userId, options, reason) => this.guilds.members(guildId).edit(userId, options, reason),
|
|
5633
|
+
addMemberRole: (guildId, userId, roleId, reason) => this.guilds.members(guildId).addRole(userId, roleId, reason),
|
|
5634
|
+
removeMemberRole: (guildId, userId, roleId, reason) => this.guilds.members(guildId).removeRole(userId, roleId, reason),
|
|
5635
|
+
editPermissionOverwrite: async (channelId, targetId, changes, options) => {
|
|
5636
|
+
const bits = { allow: 0n, deny: 0n, inherit: 0n };
|
|
5637
|
+
for (const [name, value] of Object.entries(changes)) {
|
|
5638
|
+
if (!/^[A-Za-z]+$/.test(name))
|
|
5639
|
+
throw new TypeError(`Unknown permission: ${name}`);
|
|
5640
|
+
let bit;
|
|
5641
|
+
try {
|
|
5642
|
+
bit = new PermissionSet(name).bitfield;
|
|
5643
|
+
} catch {
|
|
5644
|
+
throw new TypeError(`Unknown permission: ${name}`);
|
|
5645
|
+
}
|
|
5646
|
+
const key = value === true ? "allow" : value === false ? "deny" : "inherit";
|
|
5647
|
+
bits[key] |= bit;
|
|
5648
|
+
}
|
|
5649
|
+
return this.channels.permissionOverwrites(channelId).update(targetId, bits, options);
|
|
5650
|
+
}
|
|
5481
5651
|
};
|
|
5652
|
+
this.guilds.attachContext(this.#resourceContext);
|
|
5482
5653
|
this.#gateway = new Gateway({
|
|
5483
5654
|
token: options.token,
|
|
5484
5655
|
intents: options.intents,
|
|
@@ -5510,8 +5681,14 @@ class Client extends EventEmitter2 {
|
|
|
5510
5681
|
this.emit("close" /* Close */, data);
|
|
5511
5682
|
});
|
|
5512
5683
|
this.#gateway.on("MESSAGE_CREATE", (data) => {
|
|
5513
|
-
const
|
|
5684
|
+
const payload = data;
|
|
5685
|
+
const message = new Message(payload, this.#resourceContext);
|
|
5514
5686
|
this.#observeMessage(message);
|
|
5687
|
+
if (payload.member && payload.guild_id && this.guilds.has(payload.guild_id))
|
|
5688
|
+
this.#upsertMember(payload.guild_id, {
|
|
5689
|
+
...payload.member,
|
|
5690
|
+
user: payload.member.user ?? payload.author
|
|
5691
|
+
});
|
|
5515
5692
|
const cached = this.options.messageCache ? this.channels.messages(message.channelId).upsert(data) : message;
|
|
5516
5693
|
this.emit("messageCreate" /* MessageCreate */, cached);
|
|
5517
5694
|
});
|
|
@@ -5816,7 +5993,7 @@ class Client extends EventEmitter2 {
|
|
|
5816
5993
|
this.#merge(this.users, message.author.id, message.author);
|
|
5817
5994
|
}
|
|
5818
5995
|
#upsertMember(guildId, data) {
|
|
5819
|
-
const member = new GuildMember({ ...data, guild_id: guildId });
|
|
5996
|
+
const member = new GuildMember({ ...data, guild_id: guildId }, this.#resourceContext);
|
|
5820
5997
|
if (this.#cache.users)
|
|
5821
5998
|
this.#merge(this.users, member.user.id, member.user);
|
|
5822
5999
|
if (!this.#cache.members)
|
|
@@ -5859,6 +6036,29 @@ class Client extends EventEmitter2 {
|
|
|
5859
6036
|
collector.onDispose(() => this.off(event, listener));
|
|
5860
6037
|
return collector;
|
|
5861
6038
|
}
|
|
6039
|
+
get resourceContext() {
|
|
6040
|
+
return this.#resourceContext;
|
|
6041
|
+
}
|
|
6042
|
+
#memberPermissions(guildId, memberId, roleIds, channelId) {
|
|
6043
|
+
const guild = this.guilds.get(guildId);
|
|
6044
|
+
if (!guild)
|
|
6045
|
+
return null;
|
|
6046
|
+
let channel = channelId ? this.channels.get(channelId) : undefined;
|
|
6047
|
+
if (channelId) {
|
|
6048
|
+
if (channel?.isThread())
|
|
6049
|
+
channel = channel.parentId ? this.channels.get(channel.parentId) : undefined;
|
|
6050
|
+
if (!channel || channel.guildId !== guildId)
|
|
6051
|
+
return null;
|
|
6052
|
+
}
|
|
6053
|
+
return computePermissions({
|
|
6054
|
+
guildId,
|
|
6055
|
+
ownerId: guild.ownerId,
|
|
6056
|
+
memberId,
|
|
6057
|
+
memberRoleIds: [...roleIds],
|
|
6058
|
+
roles: this.guilds.roles(guildId).values(),
|
|
6059
|
+
overwrites: channel?.permissionOverwrites
|
|
6060
|
+
});
|
|
6061
|
+
}
|
|
5862
6062
|
permissionsFor(memberId, guildOrChannelId) {
|
|
5863
6063
|
let channel = this.channels.get(guildOrChannelId);
|
|
5864
6064
|
if (channel?.isThread()) {
|
|
@@ -5902,12 +6102,21 @@ class Client extends EventEmitter2 {
|
|
|
5902
6102
|
this.#gateway.close();
|
|
5903
6103
|
}
|
|
5904
6104
|
postInteractionResponse(id, token, response) {
|
|
5905
|
-
|
|
6105
|
+
const json = response.toJSON();
|
|
6106
|
+
const upload = json.data ? toRequest(json.data) : undefined;
|
|
6107
|
+
if (upload && typeof upload === "object" && "files" in upload) {
|
|
6108
|
+
const { body, files } = upload;
|
|
6109
|
+
return this.rest.post(Routes.interactionCallback(id, token), {
|
|
6110
|
+
body: { ...json, data: body },
|
|
6111
|
+
files
|
|
6112
|
+
});
|
|
6113
|
+
}
|
|
6114
|
+
return this.rest.post(Routes.interactionCallback(id, token), json);
|
|
5906
6115
|
}
|
|
5907
6116
|
editInteractionReply(token, data) {
|
|
5908
6117
|
if (!this.user)
|
|
5909
6118
|
return Promise.reject(new Error("Client is unauthenticated."));
|
|
5910
|
-
return this.rest.patch(Routes.interactionOriginalResponse(this.user.id, token), data);
|
|
6119
|
+
return this.rest.patch(Routes.interactionOriginalResponse(this.user.id, token), toRequest(data));
|
|
5911
6120
|
}
|
|
5912
6121
|
deleteInteractionReply(token) {
|
|
5913
6122
|
if (!this.user)
|
|
@@ -5917,7 +6126,7 @@ class Client extends EventEmitter2 {
|
|
|
5917
6126
|
followUpInteraction(token, data) {
|
|
5918
6127
|
if (!this.user)
|
|
5919
6128
|
return Promise.reject(new Error("Client is unauthenticated."));
|
|
5920
|
-
return this.rest.post(`/webhooks/${this.user.id}/${token}`, data);
|
|
6129
|
+
return this.rest.post(`/webhooks/${this.user.id}/${token}`, toRequest(data));
|
|
5921
6130
|
}
|
|
5922
6131
|
interactionWebhookMessage(method, applicationId, token, messageId, data) {
|
|
5923
6132
|
const path = messageId === "@original" ? Routes.interactionOriginalResponse(applicationId, token) : Routes.webhookMessage(applicationId, token, messageId);
|
|
@@ -5988,4 +6197,4 @@ export {
|
|
|
5988
6197
|
resolveGatewayIntents
|
|
5989
6198
|
};
|
|
5990
6199
|
|
|
5991
|
-
//# debugId=
|
|
6200
|
+
//# debugId=C58DF09843ED07E364756E2164756E21
|