@fluxerjs/core 1.0.2 → 1.0.5

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/index.js CHANGED
@@ -135,18 +135,93 @@ var init_Message = __esm({
135
135
  }
136
136
  });
137
137
 
138
+ // src/structures/Webhook.ts
139
+ var Webhook_exports = {};
140
+ __export(Webhook_exports, {
141
+ Webhook: () => Webhook
142
+ });
143
+ var import_types2, Webhook;
144
+ var init_Webhook = __esm({
145
+ "src/structures/Webhook.ts"() {
146
+ "use strict";
147
+ init_Base();
148
+ import_types2 = require("@fluxerjs/types");
149
+ Webhook = class _Webhook extends Base {
150
+ client;
151
+ id;
152
+ guildId;
153
+ channelId;
154
+ name;
155
+ avatar;
156
+ /** Present only when webhook was created via createWebhook(); not returned when fetching. */
157
+ token;
158
+ constructor(client, data) {
159
+ super();
160
+ this.client = client;
161
+ this.id = data.id;
162
+ this.guildId = data.guild_id;
163
+ this.channelId = data.channel_id;
164
+ this.name = data.name ?? "Unknown";
165
+ this.avatar = data.avatar ?? null;
166
+ this.token = data.token ?? null;
167
+ }
168
+ /** Delete this webhook. Requires bot token with Manage Webhooks permission. */
169
+ async delete() {
170
+ await this.client.rest.delete(import_types2.Routes.webhook(this.id), { auth: true });
171
+ }
172
+ /**
173
+ * Send a message via this webhook. Requires the webhook token (only present when created, not when fetched).
174
+ * @throws Error if token is not available
175
+ */
176
+ async send(options) {
177
+ if (!this.token) {
178
+ throw new Error("Webhook token is required to send. The token is only returned when creating a webhook; fetched webhooks cannot send.");
179
+ }
180
+ const body = typeof options === "string" ? { content: options } : options;
181
+ await this.client.rest.post(import_types2.Routes.webhookExecute(this.id, this.token), {
182
+ body,
183
+ auth: false
184
+ });
185
+ }
186
+ /**
187
+ * Fetch a webhook by ID using bot auth. The returned webhook will not have a token (cannot send).
188
+ */
189
+ static async fetch(client, webhookId) {
190
+ const data = await client.rest.get(import_types2.Routes.webhook(webhookId));
191
+ return new _Webhook(client, data);
192
+ }
193
+ /**
194
+ * Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).
195
+ * Useful when you have the token from a previous createWebhook() call.
196
+ */
197
+ static fromToken(client, webhookId, token, options) {
198
+ return new _Webhook(client, {
199
+ id: webhookId,
200
+ guild_id: options?.guildId ?? "",
201
+ channel_id: options?.channelId ?? "",
202
+ name: options?.name ?? "Webhook",
203
+ avatar: null,
204
+ token,
205
+ user: { id: "", username: "webhook", discriminator: "0" }
206
+ });
207
+ }
208
+ };
209
+ }
210
+ });
211
+
138
212
  // src/structures/Guild.ts
139
213
  var Guild_exports = {};
140
214
  __export(Guild_exports, {
141
215
  Guild: () => Guild
142
216
  });
