@wolfstar/plugin-gateway 0.10.0 → 0.11.0-next-20261005131555

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/esm/index.js CHANGED
@@ -8719,6 +8719,12 @@ var GuildMemberRoleManager = class GuildMemberRoleManager extends BaseManager {
8719
8719
  return this.member.guildId;
8720
8720
  }
8721
8721
  /**
8722
+ * Whether the member is partial, see {@link GuildMember.partial}. The roles of a partial member are not known.
8723
+ */
8724
+ get partial() {
8725
+ return this.member.partial;
8726
+ }
8727
+ /**
8722
8728
  * The ID of the member's user.
8723
8729
  *
8724
8730
  * @throws {GatewayError} `GuildMemberUserUnknown` when the member's payload did not include its user.
@@ -9381,6 +9387,16 @@ var GuildMember = class extends Structure {
9381
9387
  return this[kData].joined_at === void 0;
9382
9388
  }
9383
9389
  /**
9390
+ * Whether the member is partial, see {@link GuildMember.partial}, as a type guard: narrows to {@link PartialGuildMember}.
9391
+ *
9392
+ * @remarks
9393
+ * `joinedAt` stays `Date | null` on a member that is not partial: Discord types `joined_at` as nullable on the
9394
+ * gateway's member payloads, so `partial` alone can not tell that it is a date.
9395
+ */
9396
+ isPartial() {
9397
+ return this.partial;
9398
+ }
9399
+ /**
9384
9400
  * Fetches the member from the API and patches this structure with the result.
9385
9401
  */
9386
9402
  async fetch() {
@@ -13630,6 +13646,94 @@ var VoiceStateManager = class extends CachedManager {
13630
13646
  }
13631
13647
  };
13632
13648
 
13649
+ //#endregion
13650
+ //#region src/structures/channels/ThreadMember.ts
13651
+ /**
13652
+ * A member of a thread: a user who joined it, or was added to it.
13653
+ */
13654
+ var ThreadMember = class extends Structure {
13655
+ optimizeData(data) {
13656
+ this.optimizeTimestamp("join_timestamp", data.join_timestamp);
13657
+ }
13658
+ /**
13659
+ * @param data The raw thread member.
13660
+ * @param relations The guild member, thread, and user as resolved from the cache, by `client.threadMembers`.
13661
+ */
13662
+ constructor(data, relations = {}) {
13663
+ super(data, relations);
13664
+ }
13665
+ [kPatch](data) {
13666
+ if (data.member) this.dropRelations("guildMember");
13667
+ return super[kPatch](data);
13668
+ }
13669
+ /**
13670
+ * The ID of the user. Absent only from the thread member the gateway attaches to a thread payload for the bot.
13671
+ */
13672
+ get id() {
13673
+ return this[kData].user_id ?? null;
13674
+ }
13675
+ get threadId() {
13676
+ return this[kData].id ?? null;
13677
+ }
13678
+ /**
13679
+ * Whether the thread member is partial: built from its IDs alone for an event about an uncached thread member, see
13680
+ * `Partials.ThreadMember`. Only `id`, `threadId`, and `guildId` are reliable then, and {@link ThreadMember.fetch}
13681
+ * completes it.
13682
+ */
13683
+ get partial() {
13684
+ return this[kData].flags === void 0;
13685
+ }
13686
+ /**
13687
+ * Fetches the thread member from the API and patches this structure with the result.
13688
+ */
13689
+ async fetch() {
13690
+ const { threadId, id } = this;
13691
+ if (!threadId || !id) throw new GatewayError("ThreadMemberIdsMissing", "fetched");
13692
+ const member = await this.client.threadMembers.fetch(threadId, id, { force: true });
13693
+ return this[kPatch](member.toJSON());
13694
+ }
13695
+ get joinedTimestamp() {
13696
+ return this.optimizedTimestamp("join_timestamp");
13697
+ }
13698
+ get joinedAt() {
13699
+ return new Date(this.joinedTimestamp);
13700
+ }
13701
+ /**
13702
+ * The thread member's notification flags.
13703
+ */
13704
+ get flags() {
13705
+ return this[kData].flags;
13706
+ }
13707
+ /**
13708
+ * The member of the thread's guild, when known.
13709
+ */
13710
+ get guildMember() {
13711
+ return this[kRelations].guildMember ?? null;
13712
+ }
13713
+ /**
13714
+ * The thread, from the cache, like discord.js's `ThreadMember#thread`. `null` when it is not cached, or when the
13715
+ * cache is asynchronous.
13716
+ */
13717
+ get thread() {
13718
+ return this.lazyRelation("thread", (client) => cachedChannel(client, this.threadId));
13719
+ }
13720
+ /**
13721
+ * The user, from the cache, like discord.js's `ThreadMember#user`, else the user of the guild member.
13722
+ */
13723
+ get user() {
13724
+ return this[kRelations].user ?? this.guildMember?.user ?? null;
13725
+ }
13726
+ /**
13727
+ * Removes the member from the thread.
13728
+ */
13729
+ async remove() {
13730
+ const { id, threadId } = this;
13731
+ if (!id || !threadId) throw new GatewayError("ThreadMemberIdsMissing", "removed");
13732
+ await this.client.threadMembers.remove(threadId, id);
13733
+ return this;
13734
+ }
13735
+ };
13736
+
13633
13737
  //#endregion
