[Feature] Member search v2 (#2931)
* initial commit * tweak some things * a * Update JoinSourceType.cs * ill just hope it works * yup * docz
This commit is contained in:
@@ -1087,6 +1087,7 @@ namespace Discord
|
|||||||
/// be or has been removed from this guild.
|
/// be or has been removed from this guild.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null);
|
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null, IEnumerable<ulong> includeRoleIds = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a collection of users in this guild that the name or nickname starts with the
|
/// Gets a collection of users in this guild that the name or nickname starts with the
|
||||||
/// provided <see cref="string"/> at <paramref name="query"/>.
|
/// provided <see cref="string"/> at <paramref name="query"/>.
|
||||||
@@ -1104,6 +1105,11 @@ namespace Discord
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
Task<IReadOnlyCollection<IGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
|
Task<IReadOnlyCollection<IGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a collection of users in this guild that match the provided search criteria.
|
||||||
|
/// </summary>
|
||||||
|
Task<MemberSearchResult> SearchUsersAsyncV2(int limit = DiscordConfig.MaxUsersPerBatch, MemberSearchPropertiesV2 args = null, RequestOptions options = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the specified number of audit log entries for this guild.
|
/// Gets the specified number of audit log entries for this guild.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
47
src/Discord.Net.Core/Entities/Guilds/JoinSourceType.cs
Normal file
47
src/Discord.Net.Core/Entities/Guilds/JoinSourceType.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the source of a user joining a guild.
|
||||||
|
/// </summary>
|
||||||
|
public enum JoinSourceType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Unknown source.
|
||||||
|
/// </summary>
|
||||||
|
Unknown = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user was invited by a bot.
|
||||||
|
/// </summary>
|
||||||
|
BotInvite = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user was invited by an integration.
|
||||||
|
/// </summary>
|
||||||
|
Integration = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user joined via server discovery.
|
||||||
|
/// </summary>
|
||||||
|
ServerDiscovery = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user joined via the student hub.
|
||||||
|
/// </summary>
|
||||||
|
StudentHub = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user joined via an invite code.
|
||||||
|
/// </summary>
|
||||||
|
InviteCode = 5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user joined via a vanity URL.
|
||||||
|
/// </summary>
|
||||||
|
VanityUrl = 6,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The user was manually verified
|
||||||
|
/// </summary>
|
||||||
|
ManualVerification = 7
|
||||||
|
}
|
||||||
183
src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
Normal file
183
src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the properties for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public class MemberSearchPropertiesV2
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the after property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchPropertiesV2After After { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the sort type for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2SortType? Sort { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the and query for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2QueryParams? AndQuery { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the or query for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2QueryParams? OrQuery { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the after property for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public struct MemberSearchPropertiesV2After
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the user ID to search after.
|
||||||
|
/// </summary>
|
||||||
|
public ulong UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the guild joined at timestamp to search after.
|
||||||
|
/// </summary>
|
||||||
|
public long GuildJoinedAt { get; set; }
|
||||||
|
|
||||||
|
public MemberSearchPropertiesV2After(ulong userId, long guildJoinedAt)
|
||||||
|
{
|
||||||
|
UserId = userId;
|
||||||
|
GuildJoinedAt = guildJoinedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberSearchPropertiesV2After(ulong userId, DateTimeOffset guildJoinedAt)
|
||||||
|
{
|
||||||
|
UserId = userId;
|
||||||
|
GuildJoinedAt = guildJoinedAt.ToUnixTimeMilliseconds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the query parameters for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public struct MemberSearchV2QueryParams
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the safety signal search properties.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2SafetySignalsProperties? SafetySignals { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the role IDs to search for.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2QueryProperties? RoleIds { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the range to search for the user ID.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2RangeProperties? UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the range to search for the user's guild joined at timestamp.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2RangeProperties? GuildJoinedAt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the source invite code to search for.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2QueryProperties? SourceInviteCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the join source type to search for.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2QueryProperties? JoinSourceType { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the safety signal properties for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public struct MemberSearchV2SafetySignalsProperties
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the unusual DM activity until property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2SafetySignalProperties? UnusualDmActivityUntil { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the communication disabled until property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2SafetySignalProperties? CommunicationDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the unusual account activity property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public bool? UnusualAccountActivity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the automod quarantined username property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public bool? AutomodQuarantinedUsername { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the query properties for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public readonly struct MemberSearchV2QueryProperties
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the and query for the search.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<int, object> AndQuery { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the or query for the search.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<int, object> OrQuery { get; }
|
||||||
|
|
||||||
|
public MemberSearchV2QueryProperties(Dictionary<int, string> andQuery, Dictionary<int, string> orQuery)
|
||||||
|
{
|
||||||
|
AndQuery = andQuery.Select(x => new KeyValuePair<int, object>(x.Key, x.Value)).ToDictionary();
|
||||||
|
OrQuery = orQuery.Select(x => new KeyValuePair<int, object>(x.Key, x.Value)).ToDictionary();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberSearchV2QueryProperties(Dictionary<int, long> andQuery, Dictionary<int, long> orQuery)
|
||||||
|
{
|
||||||
|
AndQuery = andQuery.Select(x => new KeyValuePair<int, object>(x.Key, x.Value)).ToDictionary();
|
||||||
|
OrQuery = orQuery.Select(x => new KeyValuePair<int, object>(x.Key, x.Value)).ToDictionary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the safety signal properties for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public struct MemberSearchV2SafetySignalProperties
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the range for the search.
|
||||||
|
/// </summary>
|
||||||
|
public MemberSearchV2RangeProperties Range { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the range properties for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public struct MemberSearchV2RangeProperties
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the less than property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public long? LessThanOrEqual { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the greater than property for the search.
|
||||||
|
/// </summary>
|
||||||
|
public long? GreaterThanOrEqual { get; set; }
|
||||||
|
}
|
||||||
45
src/Discord.Net.Core/Entities/Guilds/MemberSearchResult.cs
Normal file
45
src/Discord.Net.Core/Entities/Guilds/MemberSearchResult.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
public struct MemberSearchResult
|
||||||
|
{
|
||||||
|
public ulong GuildId { get; }
|
||||||
|
|
||||||
|
public IReadOnlyCollection<MemberSearchData> Members { get; }
|
||||||
|
|
||||||
|
public int PageResultCount { get; }
|
||||||
|
|
||||||
|
public int TotalResultCount { get; }
|
||||||
|
|
||||||
|
public MemberSearchResult(ulong guildId, IReadOnlyCollection<MemberSearchData> members, int pageResultCount, int totalResultCount)
|
||||||
|
{
|
||||||
|
GuildId = guildId;
|
||||||
|
Members = members;
|
||||||
|
PageResultCount = pageResultCount;
|
||||||
|
TotalResultCount = totalResultCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||||
|
public readonly struct MemberSearchData
|
||||||
|
{
|
||||||
|
public IGuildUser User { get; }
|
||||||
|
|
||||||
|
public string SourceInviteCode { get; }
|
||||||
|
|
||||||
|
public JoinSourceType JoinSourceType { get; }
|
||||||
|
|
||||||
|
public ulong? InviterId { get; }
|
||||||
|
|
||||||
|
public MemberSearchData(IGuildUser user, string sourceInviteCode, JoinSourceType joinSourceType, ulong? inviterId)
|
||||||
|
{
|
||||||
|
User = user;
|
||||||
|
SourceInviteCode = sourceInviteCode;
|
||||||
|
JoinSourceType = joinSourceType;
|
||||||
|
InviterId = inviterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string DebuggerDisplay => $"{User.Username} ({User.Id})";
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
namespace Discord;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the sort type for searching members in a guild.
|
||||||
|
/// </summary>
|
||||||
|
public enum MemberSearchV2SortType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sort by member since newest first.
|
||||||
|
/// </summary>
|
||||||
|
MemberSinceNewestFirst = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sort by member since oldest first.
|
||||||
|
/// </summary>
|
||||||
|
MemberSinceOldestFirst = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sort by joined discord since newest first.
|
||||||
|
/// </summary>
|
||||||
|
JoinedDiscordNewestFirst = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sort by joined discord since oldest first.
|
||||||
|
/// </summary>
|
||||||
|
JoinedDiscordOldestFirst = 4,
|
||||||
|
}
|
||||||
18
src/Discord.Net.Rest/API/Common/GuildMemberSearchResponse.cs
Normal file
18
src/Discord.Net.Rest/API/Common/GuildMemberSearchResponse.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Discord.API;
|
||||||
|
|
||||||
|
internal class GuildMemberSearchResponse
|
||||||
|
{
|
||||||
|
[JsonProperty("guild_id")]
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("members")]
|
||||||
|
public GuildSearchMemberData[] Members { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("page_result_count")]
|
||||||
|
public int PageResultCount { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("total_result_count")]
|
||||||
|
public int TotalResultCount { get; set; }
|
||||||
|
}
|
||||||
18
src/Discord.Net.Rest/API/Common/GuildSearchMemberData.cs
Normal file
18
src/Discord.Net.Rest/API/Common/GuildSearchMemberData.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Discord.API;
|
||||||
|
|
||||||
|
internal class GuildSearchMemberData
|
||||||
|
{
|
||||||
|
[JsonProperty("member")]
|
||||||
|
public GuildMember Member { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("source_invite_code")]
|
||||||
|
public string InviteCode { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("join_source_type")]
|
||||||
|
public JoinSourceType JoinSourceType { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("inviter_id")]
|
||||||
|
public ulong? InviterId { get; set; }
|
||||||
|
}
|
||||||
91
src/Discord.Net.Rest/API/Rest/SearchGuildMembersParamsV2.cs
Normal file
91
src/Discord.Net.Rest/API/Rest/SearchGuildMembersParamsV2.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Discord.API.Rest;
|
||||||
|
|
||||||
|
internal class SearchGuildMembersParamsV2
|
||||||
|
{
|
||||||
|
[JsonProperty("limit")]
|
||||||
|
public Optional<int?> Limit { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("and_query")]
|
||||||
|
public Optional<SearchQueryParams> AndQuery { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("or_query")]
|
||||||
|
public Optional<SearchQueryParams> OrQuery { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("after")]
|
||||||
|
public Optional<SearchParamsAfter> After { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("sort")]
|
||||||
|
public Optional<MemberSearchV2SortType> Sort { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SearchParamsAfter
|
||||||
|
{
|
||||||
|
[JsonProperty("guild_joined_at")]
|
||||||
|
public long GuildJoinedAt { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("user_id")]
|
||||||
|
public ulong UserId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SearchQueryParams
|
||||||
|
{
|
||||||
|
[JsonProperty("safety_signals")]
|
||||||
|
public Optional<SafetySignalsProperties> SafetySignals { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("role_ids")]
|
||||||
|
public Optional<SearchQueryProperties> RoleIds { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("user_id")]
|
||||||
|
public Optional<SearchRangeProperties> UserId { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("guild_joined_at")]
|
||||||
|
public Optional<SearchRangeProperties> GuildJoinedAt { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("source_invite_code")]
|
||||||
|
public Optional<SearchQueryProperties> SourceInviteCode { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("join_source_type")]
|
||||||
|
public Optional<SearchQueryProperties> JoinSourceType { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SearchQueryProperties
|
||||||
|
{
|
||||||
|
[JsonProperty("and_query")]
|
||||||
|
public Optional<Dictionary<int, object>> AndQuery { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("or_query")]
|
||||||
|
public Optional<Dictionary<int, object>> OrQuery { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SafetySignalsProperties
|
||||||
|
{
|
||||||
|
[JsonProperty("unusual_dm_activity_until")]
|
||||||
|
public Optional<SafetySignalProperties> UnusualDMActivityUntil { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("communication_disabled_until")]
|
||||||
|
public Optional<SafetySignalProperties> CommunicationDisabledUntil { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("unusual_account_activity")]
|
||||||
|
public Optional<bool> UnusualAccountActivity { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("automod_quarantined_username")]
|
||||||
|
public Optional<bool> AutomodQuarantinedUsername { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SafetySignalProperties
|
||||||
|
{
|
||||||
|
[JsonProperty("range")]
|
||||||
|
public SearchRangeProperties Until { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SearchRangeProperties
|
||||||
|
{
|
||||||
|
[JsonProperty("gte")]
|
||||||
|
public Optional<long> GreaterThanOrEqual { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("lte")]
|
||||||
|
public Optional<long> LessThanOrEqual { get; set; }
|
||||||
|
}
|
||||||
@@ -2038,6 +2038,16 @@ namespace Discord.API
|
|||||||
Expression<Func<string>> endpoint = () => $"guilds/{guildId}/members/search?limit={limit}&query={query}";
|
Expression<Func<string>> endpoint = () => $"guilds/{guildId}/members/search?limit={limit}&query={query}";
|
||||||
return SendAsync<IReadOnlyCollection<GuildMember>>("GET", endpoint, ids, options: options);
|
return SendAsync<IReadOnlyCollection<GuildMember>>("GET", endpoint, ids, options: options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<GuildMemberSearchResponse> SearchGuildMembersAsyncV2(ulong guildId, SearchGuildMembersParamsV2 args, RequestOptions options = null)
|
||||||
|
{
|
||||||
|
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||||
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
|
var ids = new BucketIds(guildId: guildId);
|
||||||
|
return SendJsonAsync<GuildMemberSearchResponse>("POST", () => $"guilds/{guildId}/members-search", args, ids, options: options);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Guild Roles
|
#region Guild Roles
|
||||||
|
|||||||
@@ -763,6 +763,192 @@ namespace Discord.Rest
|
|||||||
var models = await client.ApiClient.SearchGuildMembersAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
var models = await client.ApiClient.SearchGuildMembersAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||||
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
|
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<MemberSearchResult> SearchUsersAsyncV2(IGuild guild, BaseDiscordClient client, int limit, MemberSearchPropertiesV2 args,
|
||||||
|
RequestOptions options)
|
||||||
|
{
|
||||||
|
var apiArgs = new SearchGuildMembersParamsV2
|
||||||
|
{
|
||||||
|
Limit = limit,
|
||||||
|
After = args is null
|
||||||
|
? null
|
||||||
|
: new SearchParamsAfter
|
||||||
|
{
|
||||||
|
UserId = args.After.UserId,
|
||||||
|
GuildJoinedAt = args.After.GuildJoinedAt
|
||||||
|
},
|
||||||
|
Sort = args?.Sort ?? Optional<MemberSearchV2SortType>.Unspecified,
|
||||||
|
OrQuery = args is null
|
||||||
|
? Optional<SearchQueryParams>.Unspecified
|
||||||
|
: args.OrQuery is null
|
||||||
|
? Optional<SearchQueryParams>.Unspecified
|
||||||
|
: new SearchQueryParams
|
||||||
|
{
|
||||||
|
GuildJoinedAt = args.OrQuery.Value.GuildJoinedAt is null
|
||||||
|
? Optional<SearchRangeProperties>.Unspecified
|
||||||
|
: new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.OrQuery.Value.GuildJoinedAt.Value.GreaterThanOrEqual is null
|
||||||
|
? Optional<long>.Unspecified
|
||||||
|
: args.OrQuery.Value.GuildJoinedAt.Value.GreaterThanOrEqual.Value,
|
||||||
|
LessThanOrEqual = args.OrQuery.Value.GuildJoinedAt.Value.LessThanOrEqual is null
|
||||||
|
? Optional<long>.Unspecified
|
||||||
|
: args.OrQuery.Value.GuildJoinedAt.Value.LessThanOrEqual.Value,
|
||||||
|
},
|
||||||
|
JoinSourceType = args.OrQuery.Value.JoinSourceType is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.OrQuery.Value.JoinSourceType.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.OrQuery.Value.JoinSourceType.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
RoleIds = args.OrQuery.Value.RoleIds is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.OrQuery.Value.RoleIds.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.OrQuery.Value.RoleIds.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
SourceInviteCode = args.OrQuery.Value.SourceInviteCode is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.OrQuery.Value.SourceInviteCode.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.OrQuery.Value.SourceInviteCode.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
SafetySignals = args.OrQuery.Value.SafetySignals is null
|
||||||
|
? Optional<SafetySignalsProperties>.Unspecified
|
||||||
|
: new SafetySignalsProperties
|
||||||
|
{
|
||||||
|
AutomodQuarantinedUsername = args.OrQuery.Value.SafetySignals.Value.AutomodQuarantinedUsername is null
|
||||||
|
? Optional<bool>.Unspecified
|
||||||
|
: args.OrQuery.Value.SafetySignals.Value.AutomodQuarantinedUsername.Value,
|
||||||
|
UnusualAccountActivity = args.OrQuery.Value.SafetySignals.Value.UnusualAccountActivity is null
|
||||||
|
? Optional<bool>.Unspecified
|
||||||
|
: args.OrQuery.Value.SafetySignals.Value.UnusualAccountActivity.Value,
|
||||||
|
CommunicationDisabledUntil = args.OrQuery.Value.SafetySignals.Value.CommunicationDisabledUntil is null
|
||||||
|
? Optional<SafetySignalProperties>.Unspecified
|
||||||
|
: new SafetySignalProperties
|
||||||
|
{
|
||||||
|
Until = new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.OrQuery.Value.SafetySignals.Value.CommunicationDisabledUntil.Value.Range.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
LessThanOrEqual = args.OrQuery.Value.SafetySignals.Value.CommunicationDisabledUntil.Value.Range.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
UnusualDMActivityUntil = args.OrQuery.Value.SafetySignals.Value.UnusualDmActivityUntil is null
|
||||||
|
? Optional<SafetySignalProperties>.Unspecified
|
||||||
|
: new SafetySignalProperties
|
||||||
|
{
|
||||||
|
Until = new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.OrQuery.Value.SafetySignals.Value.UnusualDmActivityUntil.Value.Range.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
LessThanOrEqual = args.OrQuery.Value.SafetySignals.Value.UnusualDmActivityUntil.Value.Range.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
UserId = args.OrQuery.Value.UserId is null
|
||||||
|
? Optional<SearchRangeProperties>.Unspecified
|
||||||
|
: new SearchRangeProperties
|
||||||
|
{
|
||||||
|
LessThanOrEqual = args.OrQuery.Value.UserId.Value.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
GreaterThanOrEqual = args.OrQuery.Value.UserId.Value.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AndQuery = args is null
|
||||||
|
? Optional<SearchQueryParams>.Unspecified
|
||||||
|
: args.AndQuery is null
|
||||||
|
? Optional<SearchQueryParams>.Unspecified
|
||||||
|
: new SearchQueryParams
|
||||||
|
{
|
||||||
|
GuildJoinedAt = args.AndQuery.Value.GuildJoinedAt is null
|
||||||
|
? Optional<SearchRangeProperties>.Unspecified
|
||||||
|
: new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.AndQuery.Value.GuildJoinedAt.Value.GreaterThanOrEqual is null
|
||||||
|
? Optional<long>.Unspecified
|
||||||
|
: args.AndQuery.Value.GuildJoinedAt.Value.GreaterThanOrEqual.Value,
|
||||||
|
LessThanOrEqual = args.AndQuery.Value.GuildJoinedAt.Value.LessThanOrEqual is null
|
||||||
|
? Optional<long>.Unspecified
|
||||||
|
: args.AndQuery.Value.GuildJoinedAt.Value.LessThanOrEqual.Value,
|
||||||
|
},
|
||||||
|
JoinSourceType = args.AndQuery.Value.JoinSourceType is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.AndQuery.Value.JoinSourceType.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.AndQuery.Value.JoinSourceType.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
RoleIds = args.AndQuery.Value.RoleIds is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.AndQuery.Value.RoleIds.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.AndQuery.Value.RoleIds.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
SourceInviteCode = args.AndQuery.Value.SourceInviteCode is null
|
||||||
|
? Optional<SearchQueryProperties>.Unspecified
|
||||||
|
: new SearchQueryProperties
|
||||||
|
{
|
||||||
|
AndQuery = args.AndQuery.Value.SourceInviteCode.Value.AndQuery ?? Optional<Dictionary<int, object>>.Unspecified,
|
||||||
|
OrQuery = args.AndQuery.Value.SourceInviteCode.Value.OrQuery ?? Optional<Dictionary<int, object>>.Unspecified
|
||||||
|
},
|
||||||
|
SafetySignals = args.AndQuery.Value.SafetySignals is null
|
||||||
|
? Optional<SafetySignalsProperties>.Unspecified
|
||||||
|
: new SafetySignalsProperties
|
||||||
|
{
|
||||||
|
AutomodQuarantinedUsername = args.AndQuery.Value.SafetySignals.Value.AutomodQuarantinedUsername is null
|
||||||
|
? Optional<bool>.Unspecified
|
||||||
|
: args.AndQuery.Value.SafetySignals.Value.AutomodQuarantinedUsername.Value,
|
||||||
|
UnusualAccountActivity = args.AndQuery.Value.SafetySignals.Value.UnusualAccountActivity is null
|
||||||
|
? Optional<bool>.Unspecified
|
||||||
|
: args.AndQuery.Value.SafetySignals.Value.UnusualAccountActivity.Value,
|
||||||
|
CommunicationDisabledUntil = args.AndQuery.Value.SafetySignals.Value.CommunicationDisabledUntil is null
|
||||||
|
? Optional<SafetySignalProperties>.Unspecified
|
||||||
|
: new SafetySignalProperties
|
||||||
|
{
|
||||||
|
Until = new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.AndQuery.Value.SafetySignals.Value.CommunicationDisabledUntil.Value.Range.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
LessThanOrEqual = args.AndQuery.Value.SafetySignals.Value.CommunicationDisabledUntil.Value.Range.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
UnusualDMActivityUntil = args.AndQuery.Value.SafetySignals.Value.UnusualDmActivityUntil is null
|
||||||
|
? Optional<SafetySignalProperties>.Unspecified
|
||||||
|
: new SafetySignalProperties
|
||||||
|
{
|
||||||
|
Until = new SearchRangeProperties
|
||||||
|
{
|
||||||
|
GreaterThanOrEqual = args.AndQuery.Value.SafetySignals.Value.UnusualDmActivityUntil.Value.Range.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
LessThanOrEqual = args.AndQuery.Value.SafetySignals.Value.UnusualDmActivityUntil.Value.Range.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
UserId = args.AndQuery.Value.UserId is null
|
||||||
|
? Optional<SearchRangeProperties>.Unspecified
|
||||||
|
: new SearchRangeProperties
|
||||||
|
{
|
||||||
|
LessThanOrEqual = args.AndQuery.Value.UserId.Value.LessThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
GreaterThanOrEqual = args.AndQuery.Value.UserId.Value.GreaterThanOrEqual ?? Optional<long>.Unspecified,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var model = await client.ApiClient.SearchGuildMembersAsyncV2(guild.Id, apiArgs, options);
|
||||||
|
|
||||||
|
return new MemberSearchResult(
|
||||||
|
model.GuildId,
|
||||||
|
model.Members.Select(x =>
|
||||||
|
new MemberSearchData(
|
||||||
|
RestGuildUser.Create(client, guild, x.Member),
|
||||||
|
x.InviteCode,
|
||||||
|
x.JoinSourceType,
|
||||||
|
x.InviterId)
|
||||||
|
).ToImmutableArray(),
|
||||||
|
model.PageResultCount,
|
||||||
|
model.TotalResultCount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Audit logs
|
#region Audit logs
|
||||||
|
|||||||
@@ -983,6 +983,10 @@ namespace Discord.Rest
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<IReadOnlyCollection<RestGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null)
|
public Task<IReadOnlyCollection<RestGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null)
|
||||||
=> GuildHelper.SearchUsersAsync(this, Discord, query, limit, options);
|
=> GuildHelper.SearchUsersAsync(this, Discord, query, limit, options);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<MemberSearchResult> SearchUsersAsyncV2(int limit = DiscordConfig.MaxUsersPerBatch, MemberSearchPropertiesV2 args = null, RequestOptions options = null)
|
||||||
|
=> GuildHelper.SearchUsersAsyncV2(this, Discord, limit, args, options);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Audit logs
|
#region Audit logs
|
||||||
|
|||||||
@@ -1336,6 +1336,10 @@ namespace Discord.WebSocket
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public Task<IReadOnlyCollection<RestGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null)
|
public Task<IReadOnlyCollection<RestGuildUser>> SearchUsersAsync(string query, int limit = DiscordConfig.MaxUsersPerBatch, RequestOptions options = null)
|
||||||
=> GuildHelper.SearchUsersAsync(this, Discord, query, limit, options);
|
=> GuildHelper.SearchUsersAsync(this, Discord, query, limit, options);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<MemberSearchResult> SearchUsersAsyncV2(int limit = DiscordConfig.MaxUsersPerBatch, MemberSearchPropertiesV2 args = null, RequestOptions options = null)
|
||||||
|
=> GuildHelper.SearchUsersAsyncV2(this, Discord, limit, args, options);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Guild Events
|
#region Guild Events
|
||||||
|
|||||||
Reference in New Issue
Block a user