@fluxerjs/core 1.0.5 → 1.0.7
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-BEZOW4VC.mjs +17 -0
- package/dist/Channel-DPLLHL7Y.mjs +19 -0
- package/dist/Channel-IKL3SJXN.mjs +17 -0
- package/dist/Channel-KOTARBSF.mjs +17 -0
- package/dist/Channel-ON7O3D3M.mjs +17 -0
- package/dist/Channel-OSOB6ELO.mjs +19 -0
- package/dist/Channel-YVGPVOVB.mjs +17 -0
- package/dist/ClientUser-6HBAPU6H.mjs +8 -0
- package/dist/ClientUser-ALGC4FNY.mjs +8 -0
- package/dist/ClientUser-LLL6WX35.mjs +8 -0
- package/dist/ClientUser-N7ZXYAQ3.mjs +8 -0
- package/dist/Guild-5UBZNIGD.mjs +9 -0
- package/dist/Guild-GIXJJBFM.mjs +9 -0
- package/dist/Guild-S436SLOP.mjs +9 -0
- package/dist/Guild-WAFXK2EX.mjs +9 -0
- package/dist/Guild-XPOMHZZG.mjs +9 -0
- package/dist/GuildMember-BJJNCL6W.mjs +8 -0
- package/dist/GuildMember-FX2JAWES.mjs +8 -0
- package/dist/GuildMember-K5FLBNHV.mjs +8 -0
- package/dist/GuildMember-UBNHZBCO.mjs +8 -0
- package/dist/GuildMember-UU26WJGN.mjs +8 -0
- package/dist/Message-33APPS76.mjs +9 -0
- package/dist/Message-6RSAGIRP.mjs +8 -0
- package/dist/Message-OXTQHFCF.mjs +8 -0
- package/dist/Message-QXPHQOVC.mjs +8 -0
- package/dist/Message-R7GZYIQQ.mjs +8 -0
- package/dist/Message-W624MHJF.mjs +8 -0
- package/dist/Message-ZCS7IGJX.mjs +8 -0
- package/dist/Webhook-AG6QFM2I.mjs +7 -0
- package/dist/Webhook-TGAZZRQQ.mjs +7 -0
- package/dist/chunk-2FIZRRSO.mjs +88 -0
- package/dist/chunk-3CNUPFDI.mjs +59 -0
- package/dist/chunk-5HQRX3KJ.mjs +70 -0
- package/dist/chunk-62S4AB2S.mjs +54 -0
- package/dist/chunk-7SIS5CUA.mjs +14 -0
- package/dist/chunk-BGJSL6JI.mjs +14 -0
- package/dist/chunk-BYTAODAO.mjs +70 -0
- package/dist/chunk-CQ5ZVTLX.mjs +71 -0
- package/dist/chunk-DJBCSVZX.mjs +102 -0
- package/dist/chunk-DLROMCIJ.mjs +50 -0
- package/dist/chunk-DPZHAYCK.mjs +71 -0
- package/dist/chunk-E75ZVY3I.mjs +14 -0
- package/dist/chunk-FK5X6HFL.mjs +111 -0
- package/dist/chunk-FNFID6QB.mjs +45 -0
- package/dist/chunk-G4L7WAJS.mjs +64 -0
- package/dist/chunk-IPHFDI2L.mjs +68 -0
- package/dist/chunk-J3EIGOXQ.mjs +72 -0
- package/dist/chunk-JJHZBWZM.mjs +118 -0
- package/dist/chunk-LVMFPATK.mjs +54 -0
- package/dist/chunk-NISGA2YZ.mjs +55 -0
- package/dist/chunk-NOLYW3V4.mjs +140 -0
- package/dist/chunk-OHIHIQAS.mjs +102 -0
- package/dist/chunk-PO5JZQVN.mjs +111 -0
- package/dist/chunk-PYYXC7US.mjs +76 -0
- package/dist/chunk-QXJNV5EJ.mjs +110 -0
- package/dist/chunk-RXHJYGSJ.mjs +53 -0
- package/dist/chunk-T2NSVWBH.mjs +77 -0
- package/dist/chunk-TMDZALIN.mjs +110 -0
- package/dist/chunk-WYSHH4LR.mjs +141 -0
- package/dist/chunk-WZVY7DA6.mjs +44 -0
- package/dist/chunk-XTDZQD4A.mjs +110 -0
- package/dist/chunk-YKP7JHV2.mjs +102 -0
- package/dist/chunk-YSKZR66G.mjs +102 -0
- package/dist/chunk-ZMIMAMO2.mjs +14 -0
- package/dist/index.d.mts +208 -51
- package/dist/index.d.ts +208 -51
- package/dist/index.js +361 -177
- package/dist/index.mjs +38 -25
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -39,113 +39,17 @@ var init_Constants = __esm({
|
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
// src/structures/User.ts
|
|
43
|
-
var User;
|
|
44
|
-
var init_User = __esm({
|
|
45
|
-
"src/structures/User.ts"() {
|
|
46
|
-
"use strict";
|
|
47
|
-
init_Base();
|
|
48
|
-
init_Constants();
|
|
49
|
-
User = class extends Base {
|
|
50
|
-
client;
|
|
51
|
-
id;
|
|
52
|
-
username;
|
|
53
|
-
discriminator;
|
|
54
|
-
globalName;
|
|
55
|
-
avatar;
|
|
56
|
-
bot;
|
|
57
|
-
constructor(client, data) {
|
|
58
|
-
super();
|
|
59
|
-
this.client = client;
|
|
60
|
-
this.id = data.id;
|
|
61
|
-
this.username = data.username;
|
|
62
|
-
this.discriminator = data.discriminator;
|
|
63
|
-
this.globalName = data.global_name ?? null;
|
|
64
|
-
this.avatar = data.avatar ?? null;
|
|
65
|
-
this.bot = !!data.bot;
|
|
66
|
-
}
|
|
67
|
-
avatarURL(options) {
|
|
68
|
-
if (!this.avatar) return null;
|
|
69
|
-
const ext = options?.extension ?? "png";
|
|
70
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
71
|
-
return `${CDN_URL}/avatars/${this.id}/${this.avatar}.${ext}${size}`;
|
|
72
|
-
}
|
|
73
|
-
displayAvatarURL(options) {
|
|
74
|
-
return this.avatarURL(options) ?? `${CDN_URL}/avatars/0/0.png`;
|
|
75
|
-
}
|
|
76
|
-
toString() {
|
|
77
|
-
return `<@${this.id}>`;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// src/structures/Message.ts
|
|
84
|
-
var Message_exports = {};
|
|
85
|
-
__export(Message_exports, {
|
|
86
|
-
Message: () => Message
|
|
87
|
-
});
|
|
88
|
-
var import_collection, import_types, Message;
|
|
89
|
-
var init_Message = __esm({
|
|
90
|
-
"src/structures/Message.ts"() {
|
|
91
|
-
"use strict";
|
|
92
|
-
init_Base();
|
|
93
|
-
import_collection = require("@fluxerjs/collection");
|
|
94
|
-
import_types = require("@fluxerjs/types");
|
|
95
|
-
init_User();
|
|
96
|
-
Message = class _Message extends Base {
|
|
97
|
-
client;
|
|
98
|
-
id;
|
|
99
|
-
channelId;
|
|
100
|
-
guildId;
|
|
101
|
-
author;
|
|
102
|
-
content;
|
|
103
|
-
createdAt;
|
|
104
|
-
editedAt;
|
|
105
|
-
pinned;
|
|
106
|
-
attachments;
|
|
107
|
-
channel;
|
|
108
|
-
constructor(client, data) {
|
|
109
|
-
super();
|
|
110
|
-
this.client = client;
|
|
111
|
-
this.id = data.id;
|
|
112
|
-
this.channelId = data.channel_id;
|
|
113
|
-
this.guildId = data.guild_id ?? null;
|
|
114
|
-
this.author = new User(client, data.author);
|
|
115
|
-
this.content = data.content;
|
|
116
|
-
this.createdAt = new Date(data.timestamp);
|
|
117
|
-
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
118
|
-
this.pinned = data.pinned;
|
|
119
|
-
this.attachments = new import_collection.Collection();
|
|
120
|
-
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
121
|
-
}
|
|
122
|
-
async reply(options) {
|
|
123
|
-
const body = typeof options === "string" ? { content: options, message_reference: { channel_id: this.channelId, message_id: this.id, guild_id: this.guildId ?? void 0 } } : { ...options, message_reference: { channel_id: this.channelId, message_id: this.id, guild_id: this.guildId ?? void 0 } };
|
|
124
|
-
const data = await this.client.rest.post(import_types.Routes.channelMessages(this.channelId), { body });
|
|
125
|
-
return new _Message(this.client, data);
|
|
126
|
-
}
|
|
127
|
-
async edit(options) {
|
|
128
|
-
const data = await this.client.rest.patch(import_types.Routes.channelMessage(this.channelId, this.id), { body: options });
|
|
129
|
-
return new _Message(this.client, data);
|
|
130
|
-
}
|
|
131
|
-
async delete() {
|
|
132
|
-
await this.client.rest.delete(import_types.Routes.channelMessage(this.channelId, this.id));
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
42
|
// src/structures/Webhook.ts
|
|
139
43
|
var Webhook_exports = {};
|
|
140
44
|
__export(Webhook_exports, {
|
|
141
45
|
Webhook: () => Webhook
|
|
142
46
|
});
|
|
143
|
-
var
|
|
47
|
+
var import_types, Webhook;
|
|
144
48
|
var init_Webhook = __esm({
|
|
145
49
|
"src/structures/Webhook.ts"() {
|
|
146
50
|
"use strict";
|
|
147
51
|
init_Base();
|
|
148
|
-
|
|
52
|
+
import_types = require("@fluxerjs/types");
|
|
149
53
|
Webhook = class _Webhook extends Base {
|
|
150
54
|
client;
|
|
151
55
|
id;
|
|
@@ -155,6 +59,7 @@ var init_Webhook = __esm({
|
|
|
155
59
|
avatar;
|
|
156
60
|
/** Present only when webhook was created via createWebhook(); not returned when fetching. */
|
|
157
61
|
token;
|
|
62
|
+
/** @param data - API webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token) */
|
|
158
63
|
constructor(client, data) {
|
|
159
64
|
super();
|
|
160
65
|
this.client = client;
|
|
@@ -167,7 +72,7 @@ var init_Webhook = __esm({
|
|
|
167
72
|
}
|
|
168
73
|
/** Delete this webhook. Requires bot token with Manage Webhooks permission. */
|
|
169
74
|
async delete() {
|
|
170
|
-
await this.client.rest.delete(
|
|
75
|
+
await this.client.rest.delete(import_types.Routes.webhook(this.id), { auth: true });
|
|
171
76
|
}
|
|
172
77
|
/**
|
|
173
78
|
* Send a message via this webhook. Requires the webhook token (only present when created, not when fetched).
|
|
@@ -178,21 +83,27 @@ var init_Webhook = __esm({
|
|
|
178
83
|
throw new Error("Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send.");
|
|
179
84
|
}
|
|
180
85
|
const body = typeof options === "string" ? { content: options } : options;
|
|
181
|
-
await this.client.rest.post(
|
|
86
|
+
await this.client.rest.post(import_types.Routes.webhookExecute(this.id, this.token), {
|
|
182
87
|
body,
|
|
183
88
|
auth: false
|
|
184
89
|
});
|
|
185
90
|
}
|
|
186
91
|
/**
|
|
187
|
-
* Fetch a webhook by ID using bot auth.
|
|
92
|
+
* Fetch a webhook by ID using bot auth.
|
|
93
|
+
* @param client - The client instance
|
|
94
|
+
* @param webhookId - The webhook ID
|
|
95
|
+
* @returns Webhook without token (cannot send)
|
|
188
96
|
*/
|
|
189
97
|
static async fetch(client, webhookId) {
|
|
190
|
-
const data = await client.rest.get(
|
|
98
|
+
const data = await client.rest.get(import_types.Routes.webhook(webhookId));
|
|
191
99
|
return new _Webhook(client, data);
|
|
192
100
|
}
|
|
193
101
|
/**
|
|
194
102
|
* Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).
|
|
195
|
-
*
|
|
103
|
+
* @param client - The client instance
|
|
104
|
+
* @param webhookId - The webhook ID
|
|
105
|
+
* @param token - The webhook token (from createWebhook or stored)
|
|
106
|
+
* @param options - Optional channelId, guildId, name for display
|
|
196
107
|
*/
|
|
197
108
|
static fromToken(client, webhookId, token, options) {
|
|
198
109
|
return new _Webhook(client, {
|
|
@@ -209,90 +120,49 @@ var init_Webhook = __esm({
|
|
|
209
120
|
}
|
|
210
121
|
});
|
|
211
122
|
|
|
212
|
-
// src/structures/Guild.ts
|
|
213
|
-
var Guild_exports = {};
|
|
214
|
-
__export(Guild_exports, {
|
|
215
|
-
Guild: () => Guild
|
|
216
|
-
});
|
|
217
|
-
var import_collection2, import_types3, Guild;
|
|
218
|
-
var init_Guild = __esm({
|
|
219
|
-
"src/structures/Guild.ts"() {
|
|
220
|
-
"use strict";
|
|
221
|
-
init_Base();
|
|
222
|
-
import_collection2 = require("@fluxerjs/collection");
|
|
223
|
-
init_Constants();
|
|
224
|
-
import_types3 = require("@fluxerjs/types");
|
|
225
|
-
Guild = class extends Base {
|
|
226
|
-
client;
|
|
227
|
-
id;
|
|
228
|
-
name;
|
|
229
|
-
icon;
|
|
230
|
-
banner;
|
|
231
|
-
ownerId;
|
|
232
|
-
members = new import_collection2.Collection();
|
|
233
|
-
channels = new import_collection2.Collection();
|
|
234
|
-
constructor(client, data) {
|
|
235
|
-
super();
|
|
236
|
-
this.client = client;
|
|
237
|
-
this.id = data.id;
|
|
238
|
-
this.name = data.name;
|
|
239
|
-
this.icon = data.icon ?? null;
|
|
240
|
-
this.banner = data.banner ?? null;
|
|
241
|
-
this.ownerId = data.owner_id;
|
|
242
|
-
}
|
|
243
|
-
iconURL(options) {
|
|
244
|
-
if (!this.icon) return null;
|
|
245
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
246
|
-
return `${CDN_URL}/icons/${this.id}/${this.icon}.png${size}`;
|
|
247
|
-
}
|
|
248
|
-
bannerURL(options) {
|
|
249
|
-
if (!this.banner) return null;
|
|
250
|
-
const size = options?.size ? `?size=${options.size}` : "";
|
|
251
|
-
return `${CDN_URL}/banners/${this.id}/${this.banner}.png${size}`;
|
|
252
|
-
}
|
|
253
|
-
/** Fetch all webhooks in this guild. Returned webhooks do not include the token (cannot send). */
|
|
254
|
-
async fetchWebhooks() {
|
|
255
|
-
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
256
|
-
const data = await this.client.rest.get(import_types3.Routes.guildWebhooks(this.id));
|
|
257
|
-
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
258
|
-
return list.map((w) => new Webhook2(this.client, w));
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
123
|
// src/structures/Channel.ts
|
|
265
124
|
var Channel_exports = {};
|
|
266
125
|
__export(Channel_exports, {
|
|
267
126
|
CategoryChannel: () => CategoryChannel,
|
|
268
127
|
Channel: () => Channel,
|
|
128
|
+
DMChannel: () => DMChannel,
|
|
269
129
|
GuildChannel: () => GuildChannel,
|
|
270
130
|
LinkChannel: () => LinkChannel,
|
|
271
131
|
TextChannel: () => TextChannel,
|
|
272
132
|
VoiceChannel: () => VoiceChannel
|
|
273
133
|
});
|
|
274
|
-
var
|
|
134
|
+
var import_types2, Channel, GuildChannel, TextChannel, CategoryChannel, VoiceChannel, LinkChannel, DMChannel;
|
|
275
135
|
var init_Channel = __esm({
|
|
276
136
|
"src/structures/Channel.ts"() {
|
|
277
137
|
"use strict";
|
|
278
138
|
init_Base();
|
|
279
|
-
|
|
139
|
+
import_types2 = require("@fluxerjs/types");
|
|
280
140
|
Channel = class extends Base {
|
|
141
|
+
/** Create a DM channel from API data (type DM or GroupDM). */
|
|
142
|
+
static createDM(client, data) {
|
|
143
|
+
return new DMChannel(client, data);
|
|
144
|
+
}
|
|
281
145
|
client;
|
|
282
146
|
id;
|
|
283
147
|
type;
|
|
148
|
+
/** @param data - API channel from GET /channels/{id} or GET /guilds/{id}/channels */
|
|
284
149
|
constructor(client, data) {
|
|
285
150
|
super();
|
|
286
151
|
this.client = client;
|
|
287
152
|
this.id = data.id;
|
|
288
153
|
this.type = data.type;
|
|
289
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Create the appropriate channel subclass from API data.
|
|
157
|
+
* @param client - The client instance
|
|
158
|
+
* @param data - Channel data from the API
|
|
159
|
+
*/
|
|
290
160
|
static from(client, data) {
|
|
291
161
|
const type = data.type ?? 0;
|
|
292
|
-
if (type ===
|
|
293
|
-
if (type ===
|
|
294
|
-
if (type ===
|
|
295
|
-
if (type ===
|
|
162
|
+
if (type === import_types2.ChannelType.GuildText) return new TextChannel(client, data);
|
|
163
|
+
if (type === import_types2.ChannelType.GuildCategory) return new CategoryChannel(client, data);
|
|
164
|
+
if (type === import_types2.ChannelType.GuildVoice) return new VoiceChannel(client, data);
|
|
165
|
+
if (type === import_types2.ChannelType.GuildLink || type === import_types2.ChannelType.GuildLinkExtended) return new LinkChannel(client, data);
|
|
296
166
|
return new GuildChannel(client, data);
|
|
297
167
|
}
|
|
298
168
|
};
|
|
@@ -308,19 +178,26 @@ var init_Channel = __esm({
|
|
|
308
178
|
this.position = data.position;
|
|
309
179
|
this.parentId = data.parent_id ?? null;
|
|
310
180
|
}
|
|
311
|
-
/**
|
|
181
|
+
/**
|
|
182
|
+
* Create a webhook in this channel.
|
|
183
|
+
* @param options - Webhook name and optional avatar URL
|
|
184
|
+
* @returns The webhook with token (required for send()). Requires Manage Webhooks permission.
|
|
185
|
+
*/
|
|
312
186
|
async createWebhook(options) {
|
|
313
187
|
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
314
|
-
const data = await this.client.rest.post(
|
|
188
|
+
const data = await this.client.rest.post(import_types2.Routes.channelWebhooks(this.id), {
|
|
315
189
|
body: options,
|
|
316
190
|
auth: true
|
|
317
191
|
});
|
|
318
192
|
return new Webhook2(this.client, data);
|
|
319
193
|
}
|
|
320
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* Fetch all webhooks in this channel.
|
|
196
|
+
* @returns Webhooks (includes token when listing from channel; can send via send())
|
|
197
|
+
*/
|
|
321
198
|
async fetchWebhooks() {
|
|
322
199
|
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
323
|
-
const data = await this.client.rest.get(
|
|
200
|
+
const data = await this.client.rest.get(import_types2.Routes.channelWebhooks(this.id));
|
|
324
201
|
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
325
202
|
return list.map((w) => new Webhook2(this.client, w));
|
|
326
203
|
}
|
|
@@ -337,10 +214,14 @@ var init_Channel = __esm({
|
|
|
337
214
|
this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
|
|
338
215
|
this.lastMessageId = data.last_message_id ?? null;
|
|
339
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Send a message to this channel.
|
|
219
|
+
* @param options - Text content or object with `content` and/or `embeds`
|
|
220
|
+
*/
|
|
340
221
|
async send(options) {
|
|
341
222
|
const body = typeof options === "string" ? { content: options } : options;
|
|
342
223
|
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
343
|
-
const data = await this.client.rest.post(
|
|
224
|
+
const data = await this.client.rest.post(import_types2.Routes.channelMessages(this.id), { body });
|
|
344
225
|
return new Message2(this.client, data);
|
|
345
226
|
}
|
|
346
227
|
};
|
|
@@ -364,6 +245,205 @@ var init_Channel = __esm({
|
|
|
364
245
|
this.url = data.url ?? null;
|
|
365
246
|
}
|
|
366
247
|
};
|
|
248
|
+
DMChannel = class extends Channel {
|
|
249
|
+
lastMessageId;
|
|
250
|
+
constructor(client, data) {
|
|
251
|
+
super(client, data);
|
|
252
|
+
this.lastMessageId = data.last_message_id ?? null;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Send a message to this DM channel.
|
|
256
|
+
* @param options - Text content or object with `content` and/or `embeds`
|
|
257
|
+
*/
|
|
258
|
+
async send(options) {
|
|
259
|
+
const body = typeof options === "string" ? { content: options } : options;
|
|
260
|
+
const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
|
|
261
|
+
const data = await this.client.rest.post(import_types2.Routes.channelMessages(this.id), { body });
|
|
262
|
+
return new Message2(this.client, data);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// src/structures/User.ts
|
|
269
|
+
var import_types3, User;
|
|
270
|
+
var init_User = __esm({
|
|
271
|
+
"src/structures/User.ts"() {
|
|
272
|
+
"use strict";
|
|
273
|
+
init_Base();
|
|
274
|
+
import_types3 = require("@fluxerjs/types");
|
|
275
|
+
init_Constants();
|
|
276
|
+
User = class extends Base {
|
|
277
|
+
client;
|
|
278
|
+
id;
|
|
279
|
+
username;
|
|
280
|
+
discriminator;
|
|
281
|
+
globalName;
|
|
282
|
+
avatar;
|
|
283
|
+
bot;
|
|
284
|
+
/** @param data - API user from message author, GET /users/{id}, or GET /users/@me */
|
|
285
|
+
constructor(client, data) {
|
|
286
|
+
super();
|
|
287
|
+
this.client = client;
|
|
288
|
+
this.id = data.id;
|
|
289
|
+
this.username = data.username;
|
|
290
|
+
this.discriminator = data.discriminator;
|
|
291
|
+
this.globalName = data.global_name ?? null;
|
|
292
|
+
this.avatar = data.avatar ?? null;
|
|
293
|
+
this.bot = !!data.bot;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get the URL for this user's avatar.
|
|
297
|
+
* @param options - Optional `size` and `extension` (default: `png`)
|
|
298
|
+
*/
|
|
299
|
+
avatarURL(options) {
|
|
300
|
+
if (!this.avatar) return null;
|
|
301
|
+
const ext = options?.extension ?? "png";
|
|
302
|
+
const size = options?.size ? `?size=${options.size}` : "";
|
|
303
|
+
return `${CDN_URL}/avatars/${this.id}/${this.avatar}.${ext}${size}`;
|
|
304
|
+
}
|
|
305
|
+
/** Get the avatar URL, or the default avatar if none set. */
|
|
306
|
+
displayAvatarURL(options) {
|
|
307
|
+
return this.avatarURL(options) ?? `${CDN_URL}/avatars/0/0.png`;
|
|
308
|
+
}
|
|
309
|
+
/** Returns a mention string (e.g. `<@123456>`). */
|
|
310
|
+
toString() {
|
|
311
|
+
return `<@${this.id}>`;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Create or get a DM channel with this user.
|
|
315
|
+
* Returns the DM channel; use {@link DMChannel.send} to send messages.
|
|
316
|
+
*/
|
|
317
|
+
async createDM() {
|
|
318
|
+
const { DMChannel: DMChannelClass } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
|
|
319
|
+
const data = await this.client.rest.post(import_types3.Routes.userMeChannels(), {
|
|
320
|
+
body: { recipient_id: this.id },
|
|
321
|
+
auth: true
|
|
322
|
+
});
|
|
323
|
+
return new DMChannelClass(this.client, data);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Send a DM to this user.
|
|
327
|
+
* Convenience method that creates the DM channel and sends the message.
|
|
328
|
+
*/
|
|
329
|
+
async send(options) {
|
|
330
|
+
const dm = await this.createDM();
|
|
331
|
+
return dm.send(options);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// src/structures/Message.ts
|
|
338
|
+
var Message_exports = {};
|
|
339
|
+
__export(Message_exports, {
|
|
340
|
+
Message: () => Message
|
|
341
|
+
});
|
|
342
|
+
var import_collection, import_types4, import_builders, Message;
|
|
343
|
+
var init_Message = __esm({
|
|
344
|
+
"src/structures/Message.ts"() {
|
|
345
|
+
"use strict";
|
|
346
|
+
init_Base();
|
|
347
|
+
import_collection = require("@fluxerjs/collection");
|
|
348
|
+
import_types4 = require("@fluxerjs/types");
|
|
349
|
+
import_builders = require("@fluxerjs/builders");
|
|
350
|
+
init_User();
|
|
351
|
+
Message = class _Message extends Base {
|
|
352
|
+
client;
|
|
353
|
+
id;
|
|
354
|
+
channelId;
|
|
355
|
+
guildId;
|
|
356
|
+
author;
|
|
357
|
+
content;
|
|
358
|
+
createdAt;
|
|
359
|
+
editedAt;
|
|
360
|
+
pinned;
|
|
361
|
+
attachments;
|
|
362
|
+
channel;
|
|
363
|
+
/** @param data - API message from POST/PATCH /channels/{id}/messages or gateway MESSAGE_CREATE */
|
|
364
|
+
constructor(client, data) {
|
|
365
|
+
super();
|
|
366
|
+
this.client = client;
|
|
367
|
+
this.id = data.id;
|
|
368
|
+
this.channelId = data.channel_id;
|
|
369
|
+
this.guildId = data.guild_id ?? null;
|
|
370
|
+
this.author = new User(client, data.author);
|
|
371
|
+
this.content = data.content;
|
|
372
|
+
this.createdAt = new Date(data.timestamp);
|
|
373
|
+
this.editedAt = data.edited_timestamp ? new Date(data.edited_timestamp) : null;
|
|
374
|
+
this.pinned = data.pinned;
|
|
375
|
+
this.attachments = new import_collection.Collection();
|
|
376
|
+
for (const a of data.attachments ?? []) this.attachments.set(a.id, a);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Reply to this message.
|
|
380
|
+
* @param options - Text content or object with content and/or embeds
|
|
381
|
+
*/
|
|
382
|
+
async reply(options) {
|
|
383
|
+
const body = typeof options === "string" ? { content: options, message_reference: { channel_id: this.channelId, message_id: this.id, guild_id: this.guildId ?? void 0 } } : { ...options, message_reference: { channel_id: this.channelId, message_id: this.id, guild_id: this.guildId ?? void 0 } };
|
|
384
|
+
const data = await this.client.rest.post(import_types4.Routes.channelMessages(this.channelId), { body });
|
|
385
|
+
return new _Message(this.client, data);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Edit this message. Only the author (or admins) can edit.
|
|
389
|
+
* @param options - New content and/or embeds
|
|
390
|
+
*/
|
|
391
|
+
async edit(options) {
|
|
392
|
+
const body = {};
|
|
393
|
+
if (options.content !== void 0) body.content = options.content;
|
|
394
|
+
if (options.embeds?.length) {
|
|
395
|
+
body.embeds = options.embeds.map((e) => e instanceof import_builders.EmbedBuilder ? e.toJSON() : e);
|
|
396
|
+
}
|
|
397
|
+
const data = await this.client.rest.patch(import_types4.Routes.channelMessage(this.channelId, this.id), { body });
|
|
398
|
+
return new _Message(this.client, data);
|
|
399
|
+
}
|
|
400
|
+
/** Delete this message. */
|
|
401
|
+
async delete() {
|
|
402
|
+
await this.client.rest.delete(import_types4.Routes.channelMessage(this.channelId, this.id));
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Format emoji for reaction API: unicode string or "name:id" for custom.
|
|
406
|
+
* @param emoji - Unicode emoji (e.g. "👍") or custom { name, id } or "name:id" string
|
|
407
|
+
*/
|
|
408
|
+
static formatEmoji(emoji) {
|
|
409
|
+
if (typeof emoji === "string") return emoji;
|
|
410
|
+
return `${emoji.name}:${emoji.id}`;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Add a reaction to this message (as the bot).
|
|
414
|
+
* @param emoji - Unicode emoji (e.g. `👍`) or custom emoji `{ name, id }`
|
|
415
|
+
*/
|
|
416
|
+
async react(emoji) {
|
|
417
|
+
const emojiStr = _Message.formatEmoji(emoji);
|
|
418
|
+
const route = `${import_types4.Routes.channelMessageReaction(this.channelId, this.id, emojiStr)}/@me`;
|
|
419
|
+
await this.client.rest.put(route);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Remove the bot's reaction, or a specific user's reaction if userId is provided.
|
|
423
|
+
* @param emoji - Unicode emoji or custom `{ name, id }`
|
|
424
|
+
* @param userId - If provided, removes that user's reaction (requires moderator permissions)
|
|
425
|
+
*/
|
|
426
|
+
async removeReaction(emoji, userId) {
|
|
427
|
+
const emojiStr = _Message.formatEmoji(emoji);
|
|
428
|
+
const route = `${import_types4.Routes.channelMessageReaction(this.channelId, this.id, emojiStr)}/${userId ?? "@me"}`;
|
|
429
|
+
await this.client.rest.delete(route);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Remove all reactions from this message.
|
|
433
|
+
* Requires moderator permissions.
|
|
434
|
+
*/
|
|
435
|
+
async removeAllReactions() {
|
|
436
|
+
await this.client.rest.delete(import_types4.Routes.channelMessageReactions(this.channelId, this.id));
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Remove all reactions of a specific emoji from this message.
|
|
440
|
+
* @param emoji - Unicode emoji or custom `{ name, id }`. Requires moderator permissions.
|
|
441
|
+
*/
|
|
442
|
+
async removeReactionEmoji(emoji) {
|
|
443
|
+
const emojiStr = _Message.formatEmoji(emoji);
|
|
444
|
+
await this.client.rest.delete(import_types4.Routes.channelMessageReaction(this.channelId, this.id, emojiStr));
|
|
445
|
+
}
|
|
446
|
+
};
|
|
367
447
|
}
|
|
368
448
|
});
|
|
369
449
|
|
|
@@ -372,12 +452,13 @@ var GuildMember_exports = {};
|
|
|
372
452
|
__export(GuildMember_exports, {
|
|
373
453
|
GuildMember: () => GuildMember
|
|
374
454
|
});
|
|
375
|
-
var GuildMember;
|
|
455
|
+
var import_types5, GuildMember;
|
|
376
456
|
var init_GuildMember = __esm({
|
|
377
457
|
"src/structures/GuildMember.ts"() {
|
|
378
458
|
"use strict";
|
|
379
459
|
init_Base();
|
|
380
460
|
init_User();
|
|
461
|
+
import_types5 = require("@fluxerjs/types");
|
|
381
462
|
GuildMember = class extends Base {
|
|
382
463
|
client;
|
|
383
464
|
id;
|
|
@@ -387,6 +468,7 @@ var init_GuildMember = __esm({
|
|
|
387
468
|
roles;
|
|
388
469
|
joinedAt;
|
|
389
470
|
communicationDisabledUntil;
|
|
471
|
+
/** @param data - API guild member from GET /guilds/{id}/members or GET /guilds/{id}/members/{user_id} */
|
|
390
472
|
constructor(client, data, guild) {
|
|
391
473
|
super();
|
|
392
474
|
this.client = client;
|
|
@@ -398,9 +480,97 @@ var init_GuildMember = __esm({
|
|
|
398
480
|
this.joinedAt = new Date(data.joined_at);
|
|
399
481
|
this.communicationDisabledUntil = data.communication_disabled_until ? new Date(data.communication_disabled_until) : null;
|
|
400
482
|
}
|
|
483
|
+
/** Nickname, or global name, or username. */
|
|
401
484
|
get displayName() {
|
|
402
485
|
return this.nick ?? this.user.globalName ?? this.user.username;
|
|
403
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* Add a role to this member.
|
|
489
|
+
* @param roleId - The role ID to add
|
|
490
|
+
* Requires Manage Roles permission.
|
|
491
|
+
*/
|
|
492
|
+
async addRole(roleId) {
|
|
493
|
+
await this.client.rest.put(import_types5.Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Remove a role from this member.
|
|
497
|
+
* @param roleId - The role ID to remove
|
|
498
|
+
* Requires Manage Roles permission.
|
|
499
|
+
*/
|
|
500
|
+
async removeRole(roleId) {
|
|
501
|
+
await this.client.rest.delete(import_types5.Routes.guildMemberRole(this.guild.id, this.id, roleId));
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// src/structures/Guild.ts
|
|
508
|
+
var Guild_exports = {};
|
|
509
|
+
__export(Guild_exports, {
|
|
510
|
+
Guild: () => Guild
|
|
511
|
+
});
|
|
512
|
+
var import_collection2, import_types6, Guild;
|
|
513
|
+
var init_Guild = __esm({
|
|
514
|
+
"src/structures/Guild.ts"() {
|
|
515
|
+
"use strict";
|
|
516
|
+
init_Base();
|
|
517
|
+
import_collection2 = require("@fluxerjs/collection");
|
|
518
|
+
init_GuildMember();
|
|
519
|
+
init_Constants();
|
|
520
|
+
import_types6 = require("@fluxerjs/types");
|
|
521
|
+
Guild = class extends Base {
|
|
522
|
+
client;
|
|
523
|
+
id;
|
|
524
|
+
name;
|
|
525
|
+
icon;
|
|
526
|
+
banner;
|
|
527
|
+
ownerId;
|
|
528
|
+
members = new import_collection2.Collection();
|
|
529
|
+
channels = new import_collection2.Collection();
|
|
530
|
+
/** @param data - API guild from GET /guilds/{id} or gateway GUILD_CREATE */
|
|
531
|
+
constructor(client, data) {
|
|
532
|
+
super();
|
|
533
|
+
this.client = client;
|
|
534
|
+
this.id = data.id;
|
|
535
|
+
this.name = data.name;
|
|
536
|
+
this.icon = data.icon ?? null;
|
|
537
|
+
this.banner = data.banner ?? null;
|
|
538
|
+
this.ownerId = data.owner_id;
|
|
539
|
+
}
|
|
540
|
+
/** Get the guild icon URL, or null if no icon. */
|
|
541
|
+
iconURL(options) {
|
|
542
|
+
if (!this.icon) return null;
|
|
543
|
+
const size = options?.size ? `?size=${options.size}` : "";
|
|
544
|
+
return `${CDN_URL}/icons/${this.id}/${this.icon}.png${size}`;
|
|
545
|
+
}
|
|
546
|
+
/** Get the guild banner URL, or null if no banner. */
|
|
547
|
+
bannerURL(options) {
|
|
548
|
+
if (!this.banner) return null;
|
|
549
|
+
const size = options?.size ? `?size=${options.size}` : "";
|
|
550
|
+
return `${CDN_URL}/banners/${this.id}/${this.banner}.png${size}`;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Fetch a guild member by user ID.
|
|
554
|
+
* @param userId - The user ID of the member to fetch
|
|
555
|
+
* @returns The guild member, or null if not found
|
|
556
|
+
*/
|
|
557
|
+
async fetchMember(userId) {
|
|
558
|
+
try {
|
|
559
|
+
const data = await this.client.rest.get(
|
|
560
|
+
import_types6.Routes.guildMember(this.id, userId)
|
|
561
|
+
);
|
|
562
|
+
return new GuildMember(this.client, { ...data, guild_id: this.id }, this);
|
|
563
|
+
} catch {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/** Fetch all webhooks in this guild. Returned webhooks do not include the token (cannot send). */
|
|
568
|
+
async fetchWebhooks() {
|
|
569
|
+
const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
|
|
570
|
+
const data = await this.client.rest.get(import_types6.Routes.guildWebhooks(this.id));
|
|
571
|
+
const list = Array.isArray(data) ? data : Object.values(data ?? {});
|
|
572
|
+
return list.map((w) => new Webhook2(this.client, w));
|
|
573
|
+
}
|
|
404
574
|
};
|
|
405
575
|
}
|
|
406
576
|
});
|
|
@@ -426,24 +596,25 @@ var init_ClientUser = __esm({
|
|
|
426
596
|
// src/index.ts
|
|
427
597
|
var index_exports = {};
|
|
428
598
|
__export(index_exports, {
|
|
429
|
-
AttachmentBuilder: () =>
|
|
599
|
+
AttachmentBuilder: () => import_builders2.AttachmentBuilder,
|
|
430
600
|
Base: () => Base,
|
|
431
601
|
CategoryChannel: () => CategoryChannel,
|
|
432
602
|
Channel: () => Channel,
|
|
433
603
|
Client: () => Client,
|
|
434
604
|
ClientUser: () => ClientUser,
|
|
435
|
-
|
|
605
|
+
DMChannel: () => DMChannel,
|
|
606
|
+
EmbedBuilder: () => import_builders2.EmbedBuilder,
|
|
436
607
|
ErrorCodes: () => ErrorCodes,
|
|
437
608
|
Events: () => Events,
|
|
438
609
|
FluxerError: () => FluxerError,
|
|
439
|
-
GatewayOpcodes: () =>
|
|
610
|
+
GatewayOpcodes: () => import_types8.GatewayOpcodes,
|
|
440
611
|
Guild: () => Guild,
|
|
441
612
|
GuildChannel: () => GuildChannel,
|
|
442
613
|
GuildMember: () => GuildMember,
|
|
443
614
|
LinkChannel: () => LinkChannel,
|
|
444
615
|
Message: () => Message,
|
|
445
|
-
MessagePayload: () =>
|
|
446
|
-
Routes: () =>
|
|
616
|
+
MessagePayload: () => import_builders2.MessagePayload,
|
|
617
|
+
Routes: () => import_types8.Routes,
|
|
447
618
|
TextChannel: () => TextChannel,
|
|
448
619
|
User: () => User,
|
|
449
620
|
VoiceChannel: () => VoiceChannel,
|
|
@@ -455,7 +626,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
455
626
|
var import_events = require("events");
|
|
456
627
|
var import_rest = require("@fluxerjs/rest");
|
|
457
628
|
var import_ws = require("@fluxerjs/ws");
|
|
458
|
-
var
|
|
629
|
+
var import_types7 = require("@fluxerjs/types");
|
|
459
630
|
var import_collection3 = require("@fluxerjs/collection");
|
|
460
631
|
|
|
461
632
|
// src/util/Events.ts
|
|
@@ -487,6 +658,7 @@ var Events = {
|
|
|
487
658
|
|
|
488
659
|
// src/client/Client.ts
|
|
489
660
|
var Client = class extends import_events.EventEmitter {
|
|
661
|
+
/** @param options - Token, REST config, WebSocket, presence, etc. */
|
|
490
662
|
constructor(options = {}) {
|
|
491
663
|
super();
|
|
492
664
|
this.options = options;
|
|
@@ -503,11 +675,16 @@ var Client = class extends import_events.EventEmitter {
|
|
|
503
675
|
user = null;
|
|
504
676
|
readyAt = null;
|
|
505
677
|
_ws = null;
|
|
678
|
+
/** WebSocket manager. Throws if not logged in. */
|
|
506
679
|
get ws() {
|
|
507
680
|
if (!this._ws) throw new Error("Client is not logged in");
|
|
508
681
|
return this._ws;
|
|
509
682
|
}
|
|
510
|
-
/**
|
|
683
|
+
/**
|
|
684
|
+
* Send a payload to the gateway (e.g. Voice State Update).
|
|
685
|
+
* @param shardId - Shard ID (use 0 for single-shard)
|
|
686
|
+
* @param payload - Gateway payload to send
|
|
687
|
+
*/
|
|
511
688
|
sendToGateway(shardId, payload) {
|
|
512
689
|
this.ws.send(shardId, payload);
|
|
513
690
|
}
|
|
@@ -658,6 +835,10 @@ var Client = class extends import_events.EventEmitter {
|
|
|
658
835
|
this.emit(Events.Error, err instanceof Error ? err : new Error(String(err)));
|
|
659
836
|
}
|
|
660
837
|
}
|
|
838
|
+
/**
|
|
839
|
+
* Connect to the Fluxer gateway and authenticate.
|
|
840
|
+
* @param token - Bot token (e.g. from FLUXER_BOT_TOKEN)
|
|
841
|
+
*/
|
|
661
842
|
async login(token) {
|
|
662
843
|
this.rest.setToken(token);
|
|
663
844
|
let intents = this.options.intents ?? 0;
|
|
@@ -708,6 +889,7 @@ var Client = class extends import_events.EventEmitter {
|
|
|
708
889
|
await this._ws.connect();
|
|
709
890
|
return token;
|
|
710
891
|
}
|
|
892
|
+
/** Disconnect from the gateway and clear cached data. */
|
|
711
893
|
async destroy() {
|
|
712
894
|
if (this._ws) {
|
|
713
895
|
this._ws.destroy();
|
|
@@ -720,11 +902,12 @@ var Client = class extends import_events.EventEmitter {
|
|
|
720
902
|
this.channels.clear();
|
|
721
903
|
this.users.clear();
|
|
722
904
|
}
|
|
905
|
+
/** Returns true if the client has received Ready and `user` is set. */
|
|
723
906
|
isReady() {
|
|
724
907
|
return this.readyAt !== null && this.user !== null;
|
|
725
908
|
}
|
|
726
909
|
static get Routes() {
|
|
727
|
-
return
|
|
910
|
+
return import_types7.Routes;
|
|
728
911
|
}
|
|
729
912
|
};
|
|
730
913
|
|
|
@@ -754,8 +937,8 @@ var ErrorCodes = {
|
|
|
754
937
|
};
|
|
755
938
|
|
|
756
939
|
// src/index.ts
|
|
757
|
-
var
|
|
758
|
-
var
|
|
940
|
+
var import_builders2 = require("@fluxerjs/builders");
|
|
941
|
+
var import_types8 = require("@fluxerjs/types");
|
|
759
942
|
// Annotate the CommonJS export names for ESM import in node:
|
|
760
943
|
0 && (module.exports = {
|
|
761
944
|
AttachmentBuilder,
|
|
@@ -764,6 +947,7 @@ var import_types6 = require("@fluxerjs/types");
|
|
|
764
947
|
Channel,
|
|
765
948
|
Client,
|
|
766
949
|
ClientUser,
|
|
950
|
+
DMChannel,
|
|
767
951
|
EmbedBuilder,
|
|
768
952
|
ErrorCodes,
|
|
769
953
|
Events,
|