143
- var import_collection2, Guild;
217
+ var import_collection2, import_types3, Guild;
144
218
  var init_Guild = __esm({
145
219
  "src/structures/Guild.ts"() {
146
220
  "use strict";
147
221
  init_Base();
148
222
  import_collection2 = require("@fluxerjs/collection");
149
223
  init_Constants();
224
+ import_types3 = require("@fluxerjs/types");
150
225
  Guild = class extends Base {
151
226
  client;
152
227
  id;
@@ -175,6 +250,13 @@ var init_Guild = __esm({
175
250
  const size = options?.size ? `?size=${options.size}` : "";
176
251
  return `${CDN_URL}/banners/${this.id}/${this.banner}.png${size}`;
177
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
+ }
178
260
  };
179
261
  }
180
262
  });
@@ -189,12 +271,12 @@ __export(Channel_exports, {
189
271
  TextChannel: () => TextChannel,
190
272
  VoiceChannel: () => VoiceChannel
191
273
  });
192
- var import_types2, Channel, GuildChannel, TextChannel, CategoryChannel, VoiceChannel, LinkChannel;
274
+ var import_types4, Channel, GuildChannel, TextChannel, CategoryChannel, VoiceChannel, LinkChannel;
193
275
  var init_Channel = __esm({
194
276
  "src/structures/Channel.ts"() {
195
277
  "use strict";
196
278
  init_Base();
197
- import_types2 = require("@fluxerjs/types");
279
+ import_types4 = require("@fluxerjs/types");
198
280
  Channel = class extends Base {
199
281
  client;
200
282
  id;
@@ -207,10 +289,10 @@ var init_Channel = __esm({
207
289
  }
208
290
  static from(client, data) {
209
291
  const type = data.type ?? 0;
210
- if (type === import_types2.ChannelType.GuildText) return new TextChannel(client, data);
211
- if (type === import_types2.ChannelType.GuildCategory) return new CategoryChannel(client, data);
212
- if (type === import_types2.ChannelType.GuildVoice) return new VoiceChannel(client, data);
213
- if (type === import_types2.ChannelType.GuildLink) return new LinkChannel(client, data);
292
+ if (type === import_types4.ChannelType.GuildText) return new TextChannel(client, data);
293
+ if (type === import_types4.ChannelType.GuildCategory) return new CategoryChannel(client, data);
294
+ if (type === import_types4.ChannelType.GuildVoice) return new VoiceChannel(client, data);
295
+ if (type === import_types4.ChannelType.GuildLink) return new LinkChannel(client, data);
214
296
  return new GuildChannel(client, data);
215
297
  }
216
298
  };
@@ -226,6 +308,22 @@ var init_Channel = __esm({
226
308
  this.position = data.position;
227
309
  this.parentId = data.parent_id ?? null;
228
310
  }
311
+ /** Create a webhook in this channel. Returns the webhook with token (required for send()). */
312
+ async createWebhook(options) {
313
+ const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
314
+ const data = await this.client.rest.post(import_types4.Routes.channelWebhooks(this.id), {
315
+ body: options,
316
+ auth: true
317
+ });
318
+ return new Webhook2(this.client, data);
319
+ }
320
+ /** Fetch all webhooks in this channel. Returned webhooks do not include the token (cannot send). */
321
+ async fetchWebhooks() {
322
+ const { Webhook: Webhook2 } = await Promise.resolve().then(() => (init_Webhook(), Webhook_exports));
323
+ const data = await this.client.rest.get(import_types4.Routes.channelWebhooks(this.id));
324
+ const list = Array.isArray(data) ? data : Object.values(data ?? {});
325
+ return list.map((w) => new Webhook2(this.client, w));
326
+ }
229
327
  };
230
328
  TextChannel = class extends GuildChannel {
231
329
  topic;
@@ -242,7 +340,7 @@ var init_Channel = __esm({
242
340
  async send(options) {
243
341
  const body = typeof options === "string" ? { content: options } : options;
244
342
  const { Message: Message2 } = await Promise.resolve().then(() => (init_Message(), Message_exports));
245
- const data = await this.client.rest.post(import_types2.Routes.channelMessages(this.id), { body });
343
+ const data = await this.client.rest.post(import_types4.Routes.channelMessages(this.id), { body });
246
344
  return new Message2(this.client, data);
247
345
  }
248
346
  };
@@ -338,17 +436,18 @@ __export(index_exports, {
338
436
  ErrorCodes: () => ErrorCodes,
339
437
  Events: () => Events,
340
438
  FluxerError: () => FluxerError,
341
- GatewayOpcodes: () => import_types4.GatewayOpcodes,
439
+ GatewayOpcodes: () => import_types6.GatewayOpcodes,
342
440
  Guild: () => Guild,
343
441
  GuildChannel: () => GuildChannel,
344
442
  GuildMember: () => GuildMember,
345
443
  LinkChannel: () => LinkChannel,
346
444
  Message: () => Message,
347
445
  MessagePayload: () => import_builders.MessagePayload,
348
- Routes: () => import_types4.Routes,
446
+ Routes: () => import_types6.Routes,
349
447
  TextChannel: () => TextChannel,
350
448
  User: () => User,
351
- VoiceChannel: () => VoiceChannel
449
+ VoiceChannel: () => VoiceChannel,
450
+ Webhook: () => Webhook
352
451
  });
353
452
  module.exports = __toCommonJS(index_exports);
354
453
 
@@ -356,7 +455,7 @@ module.exports = __toCommonJS(index_exports);
356
455
  var import_events = require("events");
357
456
  var import_rest = require("@fluxerjs/rest");
358
457
  var import_ws = require("@fluxerjs/ws");
359
- var import_types3 = require("@fluxerjs/types");
458
+ var import_types5 = require("@fluxerjs/types");
360
459
  var import_collection3 = require("@fluxerjs/collection");
361
460
 
362
461
  // src/util/Events.ts
@@ -365,6 +464,10 @@ var Events = {
365
464
  MessageCreate: "messageCreate",
366
465
  MessageUpdate: "messageUpdate",
367
466
  MessageDelete: "messageDelete",
467
+ MessageReactionAdd: "messageReactionAdd",
468
+ MessageReactionRemove: "messageReactionRemove",
469
+ MessageReactionRemoveAll: "messageReactionRemoveAll",
470
+ MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
368
471
  InteractionCreate: "interactionCreate",
369
472
  GuildCreate: "guildCreate",
370
473
  GuildUpdate: "guildUpdate",
@@ -426,6 +529,18 @@ var Client = class extends import_events.EventEmitter {
426
529
  case "MESSAGE_DELETE":
427
530
  this.emit(Events.MessageDelete, { id: d.id, channelId: d.channel_id });
428
531
  break;
532
+ case "MESSAGE_REACTION_ADD":
533
+ this.emit(Events.MessageReactionAdd, d);
534
+ break;
535
+ case "MESSAGE_REACTION_REMOVE":
536
+ this.emit(Events.MessageReactionRemove, d);
537
+ break;
538
+ case "MESSAGE_REACTION_REMOVE_ALL":
539
+ this.emit(Events.MessageReactionRemoveAll, d);
540
+ break;
541
+ case "MESSAGE_REACTION_REMOVE_EMOJI":
542
+ this.emit(Events.MessageReactionRemoveEmoji, d);
543
+ break;
429
544
  case "GUILD_CREATE": {
430
545
  const { Guild: Guild2 } = await Promise.resolve().then(() => (init_Guild(), Guild_exports));
431
546
  const { Channel: Channel2 } = await Promise.resolve().then(() => (init_Channel(), Channel_exports));
@@ -560,6 +675,7 @@ var Client = class extends import_events.EventEmitter {
560
675
  this._ws = new import_ws.WebSocketManager({
561
676
  token,
562
677
  intents,
678
+ presence: this.options.presence,
563
679
  rest: { get: (route) => this.rest.get(route) },
564
680
  version: this.options.rest?.version ?? "1",
565
681
  WebSocket: this.options.WebSocket
@@ -608,7 +724,7 @@ var Client = class extends import_events.EventEmitter {
608
724
  return this.readyAt !== null && this.user !== null;
609
725
  }
610
726
  static get Routes() {
611
- return import_types3.Routes;
727
+ return import_types5.Routes;
612
728
  }
613
729
  };
614
730
 
@@ -619,6 +735,7 @@ init_User();
619
735
  init_Guild();
620
736
  init_Channel();
621
737
  init_Message();
738
+ init_Webhook();
622
739
  init_GuildMember();
623
740
 
624
741
  // src/errors/FluxerError.ts
@@ -638,7 +755,7 @@ var ErrorCodes = {
638
755
 
639
756
  // src/index.ts
640
757
  var import_builders = require("@fluxerjs/builders");
641
- var import_types4 = require("@fluxerjs/types");
758
+ var import_types6 = require("@fluxerjs/types");
642
759
  // Annotate the CommonJS export names for ESM import in node:
643
760
  0 && (module.exports = {
644
761
  AttachmentBuilder,
@@ -661,5 +778,6 @@ var import_types4 = require("@fluxerjs/types");
661
778
  Routes,
662
779
  TextChannel,
663
780
  User,
664
- VoiceChannel
781
+ VoiceChannel,
782
+ Webhook
665
783
  });
package/dist/index.mjs CHANGED
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  Message
3
3
  } from "./chunk-LBBIQOSH.mjs";
4
+ import {
5
+ Webhook
6
+ } from "./chunk-BUEXP5SZ.mjs";
4
7
  import {
5
8
  Guild
6
- } from "./chunk-GUNWHOQO.mjs";
9
+ } from "./chunk-7GZN6JXT.mjs";
7
10
  import {
8
11
  CategoryChannel,
9
12
  Channel,
@@ -11,7 +14,7 @@ import {
11
14
  LinkChannel,
12
15
  TextChannel,
13
16
  VoiceChannel
14
- } from "./chunk-F2EEQP5O.mjs";
17
+ } from "./chunk-ZHRQQZ4X.mjs";
15
18
  import {
16
19
  GuildMember
17
20
  } from "./chunk-TE5IC7IP.mjs";
@@ -39,6 +42,10 @@ var Events = {
39
42
  MessageCreate: "messageCreate",
40
43
  MessageUpdate: "messageUpdate",
41
44
  MessageDelete: "messageDelete",
45
+ MessageReactionAdd: "messageReactionAdd",
46
+ MessageReactionRemove: "messageReactionRemove",
47
+ MessageReactionRemoveAll: "messageReactionRemoveAll",
48
+ MessageReactionRemoveEmoji: "messageReactionRemoveEmoji",
42
49
  InteractionCreate: "interactionCreate",
43
50
  GuildCreate: "guildCreate",
44
51
  GuildUpdate: "guildUpdate",
@@ -100,9 +107,21 @@ var Client = class extends EventEmitter {
100
107
  case "MESSAGE_DELETE":
101
108
  this.emit(Events.MessageDelete, { id: d.id, channelId: d.channel_id });
102
109
  break;
110
+ case "MESSAGE_REACTION_ADD":
111
+ this.emit(Events.MessageReactionAdd, d);
112
+ break;
113
+ case "MESSAGE_REACTION_REMOVE":
114
+ this.emit(Events.MessageReactionRemove, d);
115
+ break;
116
+ case "MESSAGE_REACTION_REMOVE_ALL":
117
+ this.emit(Events.MessageReactionRemoveAll, d);
118
+ break;
119
+ case "MESSAGE_REACTION_REMOVE_EMOJI":
120
+ this.emit(Events.MessageReactionRemoveEmoji, d);
121
+ break;
103
122
  case "GUILD_CREATE": {
104
- const { Guild: Guild2 } = await import("./Guild-GOQZ7XP4.mjs");
105
- const { Channel: Channel2 } = await import("./Channel-TOAQGSRX.mjs");
123
+ const { Guild: Guild2 } = await import("./Guild-NHNQ5TIA.mjs");
124
+ const { Channel: Channel2 } = await import("./Channel-2WNJ445K.mjs");
106
125
  const guild = new Guild2(this, d);
107
126
  this.guilds.set(guild.id, guild);
108
127
  const g = d;
@@ -117,7 +136,7 @@ var Client = class extends EventEmitter {
117
136
  break;
118
137
  }
119
138
  case "GUILD_UPDATE": {
120
- const { Guild: Guild2 } = await import("./Guild-GOQZ7XP4.mjs");
139
+ const { Guild: Guild2 } = await import("./Guild-NHNQ5TIA.mjs");
121
140
  const g = d;
122
141
  const old = this.guilds.get(g.id);
123
142
  const updated = new Guild2(this, g);
@@ -135,7 +154,7 @@ var Client = class extends EventEmitter {
135
154
  break;
136
155
  }
137
156
  case "CHANNEL_CREATE": {
138
- const { Channel: Channel2 } = await import("./Channel-TOAQGSRX.mjs");
157
+ const { Channel: Channel2 } = await import("./Channel-2WNJ445K.mjs");
139
158
  const ch = Channel2.from(this, d);
140
159
  if (ch) {
141
160
  this.channels.set(ch.id, ch);
@@ -144,7 +163,7 @@ var Client = class extends EventEmitter {
144
163
  break;
145
164
  }
146
165
  case "CHANNEL_UPDATE": {
147
- const { Channel: Channel2 } = await import("./Channel-TOAQGSRX.mjs");
166
+ const { Channel: Channel2 } = await import("./Channel-2WNJ445K.mjs");
148
167
  const ch = d;
149
168
  const oldCh = this.channels.get(ch.id);
150
169
  const newCh = Channel2.from(this, ch);
@@ -234,6 +253,7 @@ var Client = class extends EventEmitter {
234
253
  this._ws = new WebSocketManager({
235
254
  token,
236
255
  intents,
256
+ presence: this.options.presence,
237
257
  rest: { get: (route) => this.rest.get(route) },
238
258
  version: this.options.rest?.version ?? "1",
239
259
  WebSocket: this.options.WebSocket
@@ -243,8 +263,8 @@ var Client = class extends EventEmitter {
243
263
  });
244
264
  this._ws.on("ready", async ({ data }) => {
245
265
  const { ClientUser: ClientUser2 } = await import("./ClientUser-RNDKHQ3Z.mjs");
246
- const { Guild: Guild2 } = await import("./Guild-GOQZ7XP4.mjs");
247
- const { Channel: Channel2 } = await import("./Channel-TOAQGSRX.mjs");
266
+ const { Guild: Guild2 } = await import("./Guild-NHNQ5TIA.mjs");
267
+ const { Channel: Channel2 } = await import("./Channel-2WNJ445K.mjs");
248
268
  this.user = new ClientUser2(this, data.user);
249
269
  for (const g of data.guilds ?? []) {
250
270
  const guild = new Guild2(this, g);
@@ -325,5 +345,6 @@ export {
325
345
  Routes2 as Routes,
326
346
  TextChannel,
327
347
  User,
328
- VoiceChannel
348
+ VoiceChannel,
349
+ Webhook
329
350
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.2",
6
+ "version": "1.0.5",
7
7
  "description": "A fully-featured SDK for Fluxer bots",
8
8
  "main": "./dist/index.js",
9
9
  "module": "./dist/index.mjs",
@@ -19,12 +19,12 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@fluxerjs/builders": "1.0.2",
23
- "@fluxerjs/types": "1.0.2",
24
- "@fluxerjs/rest": "1.0.2",
25
- "@fluxerjs/ws": "1.0.2",
26
- "@fluxerjs/collection": "1.0.2",
27
- "@fluxerjs/util": "1.0.2"
22
+ "@fluxerjs/rest": "1.0.5",
23
+ "@fluxerjs/builders": "1.0.5",
24
+ "@fluxerjs/ws": "1.0.5",
25
+ "@fluxerjs/util": "1.0.5",
26
+ "@fluxerjs/types": "1.0.5",
27
+ "@fluxerjs/collection": "1.0.5"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^20.0.0",