seyfert 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/lib/api/CDN.d.ts +1 -1
  2. package/lib/api/CDN.js +0 -2
  3. package/lib/api/Router.js +2 -2
  4. package/lib/api/Routes/applications.d.ts +29 -33
  5. package/lib/api/Routes/channels.d.ts +11 -17
  6. package/lib/api/Routes/interactions.d.ts +3 -7
  7. package/lib/api/Routes/webhooks.d.ts +4 -6
  8. package/lib/builders/Attachment.d.ts +2 -3
  9. package/lib/cache/adapters/redis.js +6 -0
  10. package/lib/cache/adapters/workeradapter.d.ts +4 -4
  11. package/lib/cache/adapters/workeradapter.js +10 -5
  12. package/lib/cache/index.d.ts +4 -5
  13. package/lib/cache/index.js +4 -3
  14. package/lib/cache/resources/default/base.d.ts +2 -1
  15. package/lib/cache/resources/default/guild-based.d.ts +2 -1
  16. package/lib/cache/resources/default/guild-based.js +6 -6
  17. package/lib/cache/resources/default/guild-related.d.ts +2 -1
  18. package/lib/cache/resources/default/guild-related.js +1 -1
  19. package/lib/cache/resources/guilds.js +2 -1
  20. package/lib/cache/resources/overwrites.d.ts +1 -1
  21. package/lib/cache/resources/overwrites.js +7 -1
  22. package/lib/client/base.d.ts +18 -170
  23. package/lib/client/base.js +11 -14
  24. package/lib/client/client.d.ts +5 -0
  25. package/lib/client/client.js +4 -1
  26. package/lib/client/oninteractioncreate.js +2 -2
  27. package/lib/client/onmessagecreate.js +188 -152
  28. package/lib/client/workerclient.d.ts +1 -0
  29. package/lib/client/workerclient.js +36 -15
  30. package/lib/collection.js +2 -2
  31. package/lib/commands/applications/chat.d.ts +15 -7
  32. package/lib/commands/applications/chat.js +7 -7
  33. package/lib/commands/applications/chatcontext.d.ts +5 -3
  34. package/lib/commands/applications/chatcontext.js +6 -1
  35. package/lib/commands/applications/menu.d.ts +5 -1
  36. package/lib/commands/applications/menu.js +4 -0
  37. package/lib/commands/applications/menucontext.d.ts +4 -2
  38. package/lib/commands/applications/menucontext.js +6 -1
  39. package/lib/commands/applications/options.d.ts +1 -2
  40. package/lib/commands/decorators.d.ts +17 -5
  41. package/lib/commands/decorators.js +17 -7
  42. package/lib/commands/handler.d.ts +5 -5
  43. package/lib/commands/handler.js +40 -36
  44. package/lib/commands/optionresolver.d.ts +11 -4
  45. package/lib/commands/optionresolver.js +6 -4
  46. package/lib/common/index.d.ts +7 -0
  47. package/lib/common/index.js +7 -0
  48. package/lib/common/it/utils.js +2 -0
  49. package/lib/common/shorters/channels.d.ts +67 -129
  50. package/lib/common/shorters/channels.js +119 -135
  51. package/lib/common/shorters/emojis.d.ts +47 -0
  52. package/lib/common/shorters/emojis.js +80 -0
  53. package/lib/common/shorters/guilds.d.ts +22 -249
  54. package/lib/common/shorters/guilds.js +51 -140
  55. package/lib/common/shorters/members.d.ts +82 -108
  56. package/lib/common/shorters/members.js +151 -166
  57. package/lib/common/shorters/messages.d.ts +11 -23
  58. package/lib/common/shorters/messages.js +58 -104
  59. package/lib/common/shorters/reactions.d.ts +10 -0
  60. package/lib/common/shorters/reactions.js +45 -0
  61. package/lib/common/shorters/roles.d.ts +39 -7
  62. package/lib/common/shorters/roles.js +74 -42
  63. package/lib/common/shorters/templates.d.ts +6 -8
  64. package/lib/common/shorters/templates.js +17 -21
  65. package/lib/common/shorters/users.d.ts +4 -0
  66. package/lib/common/shorters/users.js +30 -0
  67. package/lib/common/shorters/webhook.d.ts +62 -26
  68. package/lib/common/shorters/webhook.js +113 -58
  69. package/lib/common/types/options.d.ts +2 -2
  70. package/lib/components/handler.d.ts +10 -7
  71. package/lib/components/handler.js +20 -5
  72. package/lib/index.d.ts +4 -2
  73. package/lib/langs/handler.js +7 -2
  74. package/lib/structures/AutoModerationRule.d.ts +2 -2
  75. package/lib/structures/ClientUser.d.ts +2 -2
  76. package/lib/structures/Guild.d.ts +2 -2
  77. package/lib/structures/GuildEmoji.d.ts +4 -4
  78. package/lib/structures/GuildEmoji.js +7 -7
  79. package/lib/structures/GuildMember.d.ts +6 -6
  80. package/lib/structures/GuildMember.js +2 -2
  81. package/lib/structures/GuildPreview.d.ts +2 -2
  82. package/lib/structures/GuildRole.d.ts +2 -2
  83. package/lib/structures/GuildTemplate.d.ts +2 -2
  84. package/lib/structures/Interaction.d.ts +7 -8
  85. package/lib/structures/Interaction.js +1 -1
  86. package/lib/structures/Message.d.ts +7 -6
  87. package/lib/structures/Message.js +7 -4
  88. package/lib/structures/Sticker.d.ts +2 -2
  89. package/lib/structures/Webhook.d.ts +2 -2
  90. package/lib/structures/Webhook.js +3 -3
  91. package/lib/structures/channels.d.ts +19 -20
  92. package/lib/structures/channels.js +13 -25
  93. package/lib/structures/extra/Base.d.ts +1 -2
  94. package/lib/structures/extra/DiscordBase.d.ts +2 -2
  95. package/lib/websocket/constants/index.js +1 -0
  96. package/lib/websocket/discord/shard.js +4 -2
  97. package/lib/websocket/discord/sharder.d.ts +3 -0
  98. package/lib/websocket/discord/sharder.js +12 -5
  99. package/lib/websocket/discord/shared.d.ts +1 -0
  100. package/lib/websocket/discord/worker.d.ts +2 -1
  101. package/lib/websocket/discord/workermanager.d.ts +8 -3
  102. package/lib/websocket/discord/workermanager.js +78 -30
  103. package/package.json +8 -6
