@fluxerjs/core 1.0.9 → 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.
- package/dist/{Channel-ICWNKXBR.mjs → Channel-WJZZSNML.mjs} +3 -1
- package/dist/{ClientUser-WWXUMO5O.mjs → ClientUser-DJO2FS7P.mjs} +1 -1
- package/dist/Guild-2P77HBQM.mjs +11 -0
- package/dist/{GuildBan-M4PA3HAA.mjs → GuildBan-7CXLTPKY.mjs} +1 -1
- package/dist/GuildMember-43B5E5CH.mjs +9 -0
- package/dist/Message-OFIVTTAZ.mjs +9 -0
- package/dist/{MessageReaction-XRPYZDSC.mjs → MessageReaction-V4UZ7OXE.mjs} +1 -1
- package/dist/{Role-SVLWIAMN.mjs → Role-5MWSGL66.mjs} +1 -1
- package/dist/Webhook-RWDDYW2Q.mjs +10 -0
- package/dist/chunk-4XJIM6SC.mjs +315 -0
- package/dist/chunk-AH7KYH2Z.mjs +50 -0
- package/dist/{chunk-HBF5QEDH.mjs → chunk-CEABHTAF.mjs} +1 -0
- package/dist/{chunk-53Y37KRG.mjs → chunk-CJVQNARM.mjs} +44 -10
- package/dist/chunk-DQ4TNBPG.mjs +63 -0
- package/dist/chunk-DUQAD7F6.mjs +173 -0
- package/dist/{chunk-GCIJYVRC.mjs → chunk-JHNKZIHY.mjs} +54 -3
- package/dist/{chunk-FJS5FBXO.mjs → chunk-LU2SNC5G.mjs} +172 -13
- package/dist/chunk-PM2IUGNR.mjs +29 -0
- package/dist/{chunk-RCP27MRC.mjs → chunk-UXIF75BV.mjs} +3 -0
- package/dist/{chunk-DSPSRPHF.mjs → chunk-V7LPVPGH.mjs} +123 -18
- package/dist/chunk-X6K3ZD62.mjs +53 -0
- package/dist/index.d.mts +603 -113
- package/dist/index.d.ts +603 -113
- package/dist/index.js +1278 -410
- package/dist/index.mjs +183 -124
- package/package.json +7 -7
- package/dist/Guild-TM6YGJWB.mjs +0 -10
- package/dist/GuildMember-RZWZ3OCG.mjs +0 -7
- package/dist/Message-6IYEYSV6.mjs +0 -7
- package/dist/Webhook-32VJD4AL.mjs +0 -7
- package/dist/chunk-GFUJVQ7L.mjs +0 -64
- package/dist/chunk-SQVCCSNN.mjs +0 -41
- package/dist/chunk-X77DFNE3.mjs +0 -136
|
@@ -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);
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSendBody
|
|
3
|
+
} from "./chunk-PM2IUGNR.mjs";
|
|
4
|
+
import {
|
|
5
|
+
cdnAvatarURL
|
|
6
|
+
} from "./chunk-X6K3ZD62.mjs";
|
|
1
7
|
import {
|
|
2
8
|
Base
|
|
3
9
|
} from "./chunk-XNS4O6QJ.mjs";
|
|
@@ -13,6 +19,8 @@ var Webhook = class _Webhook extends Base {
|
|
|
13
19
|
avatar;
|
|
14
20
|
/** Present only when webhook was created via createWebhook(); not returned when fetching. */
|
|
15
21
|
token;
|
|
22
|
+
/** User who created the webhook. */
|
|
23
|
+
user;
|
|
16
24
|
/** @param data - API webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token) */
|
|
17
25
|
constructor(client, data) {
|
|
18
26
|
super();
|
|
@@ -23,6 +31,14 @@ var Webhook = class _Webhook extends Base {
|
|
|
23
31
|
this.name = data.name ?? "Unknown";
|
|
24
32
|
this.avatar = data.avatar ?? null;
|
|
25
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);
|
|
26
42
|
}
|
|
27
43
|
/** Delete this webhook. Requires bot token with Manage Webhooks permission. */
|
|
28
44
|
async delete() {
|
|
@@ -41,10 +57,10 @@ var Webhook = class _Webhook extends Base {
|
|
|
41
57
|
body.channel_id = options.channel_id;
|
|
42
58
|
}
|
|
43
59
|
if (this.token) {
|
|
44
|
-
const data2 = await this.client.rest.patch(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
60
|
+
const data2 = await this.client.rest.patch(Routes.webhookExecute(this.id, this.token), {
|
|
61
|
+
body,
|
|
62
|
+
auth: false
|
|
63
|
+
});
|
|
48
64
|
const w2 = data2;
|
|
49
65
|
this.name = w2.name ?? this.name;
|
|
50
66
|
this.avatar = w2.avatar ?? null;
|
|
@@ -62,19 +78,37 @@ var Webhook = class _Webhook extends Base {
|
|
|
62
78
|
}
|
|
63
79
|
/**
|
|
64
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)
|
|
65
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);
|
|
66
89
|
*/
|
|
67
|
-
async send(options) {
|
|
90
|
+
async send(options, wait) {
|
|
68
91
|
if (!this.token) {
|
|
69
92
|
throw new Error(
|
|
70
93
|
"Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send."
|
|
71
94
|
);
|
|
72
95
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
78
112
|
}
|
|
79
113
|
/**
|
|
80
114
|
* Fetch a webhook by ID using bot auth.
|
|
@@ -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
|
+
};
|