From a1745d1e06ed8208059a49209aa42edd10cb7382 Mon Sep 17 00:00:00 2001 From: Zane Pereira Date: Thu, 21 Dec 2023 21:00:57 +0530 Subject: [PATCH] Various small API updates (#107) * Update default avatar calculation for migrated users * Add new auto moderation trigger metadata field: mention_raid_protection_enabled * Add new guild field: safety_alerts_channel_id * Add new permissions: CREATE_GUILD_EXPRESSIONS, CREATE_EVENTS * Add new field to LocalActivity for custom statuses: state * Add new field to ApplicationTeamMember: role * Changes * Update default param value --- src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs | 2 +- .../Application/IApplicationTeamMember.cs | 7 ++++- .../Guild/Data/IGuildAuditLogChanges.cs | 2 ++ .../IAutoModerationTriggerMetadata.cs | 8 +++++ .../Entities/Core/Guild/IGuild.cs | 5 ++++ ...AutoModerationTriggerMetadataExtensions.cs | 6 ++++ .../LocalAutoModerationTriggerMetadata.cs | 6 +++- .../TransientApplicationTeamMember.cs | 5 +++- .../Data/TransientGuildAuditLogChanges.cs | 8 +++++ .../TransientAutoModerationTriggerMetadata.cs | 3 ++ .../Transient/Guild/TransientGuild.cs | 3 ++ src/Disqord.Core/Enums/Permissions.cs | 16 ++++++++-- src/Disqord.Core/Enums/TeamMemberRole.cs | 29 +++++++++++++++++++ .../Models/Application/TeamMemberJsonModel.cs | 5 +++- .../AutoModerationTriggerMetadataJsonModel.cs | 3 ++ src/Disqord.Core/Models/GuildJsonModel.cs | 3 ++ .../Entities/Cached/CachedGuild.cs | 4 +++ .../Entities/Local/LocalActivity.cs | 14 +++++++-- .../Transient/Guild/TransientGatewayGuild.cs | 2 ++ .../Json/ModifyGuildJsonRestRequestContent.cs | 5 +++- .../Modify/ModifyGuildActionProperties.cs | 4 ++- .../Extensions/RestClientExtensions.Guild.cs | 3 +- 22 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 src/Disqord.Core/Enums/TeamMemberRole.cs diff --git a/src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs b/src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs index 1cb46a396..9aae54f9a 100644 --- a/src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs +++ b/src/Disqord.Core/Discord/Cdn/Discord.Cdn.cs @@ -61,7 +61,7 @@ public static string GetDefaultAvatarUrl(string discriminator) public static string GetDefaultAvatarUrl(Snowflake userId) { - return GetDefaultAvatarUrl((DefaultAvatarColor) ((userId.RawValue >> 22) % 5)); + return GetDefaultAvatarUrl((DefaultAvatarColor) ((userId.RawValue >> 22) % 6)); } public static string GetDefaultAvatarUrl(DefaultAvatarColor color) diff --git a/src/Disqord.Core/Entities/Core/Application/IApplicationTeamMember.cs b/src/Disqord.Core/Entities/Core/Application/IApplicationTeamMember.cs index d8f81bc92..eac013c5e 100644 --- a/src/Disqord.Core/Entities/Core/Application/IApplicationTeamMember.cs +++ b/src/Disqord.Core/Entities/Core/Application/IApplicationTeamMember.cs @@ -22,4 +22,9 @@ public interface IApplicationTeamMember : IUser, IJsonUpdatable IReadOnlyList Permissions { get; } -} \ No newline at end of file + + /// + /// Gets the role of this member. + /// + TeamMemberRole Role { get; } +} diff --git a/src/Disqord.Core/Entities/Core/AuditLogs/Guild/Data/IGuildAuditLogChanges.cs b/src/Disqord.Core/Entities/Core/AuditLogs/Guild/Data/IGuildAuditLogChanges.cs index dd3b30209..78087ed6a 100644 --- a/src/Disqord.Core/Entities/Core/AuditLogs/Guild/Data/IGuildAuditLogChanges.cs +++ b/src/Disqord.Core/Entities/Core/AuditLogs/Guild/Data/IGuildAuditLogChanges.cs @@ -48,4 +48,6 @@ public interface IGuildAuditLogChanges AuditLogChange WidgetChannelId { get; } AuditLogChange SystemChannelId { get; } + + AuditLogChange SafetyAlertsChannelId { get; } } diff --git a/src/Disqord.Core/Entities/Core/AutoModeration/IAutoModerationTriggerMetadata.cs b/src/Disqord.Core/Entities/Core/AutoModeration/IAutoModerationTriggerMetadata.cs index 1919e87d6..b14f2f25b 100644 --- a/src/Disqord.Core/Entities/Core/AutoModeration/IAutoModerationTriggerMetadata.cs +++ b/src/Disqord.Core/Entities/Core/AutoModeration/IAutoModerationTriggerMetadata.cs @@ -47,4 +47,12 @@ public interface IAutoModerationTriggerMetadata : IEntity, IJsonUpdatable trigger type. /// int? MentionLimit { get; } + + /// + /// Gets whether mention raids should be automatically detected. + /// + /// + /// Used by the trigger type. + /// + bool IsMentionRaidProtectionEnabled { get; } } diff --git a/src/Disqord.Core/Entities/Core/Guild/IGuild.cs b/src/Disqord.Core/Entities/Core/Guild/IGuild.cs index 68f82609d..7b7fc5ab4 100644 --- a/src/Disqord.Core/Entities/Core/Guild/IGuild.cs +++ b/src/Disqord.Core/Entities/Core/Guild/IGuild.cs @@ -173,4 +173,9 @@ public interface IGuild : ISnowflakeEntity, INamableEntity, IJsonUpdatable bool IsBoostProgressBarEnabled { get; } + + /// + /// Gets the safety alerts channel ID of this guild. + /// + Snowflake? SafetyAlertsChannelId { get; } } diff --git a/src/Disqord.Core/Entities/Local/AutoModeration/Extensions/LocalAutoModerationTriggerMetadataExtensions.cs b/src/Disqord.Core/Entities/Local/AutoModeration/Extensions/LocalAutoModerationTriggerMetadataExtensions.cs index 57cc98988..4b79491fa 100644 --- a/src/Disqord.Core/Entities/Local/AutoModeration/Extensions/LocalAutoModerationTriggerMetadataExtensions.cs +++ b/src/Disqord.Core/Entities/Local/AutoModeration/Extensions/LocalAutoModerationTriggerMetadataExtensions.cs @@ -110,4 +110,10 @@ public static LocalAutoModerationTriggerMetadata WithMentionLimit(this LocalAuto metadata.MentionLimit = mentionLimit; return metadata; } + + public static LocalAutoModerationTriggerMetadata WithIsMentionRaidProtectionEnabled(this LocalAutoModerationTriggerMetadata metadata, bool isEnabled = true) + { + metadata.IsMentionRaidProtectionEnabled = isEnabled; + return metadata; + } } diff --git a/src/Disqord.Core/Entities/Local/AutoModeration/LocalAutoModerationTriggerMetadata.cs b/src/Disqord.Core/Entities/Local/AutoModeration/LocalAutoModerationTriggerMetadata.cs index 3464d110f..f1ed51bda 100644 --- a/src/Disqord.Core/Entities/Local/AutoModeration/LocalAutoModerationTriggerMetadata.cs +++ b/src/Disqord.Core/Entities/Local/AutoModeration/LocalAutoModerationTriggerMetadata.cs @@ -16,6 +16,8 @@ public class LocalAutoModerationTriggerMetadata : ILocalConstruct MentionLimit { get; set; } + public Optional IsMentionRaidProtectionEnabled { get; set; } + /// /// Instantiates a new . /// @@ -33,6 +35,7 @@ protected LocalAutoModerationTriggerMetadata(LocalAutoModerationTriggerMetadata Presets = other.Presets.Clone(); AllowedSubstrings = other.AllowedSubstrings.Clone(); MentionLimit = other.MentionLimit; + IsMentionRaidProtectionEnabled = other.IsMentionRaidProtectionEnabled; } /// @@ -50,7 +53,8 @@ public AutoModerationTriggerMetadataJsonModel ToModel() RegexPatterns = RegexPatterns.ToArray(), Presets = Presets.ToArray(), AllowList = AllowedSubstrings.ToArray(), - MentionTotalLimit = MentionLimit + MentionTotalLimit = MentionLimit, + MentionRaidProtectionEnabled = IsMentionRaidProtectionEnabled }; } } diff --git a/src/Disqord.Core/Entities/Transient/Application/TransientApplicationTeamMember.cs b/src/Disqord.Core/Entities/Transient/Application/TransientApplicationTeamMember.cs index 0e38413a4..1535a0c49 100644 --- a/src/Disqord.Core/Entities/Transient/Application/TransientApplicationTeamMember.cs +++ b/src/Disqord.Core/Entities/Transient/Application/TransientApplicationTeamMember.cs @@ -15,6 +15,9 @@ public class TransientApplicationTeamMember : TransientUser, IApplicationTeamMem /// public IReadOnlyList Permissions => Model.Permissions; + /// + public TeamMemberRole Role => Model.Role; + /// public new TeamMemberJsonModel Model { get; } @@ -23,4 +26,4 @@ public TransientApplicationTeamMember(IClient client, TeamMemberJsonModel model) { Model = model; } -} \ No newline at end of file +} diff --git a/src/Disqord.Core/Entities/Transient/AuditLogs/Guild/Data/TransientGuildAuditLogChanges.cs b/src/Disqord.Core/Entities/Transient/AuditLogs/Guild/Data/TransientGuildAuditLogChanges.cs index df6178ba0..4344a2fbe 100644 --- a/src/Disqord.Core/Entities/Transient/AuditLogs/Guild/Data/TransientGuildAuditLogChanges.cs +++ b/src/Disqord.Core/Entities/Transient/AuditLogs/Guild/Data/TransientGuildAuditLogChanges.cs @@ -74,6 +74,9 @@ public class TransientGuildAuditLogChanges : IGuildAuditLogChanges /// public AuditLogChange SystemChannelId { get; } + /// + public AuditLogChange SafetyAlertsChannelId { get; } + public TransientGuildAuditLogChanges(IClient client, AuditLogJsonModel? auditLogJsonModel, AuditLogEntryJsonModel model) { for (var i = 0; i < model.Changes.Value.Length; i++) @@ -200,6 +203,11 @@ public TransientGuildAuditLogChanges(IClient client, AuditLogJsonModel? auditLog SystemChannelId = AuditLogChange.Convert(change); break; } + case "safety_alerts_channel_id": + { + SafetyAlertsChannelId = AuditLogChange.Convert(change); + break; + } default: { client.Logger.LogDebug("Unknown key {0} for {1}", change.Key, this); diff --git a/src/Disqord.Core/Entities/Transient/AutoModeration/TransientAutoModerationTriggerMetadata.cs b/src/Disqord.Core/Entities/Transient/AutoModeration/TransientAutoModerationTriggerMetadata.cs index a6e87bbc9..d51f48a5f 100644 --- a/src/Disqord.Core/Entities/Transient/AutoModeration/TransientAutoModerationTriggerMetadata.cs +++ b/src/Disqord.Core/Entities/Transient/AutoModeration/TransientAutoModerationTriggerMetadata.cs @@ -63,6 +63,9 @@ public IReadOnlyList AllowedSubstrings /// public int? MentionLimit => Model.MentionTotalLimit.GetValueOrNullable(); + /// + public bool IsMentionRaidProtectionEnabled => Model.MentionRaidProtectionEnabled.GetValueOrDefault(); + public TransientAutoModerationTriggerMetadata(AutoModerationTriggerMetadataJsonModel model) : base(model) { } diff --git a/src/Disqord.Core/Entities/Transient/Guild/TransientGuild.cs b/src/Disqord.Core/Entities/Transient/Guild/TransientGuild.cs index 21f6d2e01..dcb492c43 100644 --- a/src/Disqord.Core/Entities/Transient/Guild/TransientGuild.cs +++ b/src/Disqord.Core/Entities/Transient/Guild/TransientGuild.cs @@ -140,6 +140,9 @@ public IReadOnlyDictionary Stickers /// public bool IsBoostProgressBarEnabled => Model.PremiumProgressBarEnabled; + /// + public Snowflake? SafetyAlertsChannelId => Model.SafetyAlertsChannelId; + public TransientGuild(IClient client, GuildJsonModel model) : base(client, model) { } diff --git a/src/Disqord.Core/Enums/Permissions.cs b/src/Disqord.Core/Enums/Permissions.cs index 7724ff7b2..35e412a3c 100644 --- a/src/Disqord.Core/Enums/Permissions.cs +++ b/src/Disqord.Core/Enums/Permissions.cs @@ -167,7 +167,7 @@ public enum Permissions : ulong ManageWebhooks = 1ul << 29, /// - /// Allows management of emojis, stickers, soundboard sounds etc. + /// Allows management of emojis, stickers, soundboard sounds, etc. /// ManageExpressions = 1ul << 30, @@ -241,6 +241,16 @@ public enum Permissions : ulong /// UseSoundboard = 1ul << 42, + /// + /// Allows creating emojis, stickers, soundboard sounds, etc. + /// + CreateExpressions = 1ul << 43, + + /// + /// Allows creating guild events. + /// + CreateEvents = 1ul << 44, + /// /// Allows using sounds from other guilds. /// @@ -267,6 +277,6 @@ public enum Permissions : ulong | ManageRoles | ManageWebhooks | ManageExpressions | UseApplicationCommands | RequestToSpeak | ManageEvents | ManageThreads | CreatePublicThreads | CreatePrivateThreads | UseExternalStickers | SendMessagesInThreads | StartActivities - | ModerateMembers | ViewCreatorMonetizationAnalytics | UseSoundboard | UseExternalSounds - | SendVoiceMessages + | ModerateMembers | ViewCreatorMonetizationAnalytics | UseSoundboard | CreateExpressions + | CreateEvents | UseExternalSounds | SendVoiceMessages } diff --git a/src/Disqord.Core/Enums/TeamMemberRole.cs b/src/Disqord.Core/Enums/TeamMemberRole.cs new file mode 100644 index 000000000..721938cd4 --- /dev/null +++ b/src/Disqord.Core/Enums/TeamMemberRole.cs @@ -0,0 +1,29 @@ +using System.Runtime.Serialization; +using Disqord.Serialization.Json; + +namespace Disqord; + +/// +/// Represents the role of team member in an application team. +/// +[StringEnum] +public enum TeamMemberRole +{ + /// + /// Represents a team administrator. + /// + [EnumMember(Value = "admin")] + Administrator, + + /// + /// Represents a team developer. + /// + [EnumMember(Value = "developer")] + Developer, + + /// + /// Represents a team member with read-only access. + /// + [EnumMember(Value = "read_only")] + ReadOnly +} diff --git a/src/Disqord.Core/Models/Application/TeamMemberJsonModel.cs b/src/Disqord.Core/Models/Application/TeamMemberJsonModel.cs index a1632674b..2bc7ae93a 100644 --- a/src/Disqord.Core/Models/Application/TeamMemberJsonModel.cs +++ b/src/Disqord.Core/Models/Application/TeamMemberJsonModel.cs @@ -15,4 +15,7 @@ public class TeamMemberJsonModel : JsonModel [JsonProperty("user")] public UserJsonModel User = null!; -} \ No newline at end of file + + [JsonProperty("role")] + public TeamMemberRole Role; +} diff --git a/src/Disqord.Core/Models/AutoModeration/AutoModerationTriggerMetadataJsonModel.cs b/src/Disqord.Core/Models/AutoModeration/AutoModerationTriggerMetadataJsonModel.cs index 0f4f41e1b..24aa43961 100644 --- a/src/Disqord.Core/Models/AutoModeration/AutoModerationTriggerMetadataJsonModel.cs +++ b/src/Disqord.Core/Models/AutoModeration/AutoModerationTriggerMetadataJsonModel.cs @@ -19,4 +19,7 @@ public class AutoModerationTriggerMetadataJsonModel : JsonModel [JsonProperty("mention_total_limit")] public Optional MentionTotalLimit; + + [JsonProperty("mention_raid_protection_enabled")] + public Optional MentionRaidProtectionEnabled; } diff --git a/src/Disqord.Core/Models/GuildJsonModel.cs b/src/Disqord.Core/Models/GuildJsonModel.cs index 427da3784..02da5b90e 100644 --- a/src/Disqord.Core/Models/GuildJsonModel.cs +++ b/src/Disqord.Core/Models/GuildJsonModel.cs @@ -125,4 +125,7 @@ public class GuildJsonModel : JsonModel [JsonProperty("premium_progress_bar_enabled")] public bool PremiumProgressBarEnabled; + + [JsonProperty("safety_alerts_channel_id")] + public Snowflake? SafetyAlertsChannelId; } diff --git a/src/Disqord.Gateway/Entities/Cached/CachedGuild.cs b/src/Disqord.Gateway/Entities/Cached/CachedGuild.cs index 0514c61f7..42bf01da8 100644 --- a/src/Disqord.Gateway/Entities/Cached/CachedGuild.cs +++ b/src/Disqord.Gateway/Entities/Cached/CachedGuild.cs @@ -146,6 +146,9 @@ public IReadOnlyDictionary Members /// public bool IsBoostProgressBarEnabled { get; private set; } + /// + public Snowflake? SafetyAlertsChannelId { get; private set; } + IReadOnlyDictionary IGatewayGuild.Channels { get @@ -250,6 +253,7 @@ public void Update(GuildJsonModel model) MaxVideoMemberCount = model.MaxVideoChannelUsers.GetValueOrNullable(); NsfwLevel = model.NsfwLevel; IsBoostProgressBarEnabled = model.PremiumProgressBarEnabled; + SafetyAlertsChannelId = model.SafetyAlertsChannelId; } public void Update(GatewayGuildJsonModel model) diff --git a/src/Disqord.Gateway/Entities/Local/LocalActivity.cs b/src/Disqord.Gateway/Entities/Local/LocalActivity.cs index 9298dbce7..4560bcd79 100644 --- a/src/Disqord.Gateway/Entities/Local/LocalActivity.cs +++ b/src/Disqord.Gateway/Entities/Local/LocalActivity.cs @@ -26,6 +26,11 @@ public static LocalActivity Watching(string name) return new(name, ActivityType.Watching); } + public static LocalActivity Custom(string text) + { + return new("Custom Status", ActivityType.Custom, text: text); + } + public static LocalActivity Competing(string name) { return new(name, ActivityType.Competing); @@ -37,6 +42,8 @@ public static LocalActivity Competing(string name) public Optional Type { get; set; } + public Optional Text { get; set; } + public LocalActivity() { } @@ -45,13 +52,15 @@ protected LocalActivity(LocalActivity other) Name = other.Name; Url = other.Url; Type = other.Type; + Text = other.Text; } - public LocalActivity(string name, ActivityType type, string? url = null) + public LocalActivity(string name, ActivityType type, string? url = null, string? text = null) { Name = name; Url = Optional.FromNullable(url); Type = type; + Text = Optional.FromNullable(text); } public LocalActivity(string name, string url) @@ -76,7 +85,8 @@ public virtual ActivityJsonModel ToModel() { Name = Name.Value, Type = Type.Value, - Url = Url + Url = Url, + State = Text }; } } diff --git a/src/Disqord.Gateway/Entities/Transient/Guild/TransientGatewayGuild.cs b/src/Disqord.Gateway/Entities/Transient/Guild/TransientGatewayGuild.cs index b0ae5838d..151b2477d 100644 --- a/src/Disqord.Gateway/Entities/Transient/Guild/TransientGatewayGuild.cs +++ b/src/Disqord.Gateway/Entities/Transient/Guild/TransientGatewayGuild.cs @@ -107,6 +107,8 @@ public IReadOnlyDictionary Stickers public bool IsBoostProgressBarEnabled => Model.PremiumProgressBarEnabled; + public Snowflake? SafetyAlertsChannelId => Model.SafetyAlertsChannelId; + public DateTimeOffset JoinedAt => Model.JoinedAt; public bool IsLarge => Model.Large; diff --git a/src/Disqord.Rest.Api/Content/Json/ModifyGuildJsonRestRequestContent.cs b/src/Disqord.Rest.Api/Content/Json/ModifyGuildJsonRestRequestContent.cs index 22be6d65b..d13383788 100644 --- a/src/Disqord.Rest.Api/Content/Json/ModifyGuildJsonRestRequestContent.cs +++ b/src/Disqord.Rest.Api/Content/Json/ModifyGuildJsonRestRequestContent.cs @@ -62,4 +62,7 @@ public class ModifyGuildJsonRestRequestContent : JsonModelRestRequestContent [JsonProperty("premium_progress_bar_enabled")] public Optional PremiumProgressBarEnabled; -} \ No newline at end of file + + [JsonProperty("safety_alerts_channel_id")] + public Optional SafetyAlertsChannelId; +} diff --git a/src/Disqord.Rest/ActionProperties/Modify/ModifyGuildActionProperties.cs b/src/Disqord.Rest/ActionProperties/Modify/ModifyGuildActionProperties.cs index 0c1322c53..98f6aec53 100644 --- a/src/Disqord.Rest/ActionProperties/Modify/ModifyGuildActionProperties.cs +++ b/src/Disqord.Rest/ActionProperties/Modify/ModifyGuildActionProperties.cs @@ -45,6 +45,8 @@ public sealed class ModifyGuildActionProperties public Optional IsBoostProgressBarEnabled { internal get; set; } + public Optional SafetyAlertsChannelId { internal get; set; } + internal ModifyGuildActionProperties() { } -} \ No newline at end of file +} diff --git a/src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs b/src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs index be17500e2..3f3617503 100644 --- a/src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs +++ b/src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs @@ -59,7 +59,8 @@ public static async Task ModifyGuildAsync(this IRestClient client, PreferredLocale = Optional.Convert(properties.PreferredLocale, x => x.Name), Features = Optional.Convert(properties.Features, x => x.ToArray()), Description = properties.Description, - PremiumProgressBarEnabled = properties.IsBoostProgressBarEnabled + PremiumProgressBarEnabled = properties.IsBoostProgressBarEnabled, + SafetyAlertsChannelId = properties.SafetyAlertsChannelId }; var model = await client.ApiClient.ModifyGuildAsync(guildId, content, options, cancellationToken).ConfigureAwait(false);