@@ -4,135 +4,73 @@ import { type AllChannels } from '../../structures/channels';
4
4
  import { PermissionsBitField } from '../../structures/extra/Permissions';
5
5
  import { BaseShorter } from './base';
6
6
  export declare class ChannelShorter extends BaseShorter {
7
- get channels(): {
8
- /**
9
- * Fetches a channel by its ID.
10
- * @param id The ID of the channel to fetch.
11
- * @param force Whether to force fetching the channel from the API even if it exists in the cache.
12
- * @returns A Promise that resolves to the fetched channel.
13
- */
14
- fetch: (id: string, force?: boolean) => Promise<AllChannels>;
15
- /**
16
- * Deletes a channel by its ID.
17
- * @param id The ID of the channel to delete.
18
- * @param optional Optional parameters for the deletion.
19
- * @returns A Promise that resolves to the deleted channel.
20
- */
21
- delete: (id: string, optional?: ChannelShorterOptionalParams) => Promise<AllChannels>;
22
- /**
23
- * Edits a channel by its ID.
24
- * @param id The ID of the channel to edit.
25
- * @param body The updated channel data.
26
- * @param optional Optional parameters for the editing.
27
- * @returns A Promise that resolves to the edited channel.
28
- */
29
- edit: (id: string, body: RESTPatchAPIChannelJSONBody, optional?: ChannelShorterOptionalParams) => Promise<AllChannels>;
30
- /**
31
- * Sends a typing indicator to the channel.
32
- * @param id The ID of the channel.
33
- * @returns A Promise that resolves when the typing indicator is successfully sent.
34
- */
35
- typing: (id: string) => Promise<never>;
36
- /**
37
- * Provides access to pinned messages in the channel.
38
- */
39
- pins: {
40
- /**
41
- * Fetches pinned messages in the channel.
42
- * @param channelId The ID of the channel.
43
- * @returns A Promise that resolves to an array of pinned messages.
44
- */
45
- fetch: (channelId: string) => Promise<Message[]>;
46
- /**
47
- * Pins a message in the channel.
48
- * @param messageId The ID of the message to pin.
49
- * @param channelId The ID of the channel.
50
- * @param reason The reason for pinning the message.
51
- * @returns A Promise that resolves when the message is successfully pinned.
52
- */
53
- set: (messageId: string, channelId: string, reason?: string | undefined) => Promise<never>;
54
- /**
55
- * Unpins a message in the channel.
56
- * @param messageId The ID of the message to unpin.
57
- * @param channelId The ID of the channel.
58
- * @param reason The reason for unpinning the message.
59
- * @returns A Promise that resolves when the message is successfully unpinned.
60
- */
61
- delete: (messageId: string, channelId: string, reason?: string | undefined) => Promise<never>;
62
- };
63
- overwrites: {
64
- memberPermissions: (channelId: string, member: GuildMember, checkAdmin?: boolean) => Promise<PermissionsBitField>;
65
- overwritesFor: (channelId: string, member: GuildMember) => Promise<{
66
- everyone: {
67
- type: number;
68
- id: string;
69
- deny: PermissionsBitField;
70
- allow: PermissionsBitField;
71
- } | undefined;
72
- roles: {
73
- type: number;
74
- id: string;
75
- deny: PermissionsBitField;
76
- allow: PermissionsBitField;
77
- }[];
78
- member: {
79
- type: number;
80
- id: string;
81
- deny: PermissionsBitField;
82
- allow: PermissionsBitField;
83
- } | undefined;
84
- }>;
85
- rolePermissions: (channelId: string, role: GuildRole, checkAdmin?: boolean) => Promise<PermissionsBitField>;
86
- };
87
- };
88
- get pins(): {
89
- /**
90
- * Fetches pinned messages in the channel.
91
- * @param channelId The ID of the channel.
92
- * @returns A Promise that resolves to an array of pinned messages.
93
- */
94
- fetch: (channelId: string) => Promise<Message[]>;
95
- /**
96
- * Pins a message in the channel.
97
- * @param messageId The ID of the message to pin.
98
- * @param channelId The ID of the channel.
99
- * @param reason The reason for pinning the message.
100
- * @returns A Promise that resolves when the message is successfully pinned.
101
- */
102
- set: (messageId: string, channelId: string, reason?: string) => Promise<never>;
103
- /**
104
- * Unpins a message in the channel.
105
- * @param messageId The ID of the message to unpin.
106
- * @param channelId The ID of the channel.
107
- * @param reason The reason for unpinning the message.
108
- * @returns A Promise that resolves when the message is successfully unpinned.
109
- */
110
- delete: (messageId: string, channelId: string, reason?: string) => Promise<never>;
111
- };
112
- get overwrites(): {
113
- memberPermissions: (channelId: string, member: GuildMember, checkAdmin?: boolean) => Promise<PermissionsBitField>;
114
- overwritesFor: (channelId: string, member: GuildMember) => Promise<{
115
- everyone: {
116
- type: number;
117
- id: string;
118
- deny: PermissionsBitField;
119
- allow: PermissionsBitField;
120
- } | undefined;
121
- roles: {
122
- type: number;
123
- id: string;
124
- deny: PermissionsBitField;
125
- allow: PermissionsBitField;
126
- }[];
127
- member: {
128
- type: number;
129
- id: string;
130
- deny: PermissionsBitField;
131
- allow: PermissionsBitField;
132
- } | undefined;
133
- }>;
134
- rolePermissions: (channelId: string, role: GuildRole, checkAdmin?: boolean) => Promise<PermissionsBitField>;
135
- };
7
+ /**
8
+ * Fetches a channel by its ID.
9
+ * @param id The ID of the channel to fetch.
10
+ * @param force Whether to force fetching the channel from the API even if it exists in the cache.
11
+ * @returns A Promise that resolves to the fetched channel.
12
+ */
13
+ fetch(id: string, force?: boolean): Promise<AllChannels>;
14
+ /**
15
+ * Deletes a channel by its ID.
16
+ * @param id The ID of the channel to delete.
17
+ * @param optional Optional parameters for the deletion.
18
+ * @returns A Promise that resolves to the deleted channel.
19
+ */
20
+ delete(id: string, optional?: ChannelShorterOptionalParams): Promise<AllChannels>;
21
+ /**
22
+ * Edits a channel by its ID.
23
+ * @param id The ID of the channel to edit.
24
+ * @param body The updated channel data.
25
+ * @param optional Optional parameters for the editing.
26
+ * @returns A Promise that resolves to the edited channel.
27
+ */
28
+ edit(id: string, body: RESTPatchAPIChannelJSONBody, optional?: ChannelShorterOptionalParams): Promise<AllChannels>;
29
+ /**
30
+ * Sends a typing indicator to the channel.
31
+ * @param id The ID of the channel.
32
+ * @returns A Promise that resolves when the typing indicator is successfully sent.
33
+ */
34
+ typing(id: string): Promise<void>;
35
+ pins(channelId: string): Promise<Message[]>;
36
+ /**
37
+ * Pins a message in the channel.
38
+ * @param messageId The ID of the message to pin.
39
+ * @param channelId The ID of the channel.
40
+ * @param reason The reason for pinning the message.
41
+ * @returns A Promise that resolves when the message is successfully pinned.
42
+ */
43
+ setPin(messageId: string, channelId: string, reason?: string): Promise<never>;
44
+ /**
45
+ * Unpins a message in the channel.
46
+ * @param messageId The ID of the message to unpin.
47
+ * @param channelId The ID of the channel.
48
+ * @param reason The reason for unpinning the message.
49
+ * @returns A Promise that resolves when the message is successfully unpinned.
50
+ */
51
+ deletePin(messageId: string, channelId: string, reason?: string): Promise<never>;
52
+ memberPermissions(channelId: string, member: GuildMember, checkAdmin?: boolean): Promise<PermissionsBitField>;
53
+ overwritesFor(channelId: string, member: GuildMember): Promise<{
54
+ everyone: {
55
+ type: number;
56
+ id: string;
57
+ deny: PermissionsBitField;
58
+ allow: PermissionsBitField;
59
+ } | undefined;
60
+ roles: {
61
+ type: number;
62
+ id: string;
63
+ deny: PermissionsBitField;
64
+ allow: PermissionsBitField;
65
+ }[];
66
+ member: {
67
+ type: number;
68
+ id: string;
69
+ deny: PermissionsBitField;
70
+ allow: PermissionsBitField;
71
+ } | undefined;
72
+ }>;
73
+ rolePermissions(channelId: string, role: GuildRole, checkAdmin?: boolean): Promise<PermissionsBitField>;
136
74
  }
