@fluxerjs/core 1.1.1 → 1.1.3

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.mjs CHANGED
@@ -1,13 +1,14 @@
1
1
  import {
2
- Guild
3
- } from "./chunk-FRVZ7D6D.mjs";
2
+ Guild,
3
+ GuildMemberManager
4
+ } from "./chunk-Q4LJQGF6.mjs";
4
5
  import {
5
6
  MessageReaction
6
- } from "./chunk-K6NLD6SB.mjs";
7
+ } from "./chunk-YL5S4W6R.mjs";
7
8
  import {
8
9
  ClientUser,
9
10
  User
10
- } from "./chunk-4F765HVV.mjs";
11
+ } from "./chunk-5GTFNBZT.mjs";
11
12
  import {
12
13
  Message,
13
14
  ReactionCollector
@@ -28,11 +29,11 @@ import {
28
29
  MessageManager,
29
30
  TextChannel,
30
31
  VoiceChannel
31
- } from "./chunk-RWFKZ3DF.mjs";
32
+ } from "./chunk-ZKKBIQBA.mjs";
32
33
  import {
33
34
  ErrorCodes,
34
35
  FluxerError
35
- } from "./chunk-V6T5VMWD.mjs";
36
+ } from "./chunk-PU73YRKJ.mjs";
36
37
  import {
37
38
  Events
38
39
  } from "./chunk-AH7KYH2Z.mjs";
@@ -55,7 +56,7 @@ import {
55
56
  } from "./chunk-HQMYRYMY.mjs";
56
57
  import {
57
58
  Role
58
- } from "./chunk-DQ4TNBPG.mjs";
59
+ } from "./chunk-2ZSMLDEI.mjs";
59
60
  import {
60
61
  GuildBan
61
62
  } from "./chunk-UXIF75BV.mjs";
