Skip to content

Commit

Permalink
Implement support for join raid and mention raid protection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Jun 17, 2023
1 parent 8a2ece1 commit b3eca74
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public interface IAutoModerationTriggerMetadata
/// Max 50.
/// </remarks>
Optional<byte> MentionTotalLimit { get; }

/// <summary>
/// Gets a value indicating whether to automatically detect mention raids.
/// </summary>
Optional<bool> MentionRaidProtectionEnabled { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public enum GuildFeature
/// </summary>
PreviewEnabled,

/// <summary>
/// The guild has disabled alerts for join raids in the configured safety alerts channel.
/// </summary>
RaidAlertsDisabled,

/// <summary>
/// The guild is able to set role icons.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public interface IGuild : IPartialGuild
/// </summary>
new bool IsPremiumProgressBarEnabled { get; }

/// <summary>
/// Gets the ID of the channel where admins and moderators of Community guilds receive safety alerts from Discord.
/// </summary>
new Snowflake? SafetyAlertsChannelID { get; }

/// <inheritdoc/>
Optional<Snowflake> IPartialGuild.ID => this.ID;

Expand Down Expand Up @@ -365,4 +370,7 @@ public interface IGuild : IPartialGuild

/// <inheritdoc/>
Optional<bool> IPartialGuild.IsPremiumProgressBarEnabled => this.IsPremiumProgressBarEnabled;

/// <inheritdoc/>
Optional<Snowflake?> IPartialGuild.SafetyAlertsChannelID => this.SafetyAlertsChannelID;
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@ public interface IPartialGuild

/// <inheritdoc cref="IGuild.IsPremiumProgressBarEnabled"/>
Optional<bool> IsPremiumProgressBarEnabled { get; }

/// <inheritdoc cref="IGuild.SafetyAlertsChannelID"/>
Optional<Snowflake?> SafetyAlertsChannelID { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ Task<Result<IGuildPreview>> GetGuildPreviewAsync
/// <param name="features">The new guild features.</param>
/// <param name="description">The new description.</param>
/// <param name="isPremiumProgressBarEnabled">Whether the guild has the boost progress bar enabled.</param>
/// <param name="safetyAlertsChannelID">
/// The ID of the channel where admins and moderators of Community guilds receive safety alerts from Discord.
/// </param>
/// <param name="reason">The reason to mark the action in the audit log with.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result which may or may not have succeeded.</returns>
Expand All @@ -156,6 +159,7 @@ Task<Result<IGuild>> ModifyGuildAsync
Optional<IReadOnlyList<GuildFeature>> features = default,
Optional<string?> description = default,
Optional<bool> isPremiumProgressBarEnabled = default,
Optional<Snowflake?> safetyAlertsChannelID = default,
Optional<string> reason = default,
CancellationToken ct = default
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public record AvailableGuild
GuildNSFWLevel NSFWLevel,
Optional<IReadOnlyList<ISticker>> Stickers,
bool IsPremiumProgressBarEnabled,
Snowflake? SafetyAlertsChannelID,
DateTimeOffset JoinedAt,
bool IsLarge,
Optional<bool> IsUnavailable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ public record GuildUpdate
Optional<IWelcomeScreen> WelcomeScreen,
GuildNSFWLevel NSFWLevel,
Optional<IReadOnlyList<ISticker>> Stickers,
bool IsPremiumProgressBarEnabled
bool IsPremiumProgressBarEnabled,
Snowflake? SafetyAlertsChannelID
) : IGuildUpdate;
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public record AutoModerationTriggerMetadata
Optional<IReadOnlyList<string>> RegexPatterns = default,
Optional<IReadOnlyList<AutoModerationKeywordPresetType>> Presets = default,
Optional<IReadOnlyList<string>> AllowList = default,
Optional<byte> MentionTotalLimit = default
Optional<byte> MentionTotalLimit = default,
Optional<bool> MentionRaidProtectionEnabled = default
) : IAutoModerationTriggerMetadata;
3 changes: 2 additions & 1 deletion Backend/Remora.Discord.API/API/Objects/Guilds/Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ public record Guild
Optional<IWelcomeScreen> WelcomeScreen,
GuildNSFWLevel NSFWLevel,
Optional<IReadOnlyList<ISticker>> Stickers,
bool IsPremiumProgressBarEnabled
bool IsPremiumProgressBarEnabled,
Snowflake? SafetyAlertsChannelID
) : IGuild;
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ public record PartialGuild
Optional<IWelcomeScreen> WelcomeScreen = default,
Optional<GuildNSFWLevel> NSFWLevel = default,
Optional<IReadOnlyList<ISticker>> Stickers = default,
Optional<bool> IsPremiumProgressBarEnabled = default
Optional<bool> IsPremiumProgressBarEnabled = default,
Optional<Snowflake?> SafetyAlertsChannelID = default
) : IPartialGuild;
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public async Task<Result<IGuild>> ModifyGuildAsync
Optional<IReadOnlyList<GuildFeature>> features = default,
Optional<string?> description = default,
Optional<bool> isPremiumProgressBarEnabled = default,
Optional<Snowflake?> safetyAlertsChannelID = default,
Optional<string> reason = default,
CancellationToken ct = default
)
Expand All @@ -209,6 +210,7 @@ public async Task<Result<IGuild>> ModifyGuildAsync
features,
description,
isPremiumProgressBarEnabled,
safetyAlertsChannelID,
reason,
ct
);
Expand Down
2 changes: 2 additions & 0 deletions Backend/Remora.Discord.Rest/API/Guilds/DiscordRestGuildAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public virtual async Task<Result<IGuild>> ModifyGuildAsync
Optional<IReadOnlyList<GuildFeature>> features = default,
Optional<string?> description = default,
Optional<bool> isPremiumProgressBarEnabled = default,
Optional<Snowflake?> safetyAlertsChannelID = default,
Optional<string> reason = default,
CancellationToken ct = default
)
Expand Down Expand Up @@ -263,6 +264,7 @@ public virtual async Task<Result<IGuild>> ModifyGuildAsync
json.Write("features", features, this.JsonOptions);
json.Write("description", description, this.JsonOptions);
json.Write("premium_progress_bar_enabled", isPremiumProgressBarEnabled, this.JsonOptions);
json.Write("safety_alerts_channel_id", safetyAlertsChannelID, this.JsonOptions);
}
)
.WithRateLimitContext(this.RateLimitCache),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ public async Task PerformsRequestCorrectly()
var features = Array.Empty<GuildFeature>();
var description = "aaa";
var isPremiumProgressBarEnabled = true;
var safetyAlertsChannel = DiscordSnowflake.New(5);
var reason = "test";

