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

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
@@ -13630,6 +13630,94 @@ var VoiceStateManager = class extends CachedManager {
13630
13630
  }
13631
13631
  };
13632
13632
 
13633
+ //#endregion
13634
+ //#region src/structures/channels/ThreadMember.ts
13635
+ /**
13636
+ * A member of a thread: a user who joined it, or was added to it.
13637
+ */
13638
+ var ThreadMember = class extends Structure {
13639
+ optimizeData(data) {
13640
+ this.optimizeTimestamp("join_timestamp", data.join_timestamp);
13641
+ }
13642
+ /**
13643
+ * @param data The raw thread member.
13644
+ * @param relations The guild member, thread, and user as resolved from the cache, by `client.threadMembers`.
13645
+ */
13646
+ constructor(data, relations = {}) {
13647
+ super(data, relations);
13648
+ }
13649
+ [kPatch](data) {
13650
+ if (data.member) this.dropRelations("guildMember");
13651
+ return super[kPatch](data);
13652
+ }
13653
+ /**
13654
+ * The ID of the user. Absent only from the thread member the gateway attaches to a thread payload for the bot.
13655
+ */
13656
+ get id() {
13657
+ return this[kData].user_id ?? null;
13658
+ }
13659
+ get threadId() {
13660
+ return this[kData].id ?? null;
13661
+ }
13662
+ /**
13663
+ * Whether the thread member is partial: built from its IDs alone for an event about an uncached thread member, see
13664
+ * `Partials.ThreadMember`. Only `id`, `threadId`, and `guildId` are reliable then, and {@link ThreadMember.fetch}
13665
+ * completes it.
13666
+ */
13667
+ get partial() {
13668
+ return this[kData].flags === void 0;
13669
+ }
13670
+ /**
13671
+ * Fetches the thread member from the API and patches this structure with the result.
13672
+ */
13673
+ async fetch() {
13674
+ const { threadId, id } = this;
13675
+ if (!threadId || !id) throw new GatewayError("ThreadMemberIdsMissing", "fetched");
13676
+ const member = await this.client.threadMembers.fetch(threadId, id, { force: true });
13677
+ return this[kPatch](member.toJSON());
13678
+ }
13679
+ get joinedTimestamp() {
13680
+ return this.optimizedTimestamp("join_timestamp");
13681
+ }
13682
+ get joinedAt() {
13683
+ return new Date(this.joinedTimestamp);
13684
+ }
13685
+ /**
13686
+ * The thread member's notification flags.
13687
+ */
13688
+ get flags() {
13689
+ return this[kData].flags;
13690
+ }
13691
+ /**
13692
+ * The member of the thread's guild, when known.
13693
+ */
13694
+ get guildMember() {
13695
+ return this[kRelations].guildMember ?? null;
13696
+ }
13697
+ /**
13698
+ * The thread, from the cache, like discord.js's `ThreadMember#thread`. `null` when it is not cached, or when the
13699
+ * cache is asynchronous.
13700
+ */
13701
+ get thread() {
13702
+ return this.lazyRelation("thread", (client) => cachedChannel(client, this.threadId));
13703
+ }
13704
+ /**
13705
+ * The user, from the cache, like discord.js's `ThreadMember#user`, else the user of the guild member.
13706
+ */
13707
+ get user() {
13708
+ return this[kRelations].user ?? this.guildMember?.user ?? null;
13709
+ }
13710
+ /**
13711
+ * Removes the member from the thread.
13712
+ */
13713
+ async remove() {
13714
+ const { id, threadId } = this;
13715
+ if (!id || !threadId) throw new GatewayError("ThreadMemberIdsMissing", "removed");
13716
+ await this.client.threadMembers.remove(threadId, id);
13717
+ return this;
13718
+ }
13719
+ };
13720
+
13633
13721
  //#endregion
13634
13722
  //#region src/managers/PresenceManager.ts
13635
13723
  /**
@@ -13664,6 +13752,50 @@ var PresenceManager = class extends CachedManager {
13664
13752
  }));
13665
13753
  }
13666
13754
  /**
13755
+ * Resolves a {@link PresenceResolvable} to the cached presence of its user in a guild.
13756
+ *
13757
+ * @remarks
13758
+ * A string is a **user ID**, not a cache key: build the key with {@link PresenceManager.resolveKey} to read
13759
+ * `cache.get` directly. It is a pure cache read, no request is made and a miss is `null`; presences only come from
13760
+ * the gateway.
13761
+ *
13762
+ * The guild comes from a member or a message, else from a thread member's member or thread, and otherwise from
13763
+ * `guildId`. A message sent in a direct message belongs to no guild, so it resolves to `null` unless `guildId` is
13764
+ * given.
13765
+ *
13766
+ * @param presence The presence, something holding a user, or a user ID.
13767
+ * @param guildId The guild to look the presence up in, when the value carries none.
13768
+ * @returns The presence, or `null` if it is not cached or its guild is unknown.
13769
+ */
13770
+ resolve(presence, guildId) {
13771
+ if (presence instanceof Presence) return presence;
13772
+ const userId = this.resolveId(presence);
13773
+ const guild = this.guildOf(presence) ?? guildId ?? null;
13774
+ if (userId === null || guild === null) return null;
13775
+ return whenAll([this.cache.get(this.resolveKey(guild, userId))], ([cached]) => cached ?? null);
13776
+ }
13777
+ /**
13778
+ * Resolves a {@link PresenceResolvable} to a user ID.
13779
+ *
13780
+ * @remarks
13781
+ * This is the ID of the presence's user, like discord.js, and not the cache key {@link PresenceManager.resolveKey}
13782
+ * builds from a guild and a user.
13783
+ *
13784
+ * @param presence The presence, something holding a user, or a user ID.
13785
+ * @returns The user ID, or `null` if the value holds none.
13786
+ */
13787
+ resolveId(presence) {
13788
+ if (typeof presence === "string") return presence;
13789
+ if (presence instanceof Presence) return presence.userId;
13790
+ if (presence instanceof Message) return presence.author.id || null;
13791
+ return presence.id;
13792
+ }
13793
+ guildOf(presence) {
13794
+ if (presence instanceof GuildMember || presence instanceof Message) return presence.guildId;
13795
+ if (presence instanceof ThreadMember) return presence.guildMember?.guildId ?? presence.thread?.guildId ?? null;
13796
+ return null;
13797
+ }
13798
+ /**
13667
13799
  * Lists the cached presences of a guild.
13668
13800
  *
13669
13801
  * @param guildId The ID of the guild.
@@ -13784,94 +13916,6 @@ var ThreadManager = class extends CachedManager {
13784
13916
  }
13785
13917
  };
13786
13918
 
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
13919
  //#endregion
13876
13920
  //#region src/managers/ThreadMemberManager.ts
13877
13921
  /**