@fluxerjs/core 1.0.8 → 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 (37) hide show
  1. package/dist/{Channel-TWPDKW2P.mjs → Channel-WJZZSNML.mjs} +3 -1
  2. package/dist/{ClientUser-2K2BACK7.mjs → ClientUser-DJO2FS7P.mjs} +1 -1
  3. package/dist/Guild-2P77HBQM.mjs +11 -0
  4. package/dist/GuildBan-7CXLTPKY.mjs +7 -0
  5. package/dist/GuildMember-43B5E5CH.mjs +9 -0
  6. package/dist/{Message-G2QIKZQK.mjs → Invite-UM5BU5A6.mjs} +3 -3
  7. package/dist/Message-OFIVTTAZ.mjs +9 -0
  8. package/dist/{MessageReaction-XRPYZDSC.mjs → MessageReaction-V4UZ7OXE.mjs} +1 -1
  9. package/dist/{Role-SVLWIAMN.mjs → Role-5MWSGL66.mjs} +1 -1
  10. package/dist/Webhook-RWDDYW2Q.mjs +10 -0
  11. package/dist/chunk-4XJIM6SC.mjs +315 -0
  12. package/dist/chunk-AH7KYH2Z.mjs +50 -0
  13. package/dist/{chunk-HBF5QEDH.mjs → chunk-CEABHTAF.mjs} +1 -0
  14. package/dist/chunk-CJVQNARM.mjs +145 -0
  15. package/dist/chunk-DQ4TNBPG.mjs +63 -0
  16. package/dist/chunk-DUQAD7F6.mjs +173 -0
  17. package/dist/{chunk-4GCZFOS5.mjs → chunk-JHNKZIHY.mjs} +54 -3
  18. package/dist/chunk-LU2SNC5G.mjs +392 -0
  19. package/dist/chunk-PM2IUGNR.mjs +29 -0
  20. package/dist/chunk-QEXIYXXU.mjs +62 -0
  21. package/dist/chunk-UXIF75BV.mjs +36 -0
  22. package/dist/chunk-V7LPVPGH.mjs +305 -0
  23. package/dist/chunk-X6K3ZD62.mjs +53 -0
  24. package/dist/index.d.mts +802 -160
  25. package/dist/index.d.ts +802 -160
  26. package/dist/index.js +1467 -262
  27. package/dist/index.mjs +292 -119
  28. package/package.json +7 -7
  29. package/dist/Guild-CMZGA6DW.mjs +0 -10
  30. package/dist/GuildMember-DW2N6ITI.mjs +0 -7
  31. package/dist/Webhook-2MQESB7Z.mjs +0 -7
  32. package/dist/chunk-CO5EL5LH.mjs +0 -168
  33. package/dist/chunk-CZIO2D7F.mjs +0 -207
  34. package/dist/chunk-JVEOQFUX.mjs +0 -52
  35. package/dist/chunk-SQVCCSNN.mjs +0 -41
  36. package/dist/chunk-TJVZEILY.mjs +0 -120
  37. package/dist/chunk-ZGMM6IPQ.mjs +0 -79
@@ -6,7 +6,9 @@ import {
6
6
  LinkChannel,
7
7
  TextChannel,
8
8
  VoiceChannel
9
- } from "./chunk-CZIO2D7F.mjs";
9
+ } from "./chunk-LU2SNC5G.mjs";
10
+ import "./chunk-AH7KYH2Z.mjs";
11
+ import "./chunk-PM2IUGNR.mjs";
10
12
  import "./chunk-XNS4O6QJ.mjs";
11
13
  export {
12
14
  CategoryChannel,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ClientUser
3
- } from "./chunk-4GCZFOS5.mjs";
3
+ } from "./chunk-JHNKZIHY.mjs";
4
4
  import "./chunk-HQMYRYMY.mjs";
5
5
  import "./chunk-XNS4O6QJ.mjs";