137
75
  export type ChannelShorterOptionalParams = Partial<{
138
76
  guildId: string;
@@ -10,145 +10,129 @@ const channels_1 = __importDefault(require("../../structures/channels"));
10
10
  const Permissions_1 = require("../../structures/extra/Permissions");
11
11
  const base_1 = require("./base");
12
12
  class ChannelShorter extends base_1.BaseShorter {
13
- get channels() {
14
- return {
15
- /**
16
- * Fetches a channel by its ID.
17
- * @param id The ID of the channel to fetch.
18
- * @param force Whether to force fetching the channel from the API even if it exists in the cache.
19
- * @returns A Promise that resolves to the fetched channel.
20
- */
21
- fetch: async (id, force) => {
22
- let channel;
23
- if (!force) {
24
- channel = await this.client.cache.channels?.get(id);
25
- if (channel)
26
- return channel;
27
- }
28
- channel = await this.client.proxy.channels(id).get();
29
- await this.client.cache.channels?.patch(id, undefined, channel);
30
- return (0, channels_1.default)(channel, this.client);
31
- },
32
- /**
33
- * Deletes a channel by its ID.
34
- * @param id The ID of the channel to delete.
35
- * @param optional Optional parameters for the deletion.
36
- * @returns A Promise that resolves to the deleted channel.
37
- */
38
- delete: async (id, optional = { guildId: '@me' }) => {
39
- const res = await this.client.proxy.channels(id).delete({ reason: optional.reason });
40
- await this.client.cache.channels?.removeIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId);
41
- return (0, channels_1.default)(res, this.client);
42
- },
43
- /**
44
- * Edits a channel by its ID.
45
- * @param id The ID of the channel to edit.
46
- * @param body The updated channel data.
47
- * @param optional Optional parameters for the editing.
48
- * @returns A Promise that resolves to the edited channel.
49
- */
50
- edit: async (id, body, optional = { guildId: '@me' }) => {
51
- const res = await this.client.proxy.channels(id).patch({ body, reason: optional.reason });
52
- await this.client.cache.channels?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res);
53
- if (body.permission_overwrites && 'permission_overwrites' in res)
54
- await this.client.cache.overwrites?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res.permission_overwrites);
55
- return (0, channels_1.default)(res, this.client);
56
- },
57
- /**
58
- * Sends a typing indicator to the channel.
59
- * @param id The ID of the channel.
60
- * @returns A Promise that resolves when the typing indicator is successfully sent.
61
- */
62
- typing: (id) => this.client.proxy.channels(id).typing.post(),
63
- /**
64
- * Provides access to pinned messages in the channel.
65
- */
66
- pins: this.pins,
67
- overwrites: this.overwrites,
68
- };
13
+ /**
14
+ * Fetches a channel by its ID.
15
+ * @param id The ID of the channel to fetch.
16
+ * @param force Whether to force fetching the channel from the API even if it exists in the cache.
17
+ * @returns A Promise that resolves to the fetched channel.
18
+ */
19
+ async fetch(id, force) {
20
+ let channel;
21
+ if (!force) {
22
+ channel = await this.client.cache.channels?.get(id);
23
+ if (channel)
24
+ return channel;
25
+ }
26
+ channel = await this.client.proxy.channels(id).get();
27
+ await this.client.cache.channels?.patch(id, undefined, channel);
28
+ return (0, channels_1.default)(channel, this.client);
69
29
  }