13634
13738
  //#region src/managers/PresenceManager.ts
13635
13739
  /**
@@ -13664,6 +13768,50 @@ var PresenceManager = class extends CachedManager {
13664
13768
  }));
13665
13769
  }
13666
13770
  /**
13771
+ * Resolves a {@link PresenceResolvable} to the cached presence of its user in a guild.
13772
+ *
13773
+ * @remarks
13774
+ * A string is a **user ID**, not a cache key: build the key with {@link PresenceManager.resolveKey} to read
13775
+ * `cache.get` directly. It is a pure cache read, no request is made and a miss is `null`; presences only come from
13776
+ * the gateway.
13777
+ *
13778
+ * The guild comes from a member or a message, else from a thread member's member or thread, and otherwise from
13779
+ * `guildId`. A message sent in a direct message belongs to no guild, so it resolves to `null` unless `guildId` is
13780
+ * given.
13781
+ *
13782
+ * @param presence The presence, something holding a user, or a user ID.
13783
+ * @param guildId The guild to look the presence up in, when the value carries none.
13784
+ * @returns The presence, or `null` if it is not cached or its guild is unknown.
13785
+ */
13786
+ resolve(presence, guildId) {
13787
+ if (presence instanceof Presence) return presence;
13788
+ const userId = this.resolveId(presence);
13789
+ const guild = this.guildOf(presence) ?? guildId ?? null;
13790
+ if (userId === null || guild === null) return null;
13791
+ return whenAll([this.cache.get(this.resolveKey(guild, userId))], ([cached]) => cached ?? null);
13792
+ }
13793
+ /**
13794
+ * Resolves a {@link PresenceResolvable} to a user ID.
13795
+ *
13796
+ * @remarks
13797
+ * This is the ID of the presence's user, like discord.js, and not the cache key {@link PresenceManager.resolveKey}
13798
+ * builds from a guild and a user.
13799
+ *
13800
+ * @param presence The presence, something holding a user, or a user ID.
13801
+ * @returns The user ID, or `null` if the value holds none.
13802
+ */
13803
+ resolveId(presence) {
13804
+ if (typeof presence === "string") return presence;
13805
+ if (presence instanceof Presence) return presence.userId;
13806
+ if (presence instanceof Message) return presence.author.id || null;
13807
+ return presence.id;
13808
+ }
13809
+ guildOf(presence) {
13810
+ if (presence instanceof GuildMember || presence instanceof Message) return presence.guildId;
13811
+ if (presence instanceof ThreadMember) return presence.guildMember?.guildId ?? presence.thread?.guildId ?? null;
13812
+ return null;
13813
+ }
13814
+ /**
13667
13815
  * Lists the cached presences of a guild.
13668
13816
  *
13669
13817
  * @param guildId The ID of the guild.
@@ -13784,94 +13932,6 @@ var ThreadManager = class extends CachedManager {
13784
13932
  }
13785
13933
  };
13786
13934
 
13787
- //#endregion
13788
- //#region src/structures/channels/ThreadMember.ts
13789
- /**
13790
- * A member of a thread: a user who joined it, or was added to it.
13791
- */
13792
- var ThreadMember = class extends Structure {
13793
- optimizeData(data) {
13794
- this.optimizeTimestamp("join_timestamp", data.join_timestamp);
13795
- }
13796
- /**
13797
- * @param data The raw thread member.
13798
- * @param relations The guild member, thread, and user as resolved from the cache, by `client.threadMembers`.
13799
- */
13800
- constructor(data, relations = {}) {
13801
- super(data, relations);
13802
- }
13803
- [kPatch](data) {
13804
- if (data.member) this.dropRelations("guildMember");
13805
- return super[kPatch](data);
13806
- }
13807
- /**
13808
- * The ID of the user. Absent only from the thread member the gateway attaches to a thread payload for the bot.
13809
- */
13810
- get id() {
13811
- return this[kData].user_id ?? null;
13812
- }
13813
- get threadId() {
13814
- return this[kData].id ?? null;
13815
- }
13816
- /**
13817
- * Whether the thread member is partial: built from its IDs alone for an event about an uncached thread member, see
13818
- * `Partials.ThreadMember`. Only `id`, `threadId`, and `guildId` are reliable then, and {@link ThreadMember.fetch}
13819
- * completes it.
13820
- */
13821
- get partial() {
13822
- return this[kData].flags === void 0;
13823
- }
13824
- /**
13825
- * Fetches the thread member from the API and patches this structure with the result.
13826
- */
13827
- async fetch() {
13828
- const { threadId, id } = this;
13829
- if (!threadId || !id) throw new GatewayError("ThreadMemberIdsMissing", "fetched");
13830
- const member = await this.client.threadMembers.fetch(threadId, id, { force: true });
13831
- return this[kPatch](member.toJSON());
13832
- }
13833
- get joinedTimestamp() {
13834
- return this.optimizedTimestamp("join_timestamp");
13835
- }
13836
- get joinedAt() {
13837
- return new Date(this.joinedTimestamp);
13838
- }
13839
- /**
13840
- * The thread member's notification flags.
13841
- */
13842
- get flags() {
13843
- return this[kData].flags;
13844
- }
13845
- /**
13846
- * The member of the thread's guild, when known.
13847
- */
13848
- get guildMember() {
13849
- return this[kRelations].guildMember ?? null;
13850
- }
13851
- /**
13852
- * The thread, from the cache, like discord.js's `ThreadMember#thread`. `null` when it is not cached, or when the
13853
- * cache is asynchronous.
13854
- */
13855
- get thread() {
13856
- return this.lazyRelation("thread", (client) => cachedChannel(client, this.threadId));
13857
- }
13858
- /**
13859
- * The user, from the cache, like discord.js's `ThreadMember#user`, else the user of the guild member.
13860
- */
13861
- get user() {
13862
- return this[kRelations].user ?? this.guildMember?.user ?? null;
13863
- }
13864
- /**
13865
- * Removes the member from the thread.
13866
- */
13867
- async remove() {
13868
- const { id, threadId } = this;
13869
- if (!id || !threadId) throw new GatewayError("ThreadMemberIdsMissing", "removed");
13870
- await this.client.threadMembers.remove(threadId, id);
13871
- return this;
13872
- }
13873
- };
13874
-
13875
13935
  //#endregion
13876
13936
  //#region src/managers/ThreadMemberManager.ts
13877
13937
  /**
@@ -14503,7 +14563,8 @@ var Typing = class extends Structure {
14503
14563
  return this.lazyRelation("guild", (client) => cachedGuild(client, this[kData].guild_id));
14504
14564
  }
14505
14565
  /**
14506
- * The typing member, when the channel is in a guild: the cached member, else the one of the payload.
14566
+ * The typing member, when the channel is in a guild: the cached member, else the one of the payload, else a partial
14567
+ * one with `Partials.GuildMember`.
14507
14568
  */
14508
14569
  get member() {
14509
14570
  const resolved = this[kRelations].member;