@@ -67,8 +68,7 @@ import {
67
68
  import { EventEmitter } from "events";
68
69
  import { REST } from "@fluxerjs/rest";
69
70
  import { WebSocketManager } from "@fluxerjs/ws";
70
- import { Routes as Routes3 } from "@fluxerjs/types";
71
- import { Collection as Collection3 } from "@fluxerjs/collection";
71
+ import { Routes as Routes4 } from "@fluxerjs/types";
72
72
 
73
73
  // src/client/ChannelManager.ts
74
74
  import { Collection } from "@fluxerjs/collection";
@@ -93,7 +93,7 @@ var ChannelManager = class extends Collection {
93
93
  const cached = this.get(channelId);
94
94
  if (cached) return cached;
95
95
  try {
96
- const { Channel: Channel2 } = await import("./Channel-4WVFDOCG.mjs");
96
+ const { Channel: Channel2 } = await import("./Channel-YB3LWDHZ.mjs");
97
97
  const data = await this.client.rest.get(
98
98
  Routes.channel(channelId)
99
99
  );
@@ -190,7 +190,7 @@ var GuildManager = class extends Collection2 {
190
190
  const cached = this.get(guildId);
191
191
  if (cached) return cached;
192
192
  try {
193
- const { Guild: Guild2 } = await import("./Guild-FMBCTAV4.mjs");
193
+ const { Guild: Guild2 } = await import("./Guild-BL7JEF2B.mjs");
194
194
  const data = await this.client.rest.get(
195
195
  Routes2.guild(guildId)
196
196
  );
@@ -206,6 +206,72 @@ var GuildManager = class extends Collection2 {
206
206
  // src/client/Client.ts
207
207
  import { emitDeprecationWarning as emitDeprecationWarning2, formatEmoji, parseEmoji } from "@fluxerjs/util";
208
208
 
209
+ // src/client/UsersManager.ts
210
+ import { Collection as Collection3 } from "@fluxerjs/collection";
211
+ import { Routes as Routes3 } from "@fluxerjs/types";
212
+ var UsersManager = class extends Collection3 {
213
+ constructor(client) {
214
+ super();
215
+ this.client = client;
216
+ }
217
+ /**
218
+ * Fetch a user by ID from the API.
219
+ * Updates cache if user already exists.
220
+ * @param userId - Snowflake of the user
221
+ * @returns The user
222
+ * @throws FluxerError (or REST error) if user not found
223
+ * @example
224
+ * const user = await client.users.fetch(userId);
225
+ * console.log(user.username);
226
+ */
227
+ async fetch(userId) {
228
+ const data = await this.client.rest.get(Routes3.user(userId));
229
+ return this.client.getOrCreateUser(data);
230
+ }
231
+ /**
232
+ * Fetch a user with full profile and optional guild context.
233
+ * Returns user, global profile, server profile (when guildId), and member (when guildId).
234
+ * Ideal for userinfo commands.
235
+ * @param userId - Snowflake of the user
236
+ * @param options - Optional guildId for server profile and member data
237
+ * @returns User, raw data, profiles, and member (when in guild)
238
+ * @throws FluxerError (or REST error) if user not found
239
+ * @example
240
+ * const { user, globalProfile, serverProfile, member } = await client.users.fetchWithProfile(
241
+ * userId,
242
+ * { guildId: message.guildId ?? undefined },
243
+ * );
244
+ */
245
+ async fetchWithProfile(userId, options) {
246
+ const guildId = options?.guildId ?? void 0;
247
+ const [userData, globalProfileData, serverProfileData, memberData] = await Promise.all([
248
+ this.client.rest.get(Routes3.user(userId)),
249
+ this.client.rest.get(Routes3.userProfile(userId)).catch(() => null),
250
+ guildId ? this.client.rest.get(Routes3.userProfile(userId, guildId)).catch(() => null) : Promise.resolve(null),
251
+ guildId ? this.client.rest.get(Routes3.guildMember(guildId, userId)).catch(() => null) : Promise.resolve(null)
252
+ ]);
253
+ const user = this.client.getOrCreateUser(userData);
254
+ const globalProfile = globalProfileData && typeof globalProfileData === "object" ? globalProfileData : null;
255
+ const serverProfile = serverProfileData && typeof serverProfileData === "object" ? serverProfileData : null;
256
+ let member = null;
257
+ if (memberData && guildId) {
258
+ const guild = this.client.guilds.get(guildId) ?? await this.client.guilds.fetch(guildId);
259
+ if (guild) {
260
+ member = new GuildMember(this.client, { ...memberData, guild_id: guildId }, guild);
261
+ guild.members.set(member.id, member);
262
+ }
263
+ }
264
+ return {
265
+ user,
266
+ userData,
267
+ globalProfile,
268
+ serverProfile,
269
+ member,
270
+ memberData
271
+ };
272
+ }
273
+ };
274
+
209
275
  // src/client/EventHandlerRegistry.ts
210
276
  var handlers = /* @__PURE__ */ new Map();
211
277
  handlers.set("MESSAGE_CREATE", async (client, d) => {
@@ -237,7 +303,7 @@ handlers.set("MESSAGE_DELETE", async (client, d) => {
237
303
  });
238
304
  handlers.set("MESSAGE_REACTION_ADD", async (client, d) => {
239
305
  const data = d;
240
- const { MessageReaction: MessageReaction2 } = await import("./MessageReaction-AYSOCOMX.mjs");
306
+ const { MessageReaction: MessageReaction2 } = await import("./MessageReaction-GYQNJ6GX.mjs");
241
307
  const reaction = new MessageReaction2(client, data);
242
308
  const user = client.getOrCreateUser({
243
309
  id: data.user_id,
@@ -256,7 +322,7 @@ handlers.set("MESSAGE_REACTION_ADD", async (client, d) => {
256
322
  });
257
323
  handlers.set("MESSAGE_REACTION_REMOVE", async (client, d) => {
258
324
  const data = d;
259
- const { MessageReaction: MessageReaction2 } = await import("./MessageReaction-AYSOCOMX.mjs");
325
+ const { MessageReaction: MessageReaction2 } = await import("./MessageReaction-GYQNJ6GX.mjs");
260
326
  const reaction = new MessageReaction2(client, data);
261
327
  const user = client.getOrCreateUser({
262
328
  id: data.user_id,
@@ -283,8 +349,9 @@ handlers.set("MESSAGE_REACTION_REMOVE_EMOJI", async (client, d) => {
283
349
  );
284
350
  });
285
351
  handlers.set("GUILD_CREATE", async (client, d) => {
286
- const { Guild: Guild2 } = await import("./Guild-FMBCTAV4.mjs");
287
- const { Channel: Channel2 } = await import("./Channel-4WVFDOCG.mjs");
352
+ const { Guild: Guild2 } = await import("./Guild-BL7JEF2B.mjs");
353
+ const { Channel: Channel2 } = await import("./Channel-YB3LWDHZ.mjs");
354
+ const { GuildMember: GuildMember2 } = await import("./GuildMember-43B5E5CH.mjs");
288
355
  const raw = d;
289
356
  const guildData = raw?.properties != null ? { ...raw.properties, roles: raw.roles } : raw;
290
357
  const guild = new Guild2(client, guildData);
@@ -294,13 +361,20 @@ handlers.set("GUILD_CREATE", async (client, d) => {
294
361
  const channel = Channel2.from(client, ch);
295
362
  if (channel) client.channels.set(channel.id, channel);
296
363
  }
364
+ for (const m of g.members ?? []) {
365
+ if (m?.user?.id) {
366
+ const memberData = { ...m, guild_id: guild.id };
367
+ const member = new GuildMember2(client, memberData, guild);
368
+ guild.members.set(member.id, member);
369
+ }
370
+ }
297
371
  client.emit(Events.GuildCreate, guild);
298
372
  if (g.voice_states?.length) {
299
373
  client.emit(Events.VoiceStatesSync, { guildId: guild.id, voiceStates: g.voice_states });
300
374
  }
301
375
  });
302
376
  handlers.set("GUILD_UPDATE", async (client, d) => {
303
- const { Guild: Guild2 } = await import("./Guild-FMBCTAV4.mjs");
377
+ const { Guild: Guild2 } = await import("./Guild-BL7JEF2B.mjs");
304
378
  const raw = d;
305
379
  const guildData = raw?.properties != null ? { ...raw.properties, roles: raw.roles } : raw;
306
380
  const old = client.guilds.get(guildData.id);
@@ -317,7 +391,7 @@ handlers.set("GUILD_DELETE", async (client, d) => {
317
391
  }
318
392
  });
319
393
  handlers.set("CHANNEL_CREATE", async (client, d) => {
320
- const { Channel: Channel2 } = await import("./Channel-4WVFDOCG.mjs");
394
+ const { Channel: Channel2 } = await import("./Channel-YB3LWDHZ.mjs");
321
395
  const ch = Channel2.from(client, d);
322
396
  if (ch) {
323
397
  client.channels.set(ch.id, ch);
@@ -325,7 +399,7 @@ handlers.set("CHANNEL_CREATE", async (client, d) => {
325
399
  }
326
400
  });
327
401
  handlers.set("CHANNEL_UPDATE", async (client, d) => {
328
- const { Channel: Channel2 } = await import("./Channel-4WVFDOCG.mjs");
402
+ const { Channel: Channel2 } = await import("./Channel-YB3LWDHZ.mjs");
329
403
  const ch = d;
330
404
  const oldCh = client.channels.get(ch.id);
331
405
  const newCh = Channel2.from(client, ch);
@@ -411,7 +485,7 @@ handlers.set("GUILD_ROLE_CREATE", async (client, d) => {
411
485
  const data = d;
412
486
  const guild = client.guilds.get(data.guild_id);
413
487
  if (guild) {
414
- const { Role: Role2 } = await import("./Role-5MWSGL66.mjs");
488
+ const { Role: Role2 } = await import("./Role-SERSJFJC.mjs");
415
489
  guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
416
490
  }
417
491
  client.emit(Events.GuildRoleCreate, data);
@@ -420,8 +494,13 @@ handlers.set("GUILD_ROLE_UPDATE", async (client, d) => {
420
494
  const data = d;
421
495
  const guild = client.guilds.get(data.guild_id);
422
496
  if (guild) {
423
- const { Role: Role2 } = await import("./Role-5MWSGL66.mjs");
424
- guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
497
+ const existing = guild.roles.get(data.role.id);
498
+ if (existing) {
499
+ existing._patch(data.role);
500
+ } else {
501
+ const { Role: Role2 } = await import("./Role-SERSJFJC.mjs");
502
+ guild.roles.set(data.role.id, new Role2(client, data.role, guild.id));
503
+ }
425
504
  }
426
505
  client.emit(Events.GuildRoleUpdate, data);
427
506
  });
@@ -498,6 +577,10 @@ var Client = class extends EventEmitter {
498
577
  get: () => this.guilds,
499
578
  configurable: true
500
579
  });
580
+ Object.defineProperty(this.users, "cache", {
581
+ get: () => this.users,
582
+ configurable: true
583
+ });
501
584
  this.rest = new REST({
502
585
  api: options.rest?.api ?? "https://api.fluxer.app",
503
586
  version: options.rest?.version ?? "1",
@@ -507,7 +590,7 @@ var Client = class extends EventEmitter {
507
590
  rest;
508
591
  guilds = new GuildManager(this);
509
592
  channels = new ChannelManager(this);
510
- users = new Collection3();
593
+ users = new UsersManager(this);
511
594
  /** Typed event handlers. Use client.events.MessageReactionAdd((reaction, user, messageId, channelId, emoji, userId) => {...}) or client.on(Events.MessageReactionAdd, ...). */
512
595
  events;
513
596
  /** The authenticated bot user. Null until READY is received. */
@@ -534,7 +617,7 @@ var Client = class extends EventEmitter {
534
617
  if (parsed.id) return formatEmoji(parsed);
535
618
  if (!/^\w+$/.test(parsed.name)) return encodeURIComponent(parsed.name);
536
619
  if (guildId) {
537
- const emojis = await this.rest.get(Routes3.guildEmojis(guildId));
620
+ const emojis = await this.rest.get(Routes4.guildEmojis(guildId));
538
621
  const list = Array.isArray(emojis) ? emojis : Object.values(emojis ?? {});
539
622
  const found = list.find((e) => e.name && e.name.toLowerCase() === parsed.name.toLowerCase());
540
623
  if (found) return formatEmoji({ ...parsed, id: found.id, animated: found.animated });
@@ -651,9 +734,9 @@ var Client = class extends EventEmitter {
651
734
  async ({
652
735
  data
653
736
  }) => {
654
- const { ClientUser: ClientUser2 } = await import("./ClientUser-PXAAKR2P.mjs");
655
- const { Guild: Guild2 } = await import("./Guild-FMBCTAV4.mjs");
656
- const { Channel: Channel2 } = await import("./Channel-4WVFDOCG.mjs");
737
+ const { ClientUser: ClientUser2 } = await import("./ClientUser-URMZ5DEV.mjs");
738
+ const { Guild: Guild2 } = await import("./Guild-BL7JEF2B.mjs");
739
+ const { Channel: Channel2 } = await import("./Channel-YB3LWDHZ.mjs");
657
740
  this.user = new ClientUser2(this, data.user);
658
741
  for (const g of data.guilds ?? []) {
659
742
  const guildData = g && typeof g === "object" && "properties" in g && g.properties ? {
@@ -701,12 +784,12 @@ var Client = class extends EventEmitter {
701
784
  return this.readyAt !== null && this.user !== null;
702
785
  }
703
786
  static get Routes() {
704
- return Routes3;
787
+ return Routes4;
705
788
  }
706
789
  };
707
790
 
708
791
  // src/structures/GuildEmoji.ts
709
- import { Routes as Routes4 } from "@fluxerjs/types";
792
+ import { Routes as Routes5 } from "@fluxerjs/types";
710
793
  var GuildEmoji = class extends Base {
711
794
  client;
712
795
  id;
@@ -733,7 +816,7 @@ var GuildEmoji = class extends Base {
733
816
  }
734
817
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
735
818
  async delete() {
736
- await this.client.rest.delete(Routes4.guildEmoji(this.guildId, this.id), {
819
+ await this.client.rest.delete(Routes5.guildEmoji(this.guildId, this.id), {
737
820
  auth: true
738
821
  });
739
822
  }
@@ -742,7 +825,7 @@ var GuildEmoji = class extends Base {
742
825
  * Requires Manage Emojis and Stickers permission.
743
826
  */
744
827
  async edit(options) {
745
- const data = await this.client.rest.patch(Routes4.guildEmoji(this.guildId, this.id), {
828
+ const data = await this.client.rest.patch(Routes5.guildEmoji(this.guildId, this.id), {
746
829
  body: options,
747
830
  auth: true
748
831
  });
@@ -752,7 +835,7 @@ var GuildEmoji = class extends Base {
752
835
  };
753
836
 
754
837
  // src/structures/GuildSticker.ts
755
- import { Routes as Routes5 } from "@fluxerjs/types";
838
+ import { Routes as Routes6 } from "@fluxerjs/types";
756
839
  var GuildSticker = class extends Base {
757
840
  client;
758
841
  id;
@@ -779,7 +862,7 @@ var GuildSticker = class extends Base {
779
862
  }
780
863
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
781
864
  async delete() {
782
- await this.client.rest.delete(Routes5.guildSticker(this.guildId, this.id), {
865
+ await this.client.rest.delete(Routes6.guildSticker(this.guildId, this.id), {
783
866
  auth: true
784
867
  });
785
868
  }
@@ -788,7 +871,7 @@ var GuildSticker = class extends Base {
788
871
  * Requires Manage Emojis and Stickers permission.
789
872
  */
790
873
  async edit(options) {
791
- const data = await this.client.rest.patch(Routes5.guildSticker(this.guildId, this.id), {
874
+ const data = await this.client.rest.patch(Routes6.guildSticker(this.guildId, this.id), {
792
875
  body: options,
793
876
  auth: true
794
877
  });
@@ -801,11 +884,14 @@ var GuildSticker = class extends Base {
801
884
 
802
885
  // src/index.ts
803
886
  import { EmbedBuilder, MessagePayload, AttachmentBuilder } from "@fluxerjs/builders";
804
- import { Routes as Routes6, GatewayOpcodes, MessageAttachmentFlags } from "@fluxerjs/types";
887
+ import { Routes as Routes7, GatewayOpcodes, MessageAttachmentFlags } from "@fluxerjs/types";
805
888
  import { resolveTenorToImageUrl } from "@fluxerjs/util";
806
889
  import {
807
890
  PermissionsBitField,
808
- PermissionFlags
891
+ PermissionFlags,
892
+ resolvePermissionsToBitfield,
893
+ UserFlagsBitField,
894
+ UserFlagsBits
809
895
  } from "@fluxerjs/util";
810
896
  export {
811
897
  AttachmentBuilder,
@@ -826,6 +912,7 @@ export {
826
912
  GuildChannel,
827
913
  GuildEmoji,
828
914
  GuildMember,
915
+ GuildMemberManager,
829
916
  GuildSticker,
830
917
  Invite,
831
918
  LinkChannel,
@@ -839,9 +926,12 @@ export {
839
926
  PermissionsBitField,
840
927
  ReactionCollector,
841
928
  Role,
842
- Routes6 as Routes,
929
+ Routes7 as Routes,
843
930
  TextChannel,
844
931
  User,
932
+ UserFlagsBitField,
933
+ UserFlagsBits,
934
+ UsersManager,
845
935
  VoiceChannel,
846
936
  Webhook,
847
937
  cdnAvatarURL,
@@ -850,5 +940,6 @@ export {
850
940
  cdnDisplayAvatarURL,
851
941
  cdnMemberAvatarURL,
852
942
  cdnMemberBannerURL,
943
+ resolvePermissionsToBitfield,
853
944
  resolveTenorToImageUrl
854
945
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.1.1",
6
+ "version": "1.1.3",
7
7
  "description": "A fully-featured SDK for Fluxer bots",
8
8
  "repository": {
9
9
  "type": "git",
@@ -34,12 +34,12 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@fluxerjs/rest": "1.1.1",
38
- "@fluxerjs/ws": "1.1.1",
39
- "@fluxerjs/collection": "1.1.1",
40
- "@fluxerjs/builders": "1.1.1",
41
- "@fluxerjs/util": "1.1.1",
42
- "@fluxerjs/types": "1.1.1"
37
+ "@fluxerjs/ws": "1.1.3",
38
+ "@fluxerjs/rest": "1.1.3",
39
+ "@fluxerjs/collection": "1.1.3",
40
+ "@fluxerjs/util": "1.1.3",
41
+ "@fluxerjs/types": "1.1.3",
42
+ "@fluxerjs/builders": "1.1.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^20.0.0",
@@ -1,63 +0,0 @@
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
- };