6
6
  export {
@@ -0,0 +1,11 @@
1
+ import {
2
+ Guild
3
+ } from "./chunk-4XJIM6SC.mjs";
4
+ import "./chunk-DUQAD7F6.mjs";
5
+ import "./chunk-X6K3ZD62.mjs";
6
+ import "./chunk-HQMYRYMY.mjs";
7
+ import "./chunk-DQ4TNBPG.mjs";
8
+ import "./chunk-XNS4O6QJ.mjs";
9
+ export {
10
+ Guild
11
+ };
@@ -0,0 +1,7 @@
1
+ import {
2
+ GuildBan
3
+ } from "./chunk-UXIF75BV.mjs";
4
+ import "./chunk-XNS4O6QJ.mjs";
5
+ export {
6
+ GuildBan
7
+ };
@@ -0,0 +1,9 @@
1
+ import {
2
+ GuildMember
3
+ } from "./chunk-DUQAD7F6.mjs";
4
+ import "./chunk-X6K3ZD62.mjs";
5
+ import "./chunk-HQMYRYMY.mjs";
6
+ import "./chunk-XNS4O6QJ.mjs";
7
+ export {
8
+ GuildMember
9
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
- Message
3
- } from "./chunk-CO5EL5LH.mjs";
2
+ Invite
3
+ } from "./chunk-QEXIYXXU.mjs";
4
4
  import "./chunk-XNS4O6QJ.mjs";
5
5
  export {
6
- Message
6
+ Invite
7
7
  };
@@ -0,0 +1,9 @@
1
+ import {
2
+ Message
3
+ } from "./chunk-V7LPVPGH.mjs";
4
+ import "./chunk-AH7KYH2Z.mjs";
5
+ import "./chunk-PM2IUGNR.mjs";
6
+ import "./chunk-XNS4O6QJ.mjs";
7
+ export {
8
+ Message
9
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MessageReaction
3
- } from "./chunk-HBF5QEDH.mjs";
3
+ } from "./chunk-CEABHTAF.mjs";
4
4
  import "./chunk-XNS4O6QJ.mjs";
5
5
  export {
6
6
  MessageReaction
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Role
3
- } from "./chunk-SQVCCSNN.mjs";
3
+ } from "./chunk-DQ4TNBPG.mjs";
4
4
  import "./chunk-XNS4O6QJ.mjs";
