Skip to content

Commit

Permalink
ill just hope it works
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 committed Jun 30, 2024
1 parent 48b0d9a commit 8b0973a
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ public interface IGuild : IDeletable, ISnowflakeEntity
/// </returns>
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>
Expand Down
29 changes: 29 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/JoinSourceType.cs
Original file line number Diff line number Diff line change
@@ -1,18 +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
}
114 changes: 112 additions & 2 deletions src/Discord.Net.Core/Entities/Guilds/MemberSearchPropertiesV2.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,129 @@
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>
///
/// </summary>
public MemberSearchV2QueryParams? AndQuery { get; set; }

/// <summary>
///
/// </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; }

public ulong GuildJoinedAt { get; set; }
/// <summary>
/// Gets or sets the guild joined at timestamp to search after.
/// </summary>
public long GuildJoinedAt { get; set; }

public MemberSearchPropertiesV2After(ulong userId, ulong guildJoinedAt)
public MemberSearchPropertiesV2After(ulong userId, long guildJoinedAt)
{
UserId = userId;
GuildJoinedAt = guildJoinedAt;
}

public MemberSearchPropertiesV2After(ulong userId, DateTimeOffset guildJoinedAt)
{
UserId = userId;
GuildJoinedAt = guildJoinedAt.ToUnixTimeMilliseconds();
}
}

public struct MemberSearchV2QueryParams
{
public MemberSearchV2SafetySignalsProperties? SafetySignals { get; set; }

public MemberSearchV2QueryProperties? RoleIds { get; set; }

public MemberSearchV2RangeProperties? UserId { get; set; }

public MemberSearchV2RangeProperties? GuildJoinedAt { get; set; }

public MemberSearchV2QueryProperties? SourceInviteCode { get; set; }

public MemberSearchV2QueryProperties? JoinSourceType { get; set; }
}

public struct MemberSearchV2SafetySignalsProperties
{
public MemberSearchV2SafetySignalProperties? UnusualDmActivityUntil { get; set; }

public MemberSearchV2SafetySignalProperties? CommunicationDisabledUntil { get; set; }

public bool? UnusualAccountActivity { get; set; }

public bool? AutomodQuarantinedUsername { get; set; }
}

public readonly struct MemberSearchV2QueryProperties
{
public Dictionary<int, object> AndQuery { get; }

public Dictionary<int, object> OrQuery { get; }

public MemberSearchV2QueryProperties(Dictionary<int, object> andQuery, Dictionary<int, object> orQuery)
{
AndQuery = andQuery;
OrQuery = orQuery;
}

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();
}
}

public struct MemberSearchV2SafetySignalProperties
{
public MemberSearchV2RangeProperties Range { get; set; }
}

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; }
}
27 changes: 27 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/MemberSearchV2SortType.cs
Original file line number Diff line number Diff line change
@@ -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,
}
71 changes: 67 additions & 4 deletions src/Discord.Net.Rest/API/Rest/SearchGuildMembersParamsV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,83 @@ internal class SearchGuildMembersParamsV2
public Optional<int?> Limit { get; set; }

[JsonProperty("and_query")]
public Dictionary<string, string[]> AndQuery { get; set; }
public Optional<SearchQueryParams> AndQuery { get; set; }

[JsonProperty("or_query")]
public Dictionary<string, string[]> OrQuery { get; set; }
public Optional<SearchQueryParams> OrQuery { get; set; }

[JsonProperty("after")]
public SearchParamsAfter After { get; set; }
public Optional<SearchParamsAfter> After { get; set; }

[JsonProperty("sort")]
public Optional<MemberSearchV2SortType> Sort { get; set; }
}

internal class SearchParamsAfter
{
[JsonProperty("guild_joined_at")]
public ulong GuildJoinedAt { get; set; }
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; }
}
Loading

0 comments on commit 8b0973a

Please sign in to comment.