70
- get pins() {
71
- return {
72
- /**
73
- * Fetches pinned messages in the channel.
74
- * @param channelId The ID of the channel.
75
- * @returns A Promise that resolves to an array of pinned messages.
76
- */
77
- fetch: (channelId) => this.client.proxy
78
- .channels(channelId)
79
- .pins.get()
80
- .then(messages => messages.map(message => new structures_1.Message(this.client, message))),
81
- /**
82
- * Pins a message in the channel.
83
- * @param messageId The ID of the message to pin.
84
- * @param channelId The ID of the channel.
85
- * @param reason The reason for pinning the message.
86
- * @returns A Promise that resolves when the message is successfully pinned.
87
- */
88
- set: (messageId, channelId, reason) => this.client.proxy.channels(channelId).pins(messageId).put({ reason }),
89
- /**
90
- * Unpins a message in the channel.
91
- * @param messageId The ID of the message to unpin.
92
- * @param channelId The ID of the channel.
93
- * @param reason The reason for unpinning the message.
94
- * @returns A Promise that resolves when the message is successfully unpinned.
95
- */
96
- delete: (messageId, channelId, reason) => this.client.proxy.channels(channelId).pins(messageId).delete({ reason }),
97
- };
30
+ /**
31
+ * Deletes a channel by its ID.
32
+ * @param id The ID of the channel to delete.
33
+ * @param optional Optional parameters for the deletion.
34
+ * @returns A Promise that resolves to the deleted channel.
35
+ */
36
+ async delete(id, optional = { guildId: '@me' }) {
37
+ const res = await this.client.proxy.channels(id).delete({ reason: optional.reason });
38
+ await this.client.cache.channels?.removeIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId);
39
+ return (0, channels_1.default)(res, this.client);
40
+ }
41
+ /**
42
+ * Edits a channel by its ID.
43
+ * @param id The ID of the channel to edit.
44
+ * @param body The updated channel data.
45
+ * @param optional Optional parameters for the editing.
46
+ * @returns A Promise that resolves to the edited channel.
47
+ */
48
+ async edit(id, body, optional = { guildId: '@me' }) {
49
+ const res = await this.client.proxy.channels(id).patch({ body, reason: optional.reason });
50
+ await this.client.cache.channels?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res);
51
+ if (body.permission_overwrites && 'permission_overwrites' in res)
52
+ await this.client.cache.overwrites?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res.permission_overwrites);
53
+ return (0, channels_1.default)(res, this.client);
54
+ }
55
+ /**
56
+ * Sends a typing indicator to the channel.
57
+ * @param id The ID of the channel.
58
+ * @returns A Promise that resolves when the typing indicator is successfully sent.
59
+ */
60
+ async typing(id) {
61
+ await this.client.proxy.channels(id).typing.post();
98
62
  }