5
5
  export {
6
6
  Role
@@ -0,0 +1,10 @@
1
+ import {
2
+ Webhook
3
+ } from "./chunk-CJVQNARM.mjs";
4
+ import "./chunk-PM2IUGNR.mjs";
5
+ import "./chunk-X6K3ZD62.mjs";
6
+ import "./chunk-HQMYRYMY.mjs";
7
+ import "./chunk-XNS4O6QJ.mjs";
8
+ export {
9
+ Webhook
10
+ };
@@ -0,0 +1,315 @@
1
+ import {
2
+ GuildMember
3
+ } from "./chunk-DUQAD7F6.mjs";
4
+ import {
5
+ CDN_URL
6
+ } from "./chunk-HQMYRYMY.mjs";
7
+ import {
8
+ Role
9
+ } from "./chunk-DQ4TNBPG.mjs";
10
+ import {
11
+ Base
12
+ } from "./chunk-XNS4O6QJ.mjs";
13
+
14
+ // src/structures/Guild.ts
15
+ import { parseRoleMention } from "@fluxerjs/util";
16
+ import { FluxerAPIError } from "@fluxerjs/rest";
17
+
18
+ // src/errors/FluxerError.ts
19
+ var FluxerError = class _FluxerError extends Error {
20
+ code;
21
+ constructor(message, options) {
22
+ super(message, options?.cause ? { cause: options.cause } : void 0);
23
+ this.name = "FluxerError";
24
+ this.code = options?.code;
25
+ Object.setPrototypeOf(this, _FluxerError.prototype);
26
+ }
27
+ };
28
+
29
+ // src/errors/ErrorCodes.ts
30
+ var ErrorCodes = {
31
+ ClientNotReady: "CLIENT_NOT_READY",
32
+ InvalidToken: "INVALID_TOKEN",
33
+ AlreadyLoggedIn: "ALREADY_LOGGED_IN",
34
+ ChannelNotFound: "CHANNEL_NOT_FOUND",
35
+ MessageNotFound: "MESSAGE_NOT_FOUND",
36
+ GuildNotFound: "GUILD_NOT_FOUND",
37
+ MemberNotFound: "MEMBER_NOT_FOUND"
38
+ };
39
+
40
+ // src/structures/Guild.ts
41
+ import { Collection } from "@fluxerjs/collection";
42
+ import { Routes } from "@fluxerjs/types";
43
+ var Guild = class extends Base {
44
+ client;
45
+ id;
46
+ name;
47
+ icon;
48
+ banner;
49
+ ownerId;
50
+ /** Invite splash image hash. Null if none. */
51
+ splash;
52
+ /** Custom vanity URL code (e.g. fluxer.gg/code). Null if none. */
53
+ vanityURLCode;
54
+ /** Enabled guild features. */
55
+ features;
56
+ verificationLevel;
57
+ defaultMessageNotifications;
58
+ explicitContentFilter;
59
+ /** AFK voice channel ID. Null if none. */
60
+ afkChannelId;
61
+ /** AFK timeout in seconds. */
62
+ afkTimeout;
63
+ /** System messages channel ID. Null if none. */
64
+ systemChannelId;
65
+ /** Rules/guidelines channel ID. Null if none. */
66
+ rulesChannelId;
67
+ nsfwLevel;
68
+ mfaLevel;
69
+ /** Banner image width. Optional. */
70
+ bannerWidth;
71
+ /** Banner image height. Optional. */
72
+ bannerHeight;
73
+ /** Splash image width. Optional. */
74
+ splashWidth;
75
+ /** Splash image height. Optional. */
76
+ splashHeight;
77
+ members = new Collection();
78
+ channels = new Collection();
79
+ roles = new Collection();
80
+ /** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
81
+ constructor(client, data) {
82
+ super();
83
+ this.client = client;
84
+ this.id = data.id;
85
+ this.name = data.name;
86
+ this.icon = data.icon ?? null;
87
+ this.banner = data.banner ?? null;
88
+ this.ownerId = data.owner_id ?? data.ownerId ?? "";
89
+ this.splash = data.splash ?? null;
90
+ this.vanityURLCode = data.vanity_url_code ?? null;
91
+ this.features = data.features ?? [];
92
+ this.verificationLevel = data.verification_level ?? 0;
93
+ this.defaultMessageNotifications = data.default_message_notifications ?? 0;
94
+ this.explicitContentFilter = data.explicit_content_filter ?? 0;
95
+ this.afkChannelId = data.afk_channel_id ?? null;
96
+ this.afkTimeout = data.afk_timeout ?? 0;
97
+ this.systemChannelId = data.system_channel_id ?? null;
98
+ this.rulesChannelId = data.rules_channel_id ?? null;
99
+ this.nsfwLevel = data.nsfw_level ?? 0;
100
+ this.mfaLevel = data.mfa_level ?? 0;
101
+ this.bannerWidth = data.banner_width ?? null;
102
+ this.bannerHeight = data.banner_height ?? null;
103
+ this.splashWidth = data.splash_width ?? null;
104
+ this.splashHeight = data.splash_height ?? null;
105
+ for (const r of data.roles ?? []) {
106
+ this.roles.set(r.id, new Role(client, r, this.id));
107
+ }
108
+ }
109
+ /** Get the guild icon URL, or null if no icon. */
110
+ iconURL(options) {
111
+ if (!this.icon) return null;
112
+ const size = options?.size ? `?size=${options.size}` : "";
113
+ return `${CDN_URL}/icons/${this.id}/${this.icon}.png${size}`;
114
+ }
115
+ /** Get the guild banner URL, or null if no banner. */
116
+ bannerURL(options) {
117
+ if (!this.banner) return null;
118
+ const size = options?.size ? `?size=${options.size}` : "";
119
+ return `${CDN_URL}/banners/${this.id}/${this.banner}.png${size}`;
120
+ }
121
+ /** Get the guild splash (invite background) URL, or null if no splash. */
122
+ splashURL(options) {
123
+ if (!this.splash) return null;
124
+ const size = options?.size ? `?size=${options.size}` : "";
125
+ return `${CDN_URL}/splashes/${this.id}/${this.splash}.png${size}`;
126
+ }
127
+ /**
128
+ * Add a role to a member by user ID. Does not require fetching the member first.
129
+ * @param userId - The user ID of the member
130
+ * @param roleId - The role ID to add (or use guild.resolveRoleId for mention/name resolution)
131
+ * Requires Manage Roles permission.
132
+ */
133
+ async addRoleToMember(userId, roleId) {
134
+ await this.client.rest.put(Routes.guildMemberRole(this.id, userId, roleId));
135
+ }
136
+ /**
137
+ * Remove a role from a member by user ID. Does not require fetching the member first.
138
+ * @param userId - The user ID of the member
139
+ * @param roleId - The role ID to remove
140
+ * Requires Manage Roles permission.
141
+ */
142
+ async removeRoleFromMember(userId, roleId) {
143
+ await this.client.rest.delete(Routes.guildMemberRole(this.id, userId, roleId));
144
+ }
145
+ /**
146
+ * Resolve a role ID from an argument (role mention, raw ID, or name).
147
+ * Fetches guild roles if name is provided.
148
+ * @param arg - Role mention (@role), role ID, or role name
149
+ * @returns The role ID, or null if not found
150
+ */
151
+ async resolveRoleId(arg) {
152
+ const parsed = parseRoleMention(arg);
153
+ if (parsed) return parsed;
154
+ if (/^\d{17,19}$/.test(arg.trim())) return arg.trim();
155
+ const cached = this.roles.find(
156
+ (r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase())
157
+ );
158
+ if (cached) return cached.id;
159
+ const roles = await this.client.rest.get(Routes.guildRoles(this.id));
160
+ const list = Array.isArray(roles) ? roles : Object.values(roles ?? {});
161
+ const role = list.find((r) => !!(r.name && r.name.toLowerCase() === arg.trim().toLowerCase()));
162
+ if (role) {
163
+ this.roles.set(role.id, new Role(this.client, role, this.id));
164
+ return role.id;
165
+ }
166
+ return null;
167
+ }
168
+ /**
169
+ * Ban a user from this guild.
170
+ * @param userId - The user ID to ban
171
+ * @param options - Optional reason, delete_message_days (0–7), and ban_duration_seconds (temporary ban).
172
+ * ban_duration_seconds: 0 = permanent, or use 3600, 43200, 86400, 259200, 432000, 604800, 1209600, 2592000.
173
+ * Requires Ban Members permission.
174
+ */
175
+ async ban(userId, options) {
176
+ const body = {};
177
+ if (options?.reason) body.reason = options.reason;
178
+ if (options?.delete_message_days != null)
179
+ body.delete_message_days = options.delete_message_days;
180
+ if (options?.ban_duration_seconds != null)
181
+ body.ban_duration_seconds = options.ban_duration_seconds;
182
+ await this.client.rest.put(Routes.guildBan(this.id, userId), {
183
+ body: Object.keys(body).length ? body : void 0,
184
+ auth: true
185
+ });
186
+ }
187
+ /**
188
+ * Fetch guild bans. Requires Ban Members permission.
189
+ * @returns List of GuildBan objects
190
+ */
191
+ async fetchBans() {
192
+ const { GuildBan } = await import("./GuildBan-7CXLTPKY.mjs");
193
+ const data = await this.client.rest.get(Routes.guildBans(this.id));
194
+ const list = Array.isArray(data) ? data : data?.bans ?? [];
195
+ return list.map((b) => new GuildBan(this.client, { ...b, guild_id: this.id }, this.id));
196
+ }
197
+ /**
198
+ * Remove a ban (unban a user).
199
+ * @param userId - The user ID to unban
200
+ * Requires Ban Members permission.
201
+ */
202
+ async unban(userId) {
203
+ await this.client.rest.delete(Routes.guildBan(this.id, userId), { auth: true });
204
+ }
205
+ /**
206
+ * Kick a member from this guild.
207
+ * @param userId - The user ID to kick
208
+ * Requires Kick Members permission.
209
+ */
210
+ async kick(userId) {
211
+ await this.client.rest.delete(Routes.guildMember(this.id, userId), { auth: true });
212
+ }
213
+ /**
214
+ * Fetch a guild member by user ID.
215
+ * @param userId - The user ID of the member to fetch
216
+ * @returns The guild member
217
+ * @throws FluxerError with MEMBER_NOT_FOUND if user is not in the guild (404)
218
+ * @throws FluxerError with cause for permission denied (403) or other REST errors
219
+ */
220
+ async fetchMember(userId) {
221
+ try {
222
+ const data = await this.client.rest.get(
223
+ Routes.guildMember(this.id, userId)
224
+ );
225
+ const member = new GuildMember(this.client, { ...data, guild_id: this.id }, this);
226
+ this.members.set(member.id, member);
227
+ return member;
228
+ } catch (err) {
229
+ const statusCode = err instanceof FluxerAPIError ? err.statusCode : err?.statusCode;
230
+ if (statusCode === 404) {
231
+ throw new FluxerError(`Member ${userId} not found in guild`, {
232
+ code: ErrorCodes.MemberNotFound,
233
+ cause: err
234
+ });
235
+ }
236
+ throw err instanceof FluxerError ? err : new FluxerError("Failed to fetch guild member", { cause: err });
237
+ }
238
+ }
239
+ /**
240
+ * Fetch guild audit logs. Requires View Audit Log permission.
241
+ * @param options - Optional limit, before, after, user_id, action_type for filtering
242
+ */
243
+ async fetchAuditLogs(options) {
244
+ const params = new URLSearchParams();
245
+ if (options?.limit != null) params.set("limit", String(options.limit));
246
+ if (options?.before) params.set("before", options.before);
247
+ if (options?.after) params.set("after", options.after);
248
+ if (options?.userId) params.set("user_id", options.userId);
249
+ if (options?.actionType != null) params.set("action_type", String(options.actionType));
250
+ const qs = params.toString();
251
+ const url = Routes.guildAuditLogs(this.id) + (qs ? `?${qs}` : "");
252
+ return this.client.rest.get(url);
253
+ }
254
+ /** Fetch all webhooks in this guild. Returned webhooks do not include the token (cannot send). */
255
+ async fetchWebhooks() {
256
+ const { Webhook } = await import("./Webhook-RWDDYW2Q.mjs");
257
+ const data = await this.client.rest.get(Routes.guildWebhooks(this.id));
258
+ const list = Array.isArray(data) ? data : Object.values(data ?? {});
259
+ return list.map((w) => new Webhook(this.client, w));
260
+ }
261
+ /**
262
+ * Create a channel in this guild.
263
+ * @param data - Channel data: type (0=text, 2=voice, 4=category, 5=link), name, and optional parent_id, topic, bitrate, user_limit, nsfw, permission_overwrites
264
+ * Requires Manage Channels permission.
265
+ */
266
+ async createChannel(data) {
267
+ const { Channel } = await import("./Channel-WJZZSNML.mjs");
268
+ const created = await this.client.rest.post(Routes.guildChannels(this.id), {
269
+ body: data,
270
+ auth: true
271
+ });
272
+ const channel = Channel.from(this.client, created);
273
+ if (channel) {
274
+ this.client.channels.set(channel.id, channel);
275
+ this.channels.set(channel.id, channel);
276
+ }
277
+ return channel;
278
+ }
279
+ /**
280
+ * Fetch all channels in this guild.
281
+ * @returns Array of GuildChannel objects (cached in guild.channels and client.channels)
282
+ */
283
+ async fetchChannels() {
284
+ const { Channel } = await import("./Channel-WJZZSNML.mjs");
285
+ const data = await this.client.rest.get(Routes.guildChannels(this.id));
286
+ const list = Array.isArray(data) ? data : Object.values(data ?? {});
287
+ const channels = [];
288
+ for (const ch of list) {
289
+ const channel = Channel.from(this.client, ch);
290
+ if (channel) {
291
+ this.client.channels.set(channel.id, channel);
292
+ this.channels.set(channel.id, channel);
293
+ channels.push(channel);
294
+ }
295
+ }
296
+ return channels;
297
+ }
298
+ /**
299
+ * Update channel positions.
300
+ * @param updates - Array of { id, position?, parent_id?, lock_permissions? }
301
+ * Requires Manage Channels permission.
302
+ */
303
+ async setChannelPositions(updates) {
304
+ await this.client.rest.patch(Routes.guildChannels(this.id), {
305
+ body: updates,
306
+ auth: true
307
+ });
308
+ }
309
+ };
310
+
311
+ export {
312
+ FluxerError,
313
+ ErrorCodes,
314
+ Guild
315
+ };
@@ -0,0 +1,50 @@
1
+ // src/util/Events.ts
2
+ var Events = {
3
+ Ready: "ready",
4
+ MessageCreate: "messageCreate",
5
+ MessageUpdate: "messageUpdate",
6
+ MessageDelete: "messageDelete",
7
+ MessageDeleteBulk: "messageDeleteBulk",
8
+ MessageReactionAdd: "messageReactionAdd",
9
+ MessageReactionRemove: "messageReactionRemove",
10
+ MessageReactionRemoveAll: "messageReactionRemoveAll",
11
+ MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
12
+ InteractionCreate: "interactionCreate",
13
+ GuildCreate: "guildCreate",
14
+ GuildUpdate: "guildUpdate",
15
+ GuildDelete: "guildDelete",
16
+ GuildBanAdd: "guildBanAdd",
17
+ GuildBanRemove: "guildBanRemove",
18
+ GuildEmojisUpdate: "guildEmojisUpdate",
19
+ GuildStickersUpdate: "guildStickersUpdate",
20
+ GuildIntegrationsUpdate: "guildIntegrationsUpdate",
21
+ GuildMemberAdd: "guildMemberAdd",
22
+ GuildMemberUpdate: "guildMemberUpdate",
23
+ GuildMemberRemove: "guildMemberRemove",
24
+ GuildRoleCreate: "guildRoleCreate",
25
+ GuildRoleUpdate: "guildRoleUpdate",
26
+ GuildRoleDelete: "guildRoleDelete",
27
+ GuildScheduledEventCreate: "guildScheduledEventCreate",
28
+ GuildScheduledEventUpdate: "guildScheduledEventUpdate",
29
+ GuildScheduledEventDelete: "guildScheduledEventDelete",
30
+ ChannelCreate: "channelCreate",
31
+ ChannelUpdate: "channelUpdate",
32
+ ChannelDelete: "channelDelete",
33
+ ChannelPinsUpdate: "channelPinsUpdate",
34
+ InviteCreate: "inviteCreate",
35
+ InviteDelete: "inviteDelete",
36
+ TypingStart: "typingStart",
37
+ UserUpdate: "userUpdate",
38
+ PresenceUpdate: "presenceUpdate",
39
+ VoiceStateUpdate: "voiceStateUpdate",
40
+ VoiceServerUpdate: "voiceServerUpdate",
41
+ VoiceStatesSync: "voiceStatesSync",
42
+ WebhooksUpdate: "webhooksUpdate",
43
+ Resumed: "resumed",
44
+ Error: "error",
45
+ Debug: "debug"
46
+ };
47
+
48
+ export {
49
+ Events
50
+ };
@@ -31,6 +31,7 @@ var MessageReaction = class extends Base {
31
31
  /**
32
32
  * Fetch the message this reaction belongs to.
33
33
  * Use when you need to edit, delete, or otherwise interact with the message.
34
+ * @throws FluxerError with MESSAGE_NOT_FOUND if the message does not exist
34
35
  */
35
36
  async fetchMessage() {
36
37
  return this.client.channels.fetchMessage(this.channelId, this.messageId);
@@ -0,0 +1,145 @@
1
+ import {
2
+ buildSendBody
3
+ } from "./chunk-PM2IUGNR.mjs";
4
+ import {
5
+ cdnAvatarURL
6
+ } from "./chunk-X6K3ZD62.mjs";
7
+ import {
8
+ Base
9
+ } from "./chunk-XNS4O6QJ.mjs";
10
+
11
+ // src/structures/Webhook.ts
12
+ import { Routes } from "@fluxerjs/types";
13
+ var Webhook = class _Webhook extends Base {
14
+ client;
15
+ id;
16
+ guildId;
17
+ channelId;
18
+ name;
19
+ avatar;
20
+ /** Present only when webhook was created via createWebhook(); not returned when fetching. */
21
+ token;
22
+ /** User who created the webhook. */
23
+ user;
24
+ /** @param data - API webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token) */
25
+ constructor(client, data) {
26
+ super();
27
+ this.client = client;
28
+ this.id = data.id;
29
+ this.guildId = data.guild_id;
30
+ this.channelId = data.channel_id;
31
+ this.name = data.name ?? "Unknown";
32
+ this.avatar = data.avatar ?? null;
33
+ this.token = data.token ?? null;
34
+ this.user = client.getOrCreateUser(data.user);
35
+ }
36
+ /**
37
+ * Get the URL for this webhook's avatar.
38
+ * Returns null if the webhook has no custom avatar.
39
+ */
40
+ avatarURL(options) {
41
+ return cdnAvatarURL(this.id, this.avatar, options);
42
+ }
43
+ /** Delete this webhook. Requires bot token with Manage Webhooks permission. */
44
+ async delete() {
45
+ await this.client.rest.delete(Routes.webhook(this.id), { auth: true });
46
+ }
47
+ /**
48
+ * Edit this webhook. With token: name and avatar only. Without token (bot auth): name, avatar, and channel_id.
49
+ * @param options - Fields to update (name, avatar, channel_id when using bot auth)
50
+ * @returns This webhook instance with updated fields
51
+ */
52
+ async edit(options) {
53
+ const body = {};
54
+ if (options.name !== void 0) body.name = options.name;
55
+ if (options.avatar !== void 0) body.avatar = options.avatar;
56
+ if ("channel_id" in options && options.channel_id !== void 0 && !this.token) {
57
+ body.channel_id = options.channel_id;
58
+ }
59
+ if (this.token) {
60
+ const data2 = await this.client.rest.patch(Routes.webhookExecute(this.id, this.token), {
61
+ body,
62
+ auth: false
63
+ });
64
+ const w2 = data2;
65
+ this.name = w2.name ?? this.name;
66
+ this.avatar = w2.avatar ?? null;
67
+ return this;
68
+ }
69
+ const data = await this.client.rest.patch(Routes.webhook(this.id), {
70
+ body,
71
+ auth: true
72
+ });
73
+ const w = data;
74
+ this.name = w.name ?? this.name;
75
+ this.avatar = w.avatar ?? null;
76
+ this.channelId = w.channel_id ?? this.channelId;
77
+ return this;
78
+ }
79
+ /**
80
+ * Send a message via this webhook. Requires the webhook token (only present when created, not when fetched).
81
+ * @param options - Text content or object with content, embeds, username, avatar_url, tts, files, attachments
82
+ * @param wait - If true, waits for the API and returns the created Message; otherwise returns void (204)
83
+ * @throws Error if token is not available
84
+ * @example
85
+ * await webhook.send('Hello!');
86
+ * await webhook.send({ embeds: [embed.toJSON()] });
87
+ * await webhook.send({ content: 'File attached', files: [{ name: 'data.txt', data: buffer }] });
88
+ * const msg = await webhook.send({ content: 'Hi' }, true);
89
+ */
90
+ async send(options, wait) {
91
+ if (!this.token) {
92
+ throw new Error(
93
+ "Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send."
94
+ );
95
+ }
96
+ const opts = typeof options === "string" ? { content: options } : options;
97
+ const body = buildSendBody(options);
98
+ if (opts.username !== void 0) body.username = opts.username;
99
+ if (opts.avatar_url !== void 0) body.avatar_url = opts.avatar_url;
100
+ if (opts.tts !== void 0) body.tts = opts.tts;
101
+ const route = Routes.webhookExecute(this.id, this.token) + (wait ? "?wait=true" : "");
102
+ const postOptions = opts.files?.length ? { body, files: opts.files, auth: false } : { body, auth: false };
103
+ const data = await this.client.rest.post(
104
+ route,
105
+ postOptions
106
+ );
107
+ if (wait && data) {
108
+ const { Message } = await import("./Message-OFIVTTAZ.mjs");
109
+ return new Message(this.client, data);
110
+ }
111
+ return void 0;
112
+ }
113
+ /**
114
+ * Fetch a webhook by ID using bot auth.
115
+ * @param client - The client instance
116
+ * @param webhookId - The webhook ID
117
+ * @returns Webhook without token (cannot send)
118
+ */
119
+ static async fetch(client, webhookId) {
120
+ const data = await client.rest.get(Routes.webhook(webhookId));
121
+ return new _Webhook(client, data);
122
+ }
123
+ /**
124
+ * Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).
125
+ * @param client - The client instance
126
+ * @param webhookId - The webhook ID
127
+ * @param token - The webhook token (from createWebhook or stored)
128
+ * @param options - Optional channelId, guildId, name for display
129
+ */
130
+ static fromToken(client, webhookId, token, options) {
131
+ return new _Webhook(client, {
132
+ id: webhookId,
133
+ guild_id: options?.guildId ?? "",
134
+ channel_id: options?.channelId ?? "",
135
+ name: options?.name ?? "Webhook",
136
+ avatar: null,
137
+ token,
138
+ user: { id: "", username: "webhook", discriminator: "0" }
139
+ });
140
+ }
141
+ };
142
+
143
+ export {
144
+ Webhook
145
+ };
@@ -0,0 +1,63 @@
1
+ import {
2
+ Base
3
+ } from "./chunk-XNS4O6QJ.mjs";
4
+
5
+ // src/structures/Role.ts
6
+ import { PermissionFlags } from "@fluxerjs/util";
7
+ var Role = class extends Base {
8
+ client;
9
+ id;
10
+ guildId;
11
+ name;
12
+ color;
13
+ position;
14
+ permissions;
15
+ hoist;
16
+ mentionable;
17
+ unicodeEmoji;
18
+ /** Separately sorted position for hoisted roles. Null if not set. */
19
+ hoistPosition;
20
+ /** @param client - The client instance */
21
+ /** @param data - API role from GET /guilds/{id}/roles or gateway role events */
22
+ /** @param guildId - The guild this role belongs to */
23
+ constructor(client, data, guildId) {
24
+ super();
25
+ this.client = client;
26
+ this.id = data.id;
27
+ this.guildId = guildId;
28
+ this.name = data.name;
29
+ this.color = data.color;
30
+ this.position = data.position;
31
+ this.permissions = data.permissions;
32
+ this.hoist = !!data.hoist;
33
+ this.mentionable = !!data.mentionable;
34
+ this.unicodeEmoji = data.unicode_emoji ?? null;
35
+ this.hoistPosition = data.hoist_position ?? null;
36
+ }
37
+ /** Returns a mention string (e.g. `<@&123456>`). */
38
+ toString() {
39
+ return `<@&${this.id}>`;
40
+ }
41
+ /**
42
+ * Check if this role has a permission. Administrator grants all permissions.
43
+ * @param permission - Permission flag, name, or resolvable
44
+ * @returns true if the role has the permission
45
+ * @example
46
+ * if (role.has(PermissionFlags.BanMembers)) { ... }
47
+ * if (role.has('ManageChannels')) { ... }
48
+ */
49
+ has(permission) {
50
+ const perm = typeof permission === "number" ? permission : PermissionFlags[permission];
51
+ if (perm === void 0) return false;
52
+ const permNum = Number(perm);
53
+ const rolePerms = BigInt(this.permissions);
54
+ const permBig = BigInt(permNum);
55
+ if (permBig < 0) return false;
56
+ if ((rolePerms & BigInt(PermissionFlags.Administrator)) !== 0n) return true;
57
+ return (rolePerms & permBig) === permBig;
58
+ }
59
+ };
60
+
61
+ export {
62
+ Role
63
+ };