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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Manager } from "./base.js";
|
|
2
2
|
import { type REST } from "@lunibee/rest";
|
|
3
|
-
import type { APIGuildScheduledEvent, APIStageInstance, UserData } from "@lunibee/types";
|
|
3
|
+
import type { APIOverwrite, APIGuildScheduledEvent, APIStageInstance, UserData } from "@lunibee/types";
|
|
4
4
|
/** Raw Discord ban object. */
|
|
5
5
|
export interface APIBan {
|
|
6
6
|
user: UserData;
|
|
@@ -97,11 +97,31 @@ export interface PermissionOverwriteOptions {
|
|
|
97
97
|
/** Denied permission bits. */
|
|
98
98
|
deny?: bigint | number | string;
|
|
99
99
|
}
|
|
100
|
+
/** Bits to change on one overwrite by {@link PermissionOverwriteManager.update}; bits in none of them keep their state. */
|
|
101
|
+
export interface PermissionOverwriteUpdate {
|
|
102
|
+
/** Bits to allow. */
|
|
103
|
+
allow?: bigint;
|
|
104
|
+
/** Bits to deny. */
|
|
105
|
+
deny?: bigint;
|
|
106
|
+
/** Bits to reset to inherited (neither allowed nor denied). */
|
|
107
|
+
inherit?: bigint;
|
|
108
|
+
}
|
|
100
109
|
/** Manages a channel's permission overwrites. Discord.js-familiar. */
|
|
101
110
|
export declare class PermissionOverwriteManager {
|
|
102
111
|
#private;
|
|
103
112
|
readonly channelId: string;
|
|
104
|
-
|
|
113
|
+
/** @param current The channel's cached overwrites, read by {@link update}; the channel is fetched when they are unknown. */
|
|
114
|
+
constructor(rest: REST, channelId: string, current?: () => readonly APIOverwrite[] | undefined);
|
|
115
|
+
/**
|
|
116
|
+
* Changes some bits of one overwrite and keeps the rest -- unlike
|
|
117
|
+
* {@link edit}, which replaces the whole overwrite. Creates the overwrite
|
|
118
|
+
* when there is none (then `options.type` is required).
|
|
119
|
+
* @throws {TypeError} When the overwrite does not exist and no type is given.
|
|
120
|
+
*/
|
|
121
|
+
update(overwriteId: string, changes: PermissionOverwriteUpdate, options?: {
|
|
122
|
+
type?: PermissionOverwriteTargetType;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}): Promise<void>;
|
|
105
125
|
/** Creates or replaces the overwrite for a role or member. */
|
|
106
126
|
edit(overwriteId: string, options: PermissionOverwriteOptions, reason?: string): Promise<void>;
|
|
107
127
|
/** Deletes the overwrite for a role or member. */
|
package/dist/managers/guild.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { GuildSoundboardManager, GuildStickerManager } from "./advanced.js";
|
|
|
4
4
|
import { GuildMemberManager } from "./member.js";
|
|
5
5
|
import { RoleManager } from "./role.js";
|
|
6
6
|
import { GuildBanManager, GuildScheduledEventManager } from "./guild-resources.js";
|
|
7
|
-
import { Guild, AutoModerationRule } from "@lunibee/structures";
|
|
7
|
+
import { Guild, AutoModerationRule, type ResourceContext } from "@lunibee/structures";
|
|
8
8
|
import { type REST } from "@lunibee/rest";
|
|
9
9
|
import { type APIChannel, type APIGuildPreview, type APIInvite, type APIWebhook, type APIAutoModerationRule, type APIInviteCreate, type APIVoiceState } from "@lunibee/types";
|
|
10
10
|
type GuildData = ConstructorParameters<typeof Guild>[0];
|
|
@@ -15,6 +15,8 @@ export interface GuildEditOptions extends Record<string, unknown> {
|
|
|
15
15
|
}
|
|
16
16
|
export declare class GuildManager extends ResourceManager<string, Guild> {
|
|
17
17
|
#private;
|
|
18
|
+
/** Lets members from this manager act through a client (`member.kick()`...). Called by the client. */
|
|
19
|
+
attachContext(context: ResourceContext): void;
|
|
18
20
|
constructor(rest: REST);
|
|
19
21
|
/** Ban manager for a guild (one instance per guild). */
|
|
20
22
|
bans(guildId: string): GuildBanManager;
|
package/dist/managers/index.d.ts
CHANGED
|
@@ -42,9 +42,13 @@ export type ChannelEditOptions = Record<string, unknown>;
|
|
|
42
42
|
import { PermissionOverwriteManager } from "./guild-resources.js";
|
|
43
43
|
export declare class ChannelManager extends Manager<string, Channel> {
|
|
44
44
|
#private;
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* @param options.messageCache Enables a bounded per-channel message cache; messages are not cached by default.
|
|
47
|
+
* @param options.allowedMentions Default `allowed_mentions` for sends and edits without their own.
|
|
48
|
+
*/
|
|
46
49
|
constructor(rest: REST, options?: {
|
|
47
50
|
messageCache?: MessageCacheOptions;
|
|
51
|
+
allowedMentions?: unknown;
|
|
48
52
|
});
|
|
49
53
|
messages(channelId: string): MessageManager;
|
|
50
54
|
/** Permission overwrite manager for a channel. */
|
|
@@ -135,11 +139,11 @@ export declare class ChannelManager extends Manager<string, Channel> {
|
|
|
135
139
|
clear(): void;
|
|
136
140
|
}
|
|
137
141
|
export type CreateMessageOptions = MessageCreateOptions;
|
|
138
|
-
export { MessageManager, type MessageCacheOptions } from "./message.js";
|
|
142
|
+
export { MessageManager, toRequest, type MessageCacheOptions, type MessageFile, } from "./message.js";
|
|
139
143
|
export { ThreadManager } from "./thread.js";
|
|
140
144
|
export { RoleManager, type RoleCreateOptions, type RoleEditOptions, } from "./role.js";
|
|
141
145
|
export { GuildMemberManager, type MemberEditOptions, type BanOptions, } from "./member.js";
|
|
142
146
|
export { ApplicationCommandManager } from "./application.js";
|
|
143
|
-
export { GuildBanManager, GuildScheduledEventManager, StageInstanceManager, PermissionOverwriteManager, type APIBan, type GuildBanCreateOptions, type GuildScheduledEventOptions, type StageInstanceCreateOptions, type PermissionOverwriteOptions, type PermissionOverwriteTargetType, } from "./guild-resources.js";
|
|
147
|
+
export { GuildBanManager, GuildScheduledEventManager, StageInstanceManager, PermissionOverwriteManager, type APIBan, type GuildBanCreateOptions, type GuildScheduledEventOptions, type StageInstanceCreateOptions, type PermissionOverwriteOptions, type PermissionOverwriteTargetType, type PermissionOverwriteUpdate, } from "./guild-resources.js";
|
|
144
148
|
export { EmojiManager, type EmojiCreateOptions, type EmojiEditOptions, } from "./emoji.js";
|
|
145
149
|
export { GuildStickerManager, GuildSoundboardManager, MonetizationManager, type APIEntitlement, type APISKU, type APISoundboardSound, type APISubscription, type EntitlementQuery, type GuildStickerCreateOptions, type SoundboardSoundCreateOptions, } from "./advanced.js";
|
package/dist/managers/index.js
CHANGED
|
@@ -651,7 +651,7 @@ class ResourceManager extends Manager {
|
|
|
651
651
|
// packages/rest/package.json
|
|
652
652
|
var package_default = {
|
|
653
653
|
name: "@lunibee/rest",
|
|
654
|
-
version: "0.2.
|
|
654
|
+
version: "0.2.2",
|
|
655
655
|
type: "module",
|
|
656
656
|
module: "./src/index.ts",
|
|
657
657
|
types: "./src/index.ts",
|
|
@@ -865,6 +865,11 @@ class Channel extends BaseStructure {
|
|
|
865
865
|
editTopic(topic) {
|
|
866
866
|
return this.edit({ topic });
|
|
867
867
|
}
|
|
868
|
+
editPermissionOverwrite(targetId, changes, options) {
|
|
869
|
+
if (!this.#context?.editPermissionOverwrite)
|
|
870
|
+
throw new Error("This channel is not attached to a client.");
|
|
871
|
+
return this.#context.editPermissionOverwrite(this.id, targetId, changes, options);
|
|
872
|
+
}
|
|
868
873
|
editParent(parentId) {
|
|
869
874
|
return this.edit({ parent_id: parentId });
|
|
870
875
|
}
|
|
@@ -999,6 +1004,7 @@ class Guild extends BaseStructure {
|
|
|
999
1004
|
return this.name;
|
|
1000
1005
|
}
|
|
1001
1006
|
}
|
|
1007
|
+
|
|
1002
1008
|
// packages/core/src/permissions.ts
|
|
1003
1009
|
var Permission = {
|
|
1004
1010
|
createInstantInvite: 1n << 0n,
|
|
@@ -1391,6 +1397,11 @@ class PermissionSet {
|
|
|
1391
1397
|
toArray() {
|
|
1392
1398
|
return Object.keys(Permission).filter((permission) => this.has(permission));
|
|
1393
1399
|
}
|
|
1400
|
+
static #renamed = {
|
|
1401
|
+
ManageEmojisAndStickers: "ManageGuildExpressions",
|
|
1402
|
+
ManageEmojis: "ManageGuildExpressions",
|
|
1403
|
+
UseSlashCommands: "UseApplicationCommands"
|
|
1404
|
+
};
|
|
1394
1405
|
#resolve(permission) {
|
|
1395
1406
|
if (typeof permission === "bigint")
|
|
1396
1407
|
return permission;
|
|
@@ -1405,6 +1416,9 @@ class PermissionSet {
|
|
|
1405
1416
|
return bit;
|
|
1406
1417
|
}
|
|
1407
1418
|
if (typeof permission === "string") {
|
|
1419
|
+
const renamed = PermissionSet.#renamed[permission];
|
|
1420
|
+
if (renamed)
|
|
1421
|
+
return this.#resolve(renamed);
|
|
1408
1422
|
if (permission in Permission)
|
|
1409
1423
|
return Permission[permission];
|
|
1410
1424
|
if (permission in Permissions)
|
|
@@ -1526,13 +1540,15 @@ class GuildMember {
|
|
|
1526
1540
|
roleIds;
|
|
1527
1541
|
pending;
|
|
1528
1542
|
joinedAt;
|
|
1529
|
-
permissions;
|
|
1530
1543
|
avatarHash;
|
|
1531
1544
|
premiumSince;
|
|
1532
1545
|
timedOutUntil;
|
|
1533
1546
|
flags;
|
|
1534
|
-
|
|
1547
|
+
#suppliedPermissions;
|
|
1548
|
+
#context;
|
|
1549
|
+
constructor(data, context) {
|
|
1535
1550
|
this.user = new User(data.user);
|
|
1551
|
+
this.#context = context;
|
|
1536
1552
|
if (!/^\d{1,20}$/.test(data.guild_id))
|
|
1537
1553
|
throw new TypeError("Member guild_id must be a valid snowflake.");
|
|
1538
1554
|
this.guildId = data.guild_id;
|
|
@@ -1542,12 +1558,53 @@ class GuildMember {
|
|
|
1542
1558
|
this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
|
|
1543
1559
|
if (this.joinedAt?.toString() === "Invalid Date")
|
|
1544
1560
|
throw new RangeError("Member joined_at must be a valid date.");
|
|
1545
|
-
|
|
1561
|
+
if (data.permissions !== undefined)
|
|
1562
|
+
this.#suppliedPermissions = new PermissionsBitField(data.permissions);
|
|
1546
1563
|
this.avatarHash = data.avatar ?? null;
|
|
1547
1564
|
this.premiumSince = toDateOrNull(data.premium_since);
|
|
1548
1565
|
this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
|
|
1549
1566
|
this.flags = data.flags ?? 0;
|
|
1550
1567
|
}
|
|
1568
|
+
get permissions() {
|
|
1569
|
+
if (this.#suppliedPermissions)
|
|
1570
|
+
return this.#suppliedPermissions;
|
|
1571
|
+
return new PermissionsBitField(this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds) ?? 0n);
|
|
1572
|
+
}
|
|
1573
|
+
permissionsIn(channelId) {
|
|
1574
|
+
const computed = this.#context?.memberPermissions?.(this.guildId, this.user.id, this.roleIds, channelId);
|
|
1575
|
+
return computed ? new PermissionsBitField(computed) : null;
|
|
1576
|
+
}
|
|
1577
|
+
#action(name) {
|
|
1578
|
+
const action = this.#context?.[name];
|
|
1579
|
+
if (!action)
|
|
1580
|
+
throw new Error("This member is not attached to a client.");
|
|
1581
|
+
return action;
|
|
1582
|
+
}
|
|
1583
|
+
kick(reason) {
|
|
1584
|
+
return this.#action("kickMember")(this.guildId, this.user.id, reason);
|
|
1585
|
+
}
|
|
1586
|
+
ban(options = {}) {
|
|
1587
|
+
return this.#action("banMember")(this.guildId, this.user.id, options);
|
|
1588
|
+
}
|
|
1589
|
+
edit(options, reason) {
|
|
1590
|
+
return this.#action("editMember")(this.guildId, this.user.id, options, reason);
|
|
1591
|
+
}
|
|
1592
|
+
timeout(milliseconds, reason) {
|
|
1593
|
+
if (milliseconds !== null && !(milliseconds > 0))
|
|
1594
|
+
throw new RangeError("Timeout length must be a positive number of milliseconds.");
|
|
1595
|
+
return this.edit({
|
|
1596
|
+
communication_disabled_until: milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString()
|
|
1597
|
+
}, reason);
|
|
1598
|
+
}
|
|
1599
|
+
setNickname(nickname, reason) {
|
|
1600
|
+
return this.edit({ nick: nickname }, reason);
|
|
1601
|
+
}
|
|
1602
|
+
addRole(roleId, reason) {
|
|
1603
|
+
return this.#action("addMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
1604
|
+
}
|
|
1605
|
+
removeRole(roleId, reason) {
|
|
1606
|
+
return this.#action("removeMemberRole")(this.guildId, this.user.id, roleId, reason);
|
|
1607
|
+
}
|
|
1551
1608
|
get displayName() {
|
|
1552
1609
|
return this.nickname ?? this.user.displayName;
|
|
1553
1610
|
}
|
|
@@ -1617,7 +1674,7 @@ class TextChannel extends Channel {
|
|
|
1617
1674
|
return `<#${this.id}>`;
|
|
1618
1675
|
}
|
|
1619
1676
|
}
|
|
1620
|
-
class
|
|
1677
|
+
class Emoji2 extends BaseStructure {
|
|
1621
1678
|
name;
|
|
1622
1679
|
roleIds;
|
|
1623
1680
|
user;
|
|
@@ -1764,7 +1821,7 @@ class ForumChannel extends Channel {
|
|
|
1764
1821
|
|
|
1765
1822
|
class MediaChannel extends ForumChannel {
|
|
1766
1823
|
}
|
|
1767
|
-
function
|
|
1824
|
+
function createChannel(data, context) {
|
|
1768
1825
|
switch (data.type) {
|
|
1769
1826
|
case 0:
|
|
1770
1827
|
return new TextChannel(data, context);
|
|
@@ -1795,6 +1852,7 @@ function createChannel2(data, context) {
|
|
|
1795
1852
|
var TOKEN_LIFETIME_MS = 15 * 60000;
|
|
1796
1853
|
|
|
1797
1854
|
// packages/structures/src/index.ts
|
|
1855
|
+
var COMPONENT_COLLECTOR_DEFAULT_TIME = 15 * 60000;
|
|
1798
1856
|
var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
|
|
1799
1857
|
|
|
1800
1858
|
class Message extends BaseStructure {
|
|
@@ -1815,6 +1873,10 @@ class Message extends BaseStructure {
|
|
|
1815
1873
|
reference;
|
|
1816
1874
|
components;
|
|
1817
1875
|
referencedMessage;
|
|
1876
|
+
stickers;
|
|
1877
|
+
poll;
|
|
1878
|
+
messageSnapshots;
|
|
1879
|
+
member;
|
|
1818
1880
|
#context;
|
|
1819
1881
|
constructor(data, context) {
|
|
1820
1882
|
super(data.id);
|
|
@@ -1835,8 +1897,20 @@ class Message extends BaseStructure {
|
|
|
1835
1897
|
this.mentionEveryone = data.mention_everyone ?? false;
|
|
1836
1898
|
this.type = data.type ?? 0;
|
|
1837
1899
|
this.reference = data.message_reference;
|
|
1900
|
+
this.stickers = data.sticker_items ?? (data.stickers ?? []).map(({ id, name, format_type }) => ({
|
|
1901
|
+
id,
|
|
1902
|
+
name,
|
|
1903
|
+
format_type
|
|
1904
|
+
}));
|
|
1905
|
+
this.poll = data.poll ?? null;
|
|
1906
|
+
this.messageSnapshots = data.message_snapshots ?? [];
|
|
1838
1907
|
this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
|
|
1839
1908
|
this.#context = context;
|
|
1909
|
+
this.member = data.member && data.guild_id ? new GuildMember({
|
|
1910
|
+
...data.member,
|
|
1911
|
+
user: data.member.user ?? data.author,
|
|
1912
|
+
guild_id: data.guild_id
|
|
1913
|
+
}, context) : null;
|
|
1840
1914
|
this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
|
|
1841
1915
|
}
|
|
1842
1916
|
get embedsSuppressed() {
|
|
@@ -1877,6 +1951,20 @@ class Message extends BaseStructure {
|
|
|
1877
1951
|
throw new Error("This message is not attached to a client.");
|
|
1878
1952
|
return this.#context.crosspostMessage(this.channelId, this.id);
|
|
1879
1953
|
}
|
|
1954
|
+
createComponentCollector(options = {}) {
|
|
1955
|
+
const collect = this.#context?.collectInteractions;
|
|
1956
|
+
if (!collect)
|
|
1957
|
+
throw new Error("This message is not attached to a client.");
|
|
1958
|
+
const { componentType, filter, ...rest } = options;
|
|
1959
|
+
return collect({
|
|
1960
|
+
...rest,
|
|
1961
|
+
time: rest.time ?? (rest.idle ? undefined : COMPONENT_COLLECTOR_DEFAULT_TIME),
|
|
1962
|
+
filter: async (interaction) => interaction.isMessageComponent() && interaction.messageId === this.id && (componentType === undefined || interaction.componentType === componentType) && (filter ? await filter(interaction) : true)
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
awaitComponent(options = {}) {
|
|
1966
|
+
return this.createComponentCollector({ ...options, max: 1 }).next();
|
|
1967
|
+
}
|
|
1880
1968
|
react(emoji) {
|
|
1881
1969
|
if (!this.#context?.addReaction)
|
|
1882
1970
|
throw new Error("This message is not attached to a client.");
|
|
@@ -1950,15 +2038,33 @@ class Message extends BaseStructure {
|
|
|
1950
2038
|
}
|
|
1951
2039
|
|
|
1952
2040
|
// packages/managers/src/message.ts
|
|
2041
|
+
function toRequest(options, allowedMentions) {
|
|
2042
|
+
const { files, ...body } = options;
|
|
2043
|
+
if (allowedMentions !== undefined && body.allowed_mentions === undefined)
|
|
2044
|
+
body.allowed_mentions = allowedMentions;
|
|
2045
|
+
if (!files?.length)
|
|
2046
|
+
return body;
|
|
2047
|
+
return {
|
|
2048
|
+
body,
|
|
2049
|
+
files: files.map((file) => ({
|
|
2050
|
+
name: file.name,
|
|
2051
|
+
data: typeof file.data === "string" ? new TextEncoder().encode(file.data) : file.data,
|
|
2052
|
+
contentType: file.contentType
|
|
2053
|
+
}))
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
|
|
1953
2057
|
class MessageManager {
|
|
1954
2058
|
cache;
|
|
1955
2059
|
#caching;
|
|
1956
2060
|
#rest;
|
|
1957
2061
|
#context;
|
|
1958
2062
|
#channelId;
|
|
1959
|
-
|
|
2063
|
+
#allowedMentions;
|
|
2064
|
+
constructor(rest, context, channelId, cache, allowedMentions) {
|
|
1960
2065
|
if (!channelId)
|
|
1961
2066
|
throw new TypeError("Channel ID is required.");
|
|
2067
|
+
this.#allowedMentions = allowedMentions;
|
|
1962
2068
|
this.#rest = rest;
|
|
1963
2069
|
this.#context = context;
|
|
1964
2070
|
this.#channelId = channelId;
|
|
@@ -1972,7 +2078,7 @@ class MessageManager {
|
|
|
1972
2078
|
return this.cache.get(messageId) ?? this.fetch(messageId);
|
|
1973
2079
|
}
|
|
1974
2080
|
async send(options) {
|
|
1975
|
-
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), options);
|
|
2081
|
+
const data = await this.#rest.post(Routes.channelMessages(this.#channelId), toRequest(options, this.#allowedMentions));
|
|
1976
2082
|
return this.upsert(data);
|
|
1977
2083
|
}
|
|
1978
2084
|
async fetch(messageId) {
|
|
@@ -2016,7 +2122,7 @@ class ThreadManager {
|
|
|
2016
2122
|
auto_archive_duration: options.autoArchiveDuration,
|
|
2017
2123
|
rate_limit_per_user: options.rateLimitPerUser
|
|
2018
2124
|
});
|
|
2019
|
-
return
|
|
2125
|
+
return createChannel(data, this.#context);
|
|
2020
2126
|
}
|
|
2021
2127
|
}
|
|
2022
2128
|
|
|
@@ -2054,7 +2160,7 @@ class EmojiManager extends Manager {
|
|
|
2054
2160
|
this.#guildId = guildId;
|
|
2055
2161
|
}
|
|
2056
2162
|
fetch(emojiId) {
|
|
2057
|
-
return this.fetchOnce(emojiId, async () => new
|
|
2163
|
+
return this.fetchOnce(emojiId, async () => new Emoji2(await this.#rest.get(Routes.guildEmoji(this.#guildId, emojiId))), (emoji) => this.#merge(emojiId, emoji));
|
|
2058
2164
|
}
|
|
2059
2165
|
async fetchAll() {
|
|
2060
2166
|
const data = await this.#rest.get(Routes.guildEmoji(this.#guildId));
|
|
@@ -2072,7 +2178,7 @@ class EmojiManager extends Manager {
|
|
|
2072
2178
|
}
|
|
2073
2179
|
upsert(data) {
|
|
2074
2180
|
const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
|
|
2075
|
-
return this.#merge(key, new
|
|
2181
|
+
return this.#merge(key, new Emoji2(data));
|
|
2076
2182
|
}
|
|
2077
2183
|
#merge(key, emoji) {
|
|
2078
2184
|
const existing = this.get(key);
|
|
@@ -2253,14 +2359,20 @@ class MonetizationManager extends Manager {
|
|
|
2253
2359
|
// packages/managers/src/member.ts
|
|
2254
2360
|
class GuildMemberManager extends ResourceManager {
|
|
2255
2361
|
#rest;
|
|
2362
|
+
#context;
|
|
2256
2363
|
guildId;
|
|
2257
|
-
constructor(guildId, rest) {
|
|
2258
|
-
|
|
2364
|
+
constructor(guildId, rest, context = () => {
|
|
2365
|
+
return;
|
|
2366
|
+
}) {
|
|
2367
|
+
super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId }, context())), (member) => member.user.id);
|
|
2259
2368
|
this.guildId = guildId;
|
|
2260
2369
|
this.#rest = rest;
|
|
2370
|
+
this.#context = context;
|
|
2261
2371
|
}
|
|
2262
|
-
async kick(userId) {
|
|
2263
|
-
await this.#rest.delete(Routes.guildMember(this.guildId, userId)
|
|
2372
|
+
async kick(userId, reason) {
|
|
2373
|
+
await this.#rest.delete(Routes.guildMember(this.guildId, userId), {
|
|
2374
|
+
reason
|
|
2375
|
+
});
|
|
2264
2376
|
this.delete(userId);
|
|
2265
2377
|
}
|
|
2266
2378
|
async ban(userId, options = {}) {
|
|
@@ -2270,21 +2382,21 @@ class GuildMemberManager extends ResourceManager {
|
|
|
2270
2382
|
async unban(userId) {
|
|
2271
2383
|
await this.#rest.delete(Routes.guildBan(this.guildId, userId));
|
|
2272
2384
|
}
|
|
2273
|
-
async edit(userId, options) {
|
|
2274
|
-
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options);
|
|
2275
|
-
const member = new GuildMember({ ...data, guild_id: this.guildId });
|
|
2385
|
+
async edit(userId, options, reason) {
|
|
2386
|
+
const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options, { reason });
|
|
2387
|
+
const member = new GuildMember({ ...data, guild_id: this.guildId }, this.#context());
|
|
2276
2388
|
this.set(member.user.id, member);
|
|
2277
2389
|
return member;
|
|
2278
2390
|
}
|
|
2279
|
-
async addRole(userId, roleId) {
|
|
2280
|
-
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
2391
|
+
async addRole(userId, roleId, reason) {
|
|
2392
|
+
await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId), undefined, { reason });
|
|
2281
2393
|
}
|
|
2282
|
-
async removeRole(userId, roleId) {
|
|
2283
|
-
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId));
|
|
2394
|
+
async removeRole(userId, roleId, reason) {
|
|
2395
|
+
await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId), { reason });
|
|
2284
2396
|
}
|
|
2285
|
-
async timeout(userId, milliseconds) {
|
|
2397
|
+
async timeout(userId, milliseconds, reason) {
|
|
2286
2398
|
const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
|
|
2287
|
-
return this.edit(userId, { communication_disabled_until: timeoutDate });
|
|
2399
|
+
return this.edit(userId, { communication_disabled_until: timeoutDate }, reason);
|
|
2288
2400
|
}
|
|
2289
2401
|
}
|
|
2290
2402
|
|
|
@@ -2455,10 +2567,25 @@ class StageInstanceManager extends Manager {
|
|
|
2455
2567
|
|
|
2456
2568
|
class PermissionOverwriteManager {
|
|
2457
2569
|
#rest;
|
|
2570
|
+
#current;
|
|
2458
2571
|
channelId;
|
|
2459
|
-
constructor(rest, channelId) {
|
|
2572
|
+
constructor(rest, channelId, current = () => {
|
|
2573
|
+
return;
|
|
2574
|
+
}) {
|
|
2460
2575
|
this.#rest = rest;
|
|
2461
2576
|
this.channelId = channelId;
|
|
2577
|
+
this.#current = current;
|
|
2578
|
+
}
|
|
2579
|
+
async update(overwriteId, changes, options = {}) {
|
|
2580
|
+
const overwrites = this.#current() ?? (await this.#rest.get(Routes.channel(this.channelId))).permission_overwrites ?? [];
|
|
2581
|
+
const existing = overwrites.find((entry) => entry.id === overwriteId);
|
|
2582
|
+
const type = existing?.type ?? options.type;
|
|
2583
|
+
if (type !== 0 && type !== 1)
|
|
2584
|
+
throw new TypeError("A new permission overwrite needs a type: 0 for a role, 1 for a member.");
|
|
2585
|
+
const touched = (changes.allow ?? 0n) | (changes.deny ?? 0n) | (changes.inherit ?? 0n);
|
|
2586
|
+
const allow = BigInt(existing?.allow ?? 0) & ~touched | (changes.allow ?? 0n);
|
|
2587
|
+
const deny = BigInt(existing?.deny ?? 0) & ~touched | (changes.deny ?? 0n);
|
|
2588
|
+
await this.edit(overwriteId, { type, allow, deny }, options.reason);
|
|
2462
2589
|
}
|
|
2463
2590
|
async edit(overwriteId, options, reason) {
|
|
2464
2591
|
await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
|
|
@@ -2490,6 +2617,10 @@ class GuildManager extends ResourceManager {
|
|
|
2490
2617
|
#voiceStates = new Map;
|
|
2491
2618
|
#autoModerationRules = new Map;
|
|
2492
2619
|
#invites = new Map;
|
|
2620
|
+
#context;
|
|
2621
|
+
attachContext(context) {
|
|
2622
|
+
this.#context = context;
|
|
2623
|
+
}
|
|
2493
2624
|
#perGuild(map, guildId, create) {
|
|
2494
2625
|
let manager = map.get(guildId);
|
|
2495
2626
|
if (!manager)
|
|
@@ -2515,7 +2646,7 @@ class GuildManager extends ResourceManager {
|
|
|
2515
2646
|
members(guildId) {
|
|
2516
2647
|
let manager = this.#members.get(guildId);
|
|
2517
2648
|
if (!manager)
|
|
2518
|
-
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest));
|
|
2649
|
+
this.#members.set(guildId, manager = new GuildMemberManager(guildId, this.#rest, () => this.#context));
|
|
2519
2650
|
return manager;
|
|
2520
2651
|
}
|
|
2521
2652
|
roles(guildId) {
|
|
@@ -2743,10 +2874,12 @@ class ChannelManager extends Manager {
|
|
|
2743
2874
|
#context;
|
|
2744
2875
|
#messageManagers = new Map;
|
|
2745
2876
|
#messageCache;
|
|
2877
|
+
#allowedMentions;
|
|
2746
2878
|
constructor(rest, options = {}) {
|
|
2747
2879
|
super();
|
|
2748
2880
|
this.#rest = rest;
|
|
2749
2881
|
this.#messageCache = options.messageCache;
|
|
2882
|
+
this.#allowedMentions = options.allowedMentions;
|
|
2750
2883
|
this.#context = {
|
|
2751
2884
|
sendMessage: (channelId, options) => this.send(channelId, options),
|
|
2752
2885
|
editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
|
|
@@ -2765,25 +2898,25 @@ class ChannelManager extends Manager {
|
|
|
2765
2898
|
messages(channelId) {
|
|
2766
2899
|
let manager = this.#messageManagers.get(channelId);
|
|
2767
2900
|
if (!manager) {
|
|
2768
|
-
manager = new MessageManager(this.#rest, this.#context, channelId, this.#messageCache);
|
|
2901
|
+
manager = new MessageManager(this.#rest, this.#context, channelId, this.#messageCache, this.#allowedMentions);
|
|
2769
2902
|
this.#messageManagers.set(channelId, manager);
|
|
2770
2903
|
}
|
|
2771
2904
|
return manager;
|
|
2772
2905
|
}
|
|
2773
2906
|
permissionOverwrites(channelId) {
|
|
2774
|
-
return new PermissionOverwriteManager(this.#rest, channelId);
|
|
2907
|
+
return new PermissionOverwriteManager(this.#rest, channelId, () => this.get(channelId)?.permissionOverwrites);
|
|
2775
2908
|
}
|
|
2776
2909
|
threads(channelId) {
|
|
2777
2910
|
return new ThreadManager(this.#rest, this.#context, channelId);
|
|
2778
2911
|
}
|
|
2779
2912
|
fetch(channelId) {
|
|
2780
|
-
return this.fetchOnce(channelId, async () =>
|
|
2913
|
+
return this.fetchOnce(channelId, async () => createChannel(await this.#rest.get(Routes.channel(channelId)), this.#context), (channel) => this.#merge(channel));
|
|
2781
2914
|
}
|
|
2782
2915
|
async resolve(channelId) {
|
|
2783
2916
|
return this.get(channelId) ?? this.fetch(channelId);
|
|
2784
2917
|
}
|
|
2785
2918
|
upsert(data) {
|
|
2786
|
-
return this.#merge(
|
|
2919
|
+
return this.#merge(createChannel(data, this.#context));
|
|
2787
2920
|
}
|
|
2788
2921
|
#merge(channel) {
|
|
2789
2922
|
const existing = this.get(channel.id);
|
|
@@ -2871,7 +3004,7 @@ class ChannelManager extends Manager {
|
|
|
2871
3004
|
return this.messages(data.channel_id).upsert(data);
|
|
2872
3005
|
}
|
|
2873
3006
|
async editMessage(channelId, messageId, options) {
|
|
2874
|
-
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), options));
|
|
3007
|
+
return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), toRequest(options, this.#allowedMentions)));
|
|
2875
3008
|
}
|
|
2876
3009
|
async deleteMessage(channelId, messageId) {
|
|
2877
3010
|
await this.#rest.delete(Routes.message(channelId, messageId));
|
|
@@ -2994,7 +3127,8 @@ export {
|
|
|
2994
3127
|
RoleManager,
|
|
2995
3128
|
StageInstanceManager,
|
|
2996
3129
|
ThreadManager,
|
|
2997
|
-
UserManager
|
|
3130
|
+
UserManager,
|
|
3131
|
+
toRequest
|
|
2998
3132
|
};
|
|
2999
3133
|
|
|
3000
|
-
//# debugId=
|
|
3134
|
+
//# debugId=EB58705923B2D19264756E2164756E21
|