99
- get overwrites() {
63
+ async pins(channelId) {
64
+ const messages = await this.client.proxy.channels(channelId).pins.get();
65
+ return messages.map(message => new structures_1.Message(this.client, message));
66
+ }
67
+ /**
68
+ * Pins a message in the channel.
69
+ * @param messageId The ID of the message to pin.
70
+ * @param channelId The ID of the channel.
71
+ * @param reason The reason for pinning the message.
72
+ * @returns A Promise that resolves when the message is successfully pinned.
73
+ */
74
+ setPin(messageId, channelId, reason) {
75
+ return this.client.proxy.channels(channelId).pins(messageId).put({ reason });
76
+ }
77
+ /**
78
+ * Unpins a message in the channel.
79
+ * @param messageId The ID of the message to unpin.
80
+ * @param channelId The ID of the channel.
81
+ * @param reason The reason for unpinning the message.
82
+ * @returns A Promise that resolves when the message is successfully unpinned.
83
+ */
84
+ deletePin(messageId, channelId, reason) {
85
+ return this.client.proxy.channels(channelId).pins(messageId).delete({ reason });
86
+ }
87
+ async memberPermissions(channelId, member, checkAdmin = true) {
88
+ const permissions = await member.fetchPermissions();
89
+ if (checkAdmin && permissions.has(__1.PermissionFlagsBits.Administrator)) {
90
+ return new Permissions_1.PermissionsBitField(Permissions_1.PermissionsBitField.All);
91
+ }
92
+ const overwrites = await this.overwritesFor(channelId, member);
93
+ permissions.remove(overwrites.everyone?.deny.bits ?? 0n);
94
+ permissions.add(overwrites.everyone?.allow.bits ?? 0n);
95
+ permissions.remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny.bits) : 0n);
96
+ permissions.add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow.bits) : 0n);
97
+ permissions.remove(overwrites.member?.deny.bits ?? 0n);
98
+ permissions.add(overwrites.member?.allow.bits ?? 0n);
99
+ return permissions;
100
+ }
101
+ async overwritesFor(channelId, member) {
102
+ const roleOverwrites = [];
103
+ let memberOverwrites;
104
+ let everyoneOverwrites;
105
+ const channelOverwrites = (await this.client.cache.overwrites?.get(channelId)) ?? [];
106
+ for (const overwrite of channelOverwrites) {
107
+ if (overwrite.id === member.guildId) {
108
+ everyoneOverwrites = overwrite;
109
+ }
110
+ else if (member.roles.values.includes(overwrite.id)) {
111
+ roleOverwrites.push(overwrite);
112
+ }
113
+ else if (overwrite.id === member.id) {
114
+ memberOverwrites = overwrite;
115
+ }
116
+ }
100
117
  return {
101
- memberPermissions: async (channelId, member, checkAdmin = true) => {
102
- const permissions = await member.fetchPermissions();
103
- if (checkAdmin && permissions.has(__1.PermissionFlagsBits.Administrator)) {
104
- return new Permissions_1.PermissionsBitField(Permissions_1.PermissionsBitField.All);
105
- }
106
- const overwrites = await this.overwrites.overwritesFor(channelId, member);
107
- permissions.remove(overwrites.everyone?.deny.bits ?? 0n);
108
- permissions.add(overwrites.everyone?.allow.bits ?? 0n);
109
- permissions.remove(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.deny.bits) : 0n);
110
- permissions.add(overwrites.roles.length > 0 ? overwrites.roles.map(role => role.allow.bits) : 0n);
111
- permissions.remove(overwrites.member?.deny.bits ?? 0n);
112
- permissions.add(overwrites.member?.allow.bits ?? 0n);
113
- return permissions;
114
- },
115
- overwritesFor: async (channelId, member) => {
116
- const roleOverwrites = [];
117
- let memberOverwrites;
118
- let everyoneOverwrites;
119
- const channelOverwrites = (await this.client.cache.overwrites?.get(channelId)) ?? [];
120
- for (const overwrite of channelOverwrites) {
121
- if (overwrite.id === member.guildId) {
122
- everyoneOverwrites = overwrite;
123
- }
124
- else if (member.roles.values.includes(overwrite.id)) {
125
- roleOverwrites.push(overwrite);
126
- }
127
- else if (overwrite.id === member.id) {
128
- memberOverwrites = overwrite;
129
- }
130
- }
131
- return {
132
- everyone: everyoneOverwrites,
133
- roles: roleOverwrites,
134
- member: memberOverwrites,
135
- };
136
- },
137
- rolePermissions: async (channelId, role, checkAdmin = true) => {
138
- if (checkAdmin && role.permissions.has(__1.PermissionFlagsBits.Administrator)) {
139
- return new Permissions_1.PermissionsBitField(Permissions_1.PermissionsBitField.All);
140
- }
141
- const channelOverwrites = (await this.client.cache.overwrites?.get(channelId)) ?? [];
142
- const everyoneOverwrites = channelOverwrites.find(x => x.id === role.guildId);
143
- const roleOverwrites = channelOverwrites.find(x => x.id === role.id);
144
- const permissions = new Permissions_1.PermissionsBitField(role.permissions.bits);
145
- permissions.remove(everyoneOverwrites?.deny.bits ?? 0n);
146
- permissions.add(everyoneOverwrites?.allow.bits ?? 0n);
147
- permissions.remove(roleOverwrites?.deny.bits ?? 0n);
148
- permissions.add(roleOverwrites?.allow.bits ?? 0n);
149
- return permissions;
150
- },
118
+ everyone: everyoneOverwrites,
119
+ roles: roleOverwrites,
120
+ member: memberOverwrites,
151
121
  };
