From 36439b6325e90c0246c929805288517d5c898115 Mon Sep 17 00:00:00 2001
From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
Date: Wed, 8 Jan 2025 00:37:41 +0300
Subject: [PATCH] Refactor & update member search v2 (#3046)
---
.../Guilds/MemberSearchPropertiesV2.cs | 187 ++++++++++++------
.../API/Common/GuildMemberSearchResponse.cs | 2 +-
...MemberData.cs => SupplementalGuildUser.cs} | 2 +-
.../API/Rest/SearchGuildMembersParamsV2.cs | 43 ++--
src/Discord.Net.Rest/DiscordRestApiClient.cs | 6 +-
.../Entities/Guilds/GuildHelper.cs | 158 +--------------
.../Extensions/MemberSearchExtensions.cs | 43 ++++
7 files changed, 208 insertions(+), 233 deletions(-)
rename src/Discord.Net.Rest/API/Common/{GuildSearchMemberData.cs => SupplementalGuildUser.cs} (91%)
create mode 100644 src/Discord.Net.Rest/Extensions/MemberSearchExtensions.cs
diff --git a/src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs b/src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
index 476f3a82..c42578e9 100644
--- a/src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
+++ b/src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
@@ -13,7 +13,12 @@ public class MemberSearchPropertiesV2
///
/// Gets or sets the after property for the search.
///
- public MemberSearchPropertiesV2After After { get; set; }
+ public MemberSearchPaginationFilter After { get; set; }
+
+ ///
+ /// Gets or sets the before property for the search.
+ ///
+ public MemberSearchPaginationFilter Before { get; set; }
///
/// Gets or sets the sort type for the search.
@@ -23,19 +28,19 @@ public class MemberSearchPropertiesV2
///
/// Gets or sets the and query for the search.
///
- public MemberSearchV2QueryParams? AndQuery { get; set; }
+ public MemberSearchFilter? AndQuery { get; set; }
///
/// Gets or sets the or query for the search.
///
- public MemberSearchV2QueryParams? OrQuery { get; set; }
+ public MemberSearchFilter? OrQuery { get; set; }
}
///
/// Represents the after property for searching members in a guild.
///
-public struct MemberSearchPropertiesV2After
+public struct MemberSearchPaginationFilter
{
///
/// Gets or sets the user ID to search after.
@@ -47,24 +52,26 @@ public struct MemberSearchPropertiesV2After
///
public long GuildJoinedAt { get; set; }
- public MemberSearchPropertiesV2After(ulong userId, long guildJoinedAt)
+ public MemberSearchPaginationFilter(ulong userId, long guildJoinedAt)
{
UserId = userId;
GuildJoinedAt = guildJoinedAt;
}
- public MemberSearchPropertiesV2After(ulong userId, DateTimeOffset guildJoinedAt)
+ public MemberSearchPaginationFilter(ulong userId, DateTimeOffset guildJoinedAt)
{
UserId = userId;
GuildJoinedAt = guildJoinedAt.ToUnixTimeMilliseconds();
}
+
+ public MemberSearchPaginationFilter() { }
}
///
/// Represents the query parameters for searching members in a guild.
///
-public struct MemberSearchV2QueryParams
+public struct MemberSearchFilter
{
///
/// Gets or sets the safety signal search properties.
@@ -74,27 +81,60 @@ public struct MemberSearchV2QueryParams
///
/// Gets or sets the role IDs to search for.
///
- public MemberSearchV2QueryProperties? RoleIds { get; set; }
+ ///
+ /// Only and are supported.
+ ///
+ public MemberSearchSnowflakeQuery? RoleIds { get; set; }
///
/// Gets or sets the range to search for the user ID.
///
- public MemberSearchV2RangeProperties? UserId { get; set; }
+ ///
+ /// Only and are supported.
+ ///
+ public MemberSearchSnowflakeQuery? UserId { get; set; }
///
/// Gets or sets the range to search for the user's guild joined at timestamp.
///
- public MemberSearchV2RangeProperties? GuildJoinedAt { get; set; }
+ ///
+ /// Only is supported.
+ ///
+ public MemberSearchIntQuery? GuildJoinedAt { get; set; }
///
/// Gets or sets the source invite code to search for.
///
- public MemberSearchV2QueryProperties? SourceInviteCode { get; set; }
+ ///
+ /// Only is supported.
+ ///
+ public MemberSearchStringQuery? SourceInviteCode { get; set; }
///
/// Gets or sets the join source type to search for.
///
- public MemberSearchV2QueryProperties? JoinSourceType { get; set; }
+ ///
+ /// Only is supported.
+ ///
+ public MemberSearchIntQuery? JoinSourceType { get; set; }
+
+ ///
+ /// Gets or sets whether the member left and rejoined the guild.
+ ///
+ public bool? DidRejoin { get; set; }
+
+ ///
+ /// Gets or sets whether the member has not yet passed the guild's member verification requirements.
+ ///
+ public bool? IsPending { get; set; }
+
+ ///
+ /// Gets or sets the usernames to match against.
+ ///
+ ///
+ /// Only is supported.
+ ///
+ public MemberSearchStringQuery? Usernames { get; set; }
}
@@ -106,12 +146,12 @@ public struct MemberSearchV2SafetySignalsProperties
///
/// Gets or sets the unusual DM activity until property for the search.
///
- public MemberSearchV2SafetySignalProperties? UnusualDmActivityUntil { get; set; }
+ public MemberSearchIntQuery? UnusualDmActivityUntil { get; set; }
///
/// Gets or sets the communication disabled until property for the search.
///
- public MemberSearchV2SafetySignalProperties? CommunicationDisabledUntil { get; set; }
+ public MemberSearchIntQuery? CommunicationDisabledUntil { get; set; }
///
/// Gets or sets the unusual account activity property for the search.
@@ -124,52 +164,10 @@ public struct MemberSearchV2SafetySignalsProperties
public bool? AutomodQuarantinedUsername { get; set; }
}
-
-///
-/// Represents the query properties for searching members in a guild.
-///
-public readonly struct MemberSearchV2QueryProperties
-{
- ///
- /// Gets the and query for the search.
- ///
- public Dictionary AndQuery { get; }
-
- ///
- /// Gets the or query for the search.
- ///
- public Dictionary OrQuery { get; }
-
- public MemberSearchV2QueryProperties(Dictionary andQuery, Dictionary orQuery)
- {
- AndQuery = andQuery.Select(x => new KeyValuePair(x.Key, x.Value)).ToDictionary(x => x.Key, y => y.Value);
- OrQuery = orQuery.Select(x => new KeyValuePair(x.Key, x.Value)).ToDictionary(x => x.Key, y => y.Value);
- }
-
- public MemberSearchV2QueryProperties(Dictionary andQuery, Dictionary orQuery)
- {
- AndQuery = andQuery.Select(x => new KeyValuePair(x.Key, x.Value)).ToDictionary(x => x.Key, y => y.Value);
- OrQuery = orQuery.Select(x => new KeyValuePair(x.Key, x.Value)).ToDictionary(x => x.Key, y => y.Value);
- }
-}
-
-
-///
-/// Represents the safety signal properties for searching members in a guild.
-///
-public struct MemberSearchV2SafetySignalProperties
-{
- ///
- /// Gets or sets the range for the search.
- ///
- public MemberSearchV2RangeProperties Range { get; set; }
-}
-
-
///
/// Represents the range properties for searching members in a guild.
///
-public struct MemberSearchV2RangeProperties
+public struct MemberSearchV2Range
{
///
/// Gets or sets the less than property for the search.
@@ -181,3 +179,78 @@ public struct MemberSearchV2RangeProperties
///
public long? GreaterThanOrEqual { get; set; }
}
+
+
+public interface IMemberSearchQuery
+{
+ ///
+ /// Gets or sets the range for the search.
+ ///
+ MemberSearchV2Range? Range { get; }
+
+ ///
+ /// Gets the AND query for the search.
+ ///
+ IEnumerable