var api = CreateAPI
Expand Down Expand Up @@ -381,6 +382,7 @@ public async Task PerformsRequestCorrectly()
.WithProperty("features", p => p.IsArray())
.WithProperty("description", p => p.Is(description))
.WithProperty("premium_progress_bar_enabled", p => p.Is(isPremiumProgressBarEnabled))
.WithProperty("safety_alerts_channel_id", p => p.Is(safetyAlertsChannel.ToString()))
)
)
.Respond("application/json", SampleRepository.Samples[typeof(IGuild)])
Expand Down Expand Up @@ -408,6 +410,7 @@ public async Task PerformsRequestCorrectly()
features,
description,
isPremiumProgressBarEnabled,
safetyAlertsChannel,
reason
);

Expand Down Expand Up @@ -436,6 +439,7 @@ public async Task PerformsNullableRequestCorrectly()
.WithProperty("icon", p => p.IsNull())
.WithProperty("splash", p => p.IsNull())
.WithProperty("banner", p => p.IsNull())
.WithProperty("safety_alerts_channel_id", p => p.IsNull())
)
)
.Respond("application/json", SampleRepository.Samples[typeof(IGuild)])
Expand All @@ -447,7 +451,8 @@ public async Task PerformsNullableRequestCorrectly()
name,
icon: null,
banner: null,
splash: null
splash: null,
safetyAlertsChannelID: null
);

ResultAssert.Successful(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
}
],
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999",
"joined_at": "1970-01-01T00:00:00.000000+00:00",
"large": true,
"unavailable": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
}
],
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": null,
"joined_at": "1970-01-01T00:00:00.000000+00:00",
"large": true,
"unavailable": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"public_updates_channel_id": "999999999999999999",
"nsfw_level": 0,
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999",
"joined_at": "1970-01-01T00:00:00.000000+00:00",
"large": true,
"member_count": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"format_type": 1
}
],
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"format_type": 1
}
],
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"preferred_locale": "en-US",
"public_updates_channel_id": "999999999999999999",
"nsfw_level": 0,
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"allow_list": [
"none"
],
"mention_total_limit": 1
"mention_total_limit": 1,
"mention_raid_protection_enabled": true
}
3 changes: 2 additions & 1 deletion Tests/Remora.Discord.Tests/Samples/Objects/GUILD/GUILD.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
"format_type": 1
}
],
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999"
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"format_type": 1
}
],
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"preferred_locale": "en-US",
"public_updates_channel_id": "999999999999999999",
"nsfw_level": 0,
"premium_progress_bar_enabled": true
"premium_progress_bar_enabled": true,
"safety_alerts_channel_id": "999999999999999999"
}

0 comments on commit b3eca74

Please sign in to comment.