152
122
  }
123
+ async rolePermissions(channelId, role, checkAdmin = true) {
124
+ if (checkAdmin && role.permissions.has(__1.PermissionFlagsBits.Administrator)) {
125
+ return new Permissions_1.PermissionsBitField(Permissions_1.PermissionsBitField.All);
126
+ }
127
+ const channelOverwrites = (await this.client.cache.overwrites?.get(channelId)) ?? [];
128
+ const everyoneOverwrites = channelOverwrites.find(x => x.id === role.guildId);
129
+ const roleOverwrites = channelOverwrites.find(x => x.id === role.id);
130
+ const permissions = new Permissions_1.PermissionsBitField(role.permissions.bits);
131
+ permissions.remove(everyoneOverwrites?.deny.bits ?? 0n);
132
+ permissions.add(everyoneOverwrites?.allow.bits ?? 0n);
133
+ permissions.remove(roleOverwrites?.deny.bits ?? 0n);
134
+ permissions.add(roleOverwrites?.allow.bits ?? 0n);
135
+ return permissions;
136
+ }
153
137
  }
154
138
  exports.ChannelShorter = ChannelShorter;
@@ -0,0 +1,47 @@
1
+ import type { RESTPatchAPIGuildEmojiJSONBody, RESTPostAPIGuildEmojiJSONBody } from 'discord-api-types/v10';
2
+ import { GuildEmoji } from '../..';
3
+ import type { ImageResolvable } from '../types/resolvables';
4
+ import type { OmitInsert } from '../types/util';
5
+ import { BaseShorter } from './base';
6
+ export declare class EmojiShorter extends BaseShorter {
7
+ /**
8
+ * Retrieves a list of emojis in the guild.
9
+ * @param guildId The ID of the guild.
10
+ * @param force Whether to force fetching emojis from the API even if they exist in the cache.
11
+ * @returns A Promise that resolves to an array of emojis.
12
+ */
13
+ list(guildId: string, force?: boolean): Promise<GuildEmoji[]>;
14
+ /**
15
+ * Creates a new emoji in the guild.
16
+ * @param guildId The ID of the guild.
17
+ * @param body The data for creating the emoji.
18
+ * @returns A Promise that resolves to the created emoji.
19
+ */
20
+ create(guildId: string, body: OmitInsert<RESTPostAPIGuildEmojiJSONBody, 'image', {
21
+ image: ImageResolvable;
22
+ }>): Promise<void>;
23
+ /**
24
+ * Fetches an emoji by its ID.
25
+ * @param guildId The ID of the guild.
26
+ * @param emojiId The ID of the emoji to fetch.
27
+ * @param force Whether to force fetching the emoji from the API even if it exists in the cache.
28
+ * @returns A Promise that resolves to the fetched emoji.
29
+ */
30
+ fetch(guildId: string, emojiId: string, force?: boolean): Promise<GuildEmoji>;
31
+ /**
32
+ * Deletes an emoji from the guild.
33
+ * @param guildId The ID of the guild.
34
+ * @param emojiId The ID of the emoji to delete.
35
+ * @param reason The reason for deleting the emoji.
36
+ */
37
+ delete(guildId: string, emojiId: string, reason?: string): Promise<void>;
38
+ /**
39
+ * Edits an emoji in the guild.
40
+ * @param guildId The ID of the guild.
41
+ * @param emojiId The ID of the emoji to edit.
42
+ * @param body The data to update the emoji with.
43
+ * @param reason The reason for editing the emoji.
44
+ * @returns A Promise that resolves to the edited emoji.
45
+ */
46
+ edit(guildId: string, emojiId: string, body: RESTPatchAPIGuildEmojiJSONBody, reason?: string): Promise<GuildEmoji>;
47
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmojiShorter = void 0;
4
+ const __1 = require("../..");
5
+ const builders_1 = require("../../builders");
6
+ const base_1 = require("./base");
7
+ class EmojiShorter extends base_1.BaseShorter {
8
+ /**
9
+ * Retrieves a list of emojis in the guild.
10
+ * @param guildId The ID of the guild.
11
+ * @param force Whether to force fetching emojis from the API even if they exist in the cache.
12
+ * @returns A Promise that resolves to an array of emojis.
13
+ */
14
+ async list(guildId, force = false) {
15
+ let emojis;
16
+ if (!force) {
17
+ emojis = (await this.client.cache.emojis?.values(guildId)) ?? [];
18
+ if (emojis.length) {
19
+ return emojis;
20
+ }
21
+ }
22
+ emojis = await this.client.proxy.guilds(guildId).emojis.get();
23
+ await this.client.cache.emojis?.set(emojis.map(x => [x.id, x]), guildId);
24
+ return emojis.map(m => new __1.GuildEmoji(this.client, m, guildId));
25
+ }
26
+ /**
27
+ * Creates a new emoji in the guild.
28
+ * @param guildId The ID of the guild.
29
+ * @param body The data for creating the emoji.
30
+ * @returns A Promise that resolves to the created emoji.
31
+ */
32
+ async create(guildId, body) {
33
+ const bodyResolved = { ...body, image: await (0, builders_1.resolveImage)(body.image) };
34
+ const emoji = await this.client.proxy.guilds(guildId).emojis.post({
35
+ body: bodyResolved,
36
+ });
37
+ await this.client.cache.channels?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
38
+ }
39
+ /**
40
+ * Fetches an emoji by its ID.
41
+ * @param guildId The ID of the guild.
42
+ * @param emojiId The ID of the emoji to fetch.
43
+ * @param force Whether to force fetching the emoji from the API even if it exists in the cache.
44
+ * @returns A Promise that resolves to the fetched emoji.
45
+ */
46
+ async fetch(guildId, emojiId, force = false) {
47
+ let emoji;
48
+ if (!force) {
49
+ emoji = await this.client.cache.emojis?.get(emojiId);
50
+ if (emoji)
51
+ return emoji;
52
+ }
53
+ emoji = await this.client.proxy.guilds(guildId).emojis(emojiId).get();
54
+ return new __1.GuildEmoji(this.client, emoji, guildId);
55
+ }
56
+ /**
57
+ * Deletes an emoji from the guild.
58
+ * @param guildId The ID of the guild.
59
+ * @param emojiId The ID of the emoji to delete.
60
+ * @param reason The reason for deleting the emoji.
61
+ */
62
+ async delete(guildId, emojiId, reason) {
63
+ await this.client.proxy.guilds(guildId).emojis(emojiId).delete({ reason });
64
+ await this.client.cache.channels?.removeIfNI('GuildEmojisAndStickers', emojiId, guildId);
65
+ }
66
+ /**
67
+ * Edits an emoji in the guild.
68
+ * @param guildId The ID of the guild.
69
+ * @param emojiId The ID of the emoji to edit.
70
+ * @param body The data to update the emoji with.
71
+ * @param reason The reason for editing the emoji.
72
+ * @returns A Promise that resolves to the edited emoji.
73
+ */
74
+ async edit(guildId, emojiId, body, reason) {
75
+ const emoji = await this.client.proxy.guilds(guildId).emojis(emojiId).patch({ body, reason });
76
+ await this.client.cache.channels?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
77
+ return new __1.GuildEmoji(this.client, emoji, guildId);
78
+ }
79
+ }
80
+ exports.EmojiShorter = EmojiShorter;