Skip to content

Commit

Permalink
Add urgent report threshold (#15)
Browse files Browse the repository at this point in the history
Mentions all staff if message report count exceeds a configuration-defined threshold (defaults to 5)
  • Loading branch information
oliverbooth committed Mar 26, 2022
1 parent 0d59a3f commit fe42e2d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Hammer/Configuration/GuildConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ internal sealed class GuildConfiguration
/// <value>The guild's tertiary color, in 24-bit RGB format.</value>
[JsonPropertyName("tertiaryColor")]
public int TertiaryColor { get; set; } = 0xFFE056;

/// <summary>
/// Gets or sets the threshold before a message report is considered urgent.
/// </summary>
/// <value>The urgent report threshold.</value>
[JsonPropertyName("urgentReportThreshold")]
public int UrgentReportThreshold { get; set; } = 5;
}
26 changes: 24 additions & 2 deletions Hammer/Services/MessageReportService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -97,6 +97,16 @@ public async Task<ReportedMessage> CreateNewMessageReportAsync(DiscordMessage me
return report;
}

/// <summary>
/// Returns the count of reports on a specified message.
/// </summary>
/// <param name="message">The message whose report count to retrieve.</param>
/// <returns>The number of reports made on <paramref name="message" />.</returns>
public int GetReportCount(DiscordMessage message)
{
return _reportedMessages.Count(m => m.MessageId == message.Id);
}

/// <summary>
/// Determines if a specified reporter has already
/// </summary>
Expand Down Expand Up @@ -154,8 +164,20 @@ public async Task ReportMessageAsync(DiscordMessage message, DiscordMember repor

Logger.Info(LoggerMessages.MessageReported.FormatSmart(new {user = reporter, message}));
await CreateNewMessageReportAsync(message, reporter);

GuildConfiguration guildConfiguration = _configurationService.GetGuildConfiguration(message.Channel.Guild);
int urgentReportThreshold = guildConfiguration.UrgentReportThreshold;
int reportCount = GetReportCount(message);

StaffNotificationOptions notificationOptions;

if (reportCount >= urgentReportThreshold)
notificationOptions = StaffNotificationOptions.Administrator | StaffNotificationOptions.Moderator;
else
notificationOptions = StaffNotificationOptions.Here;

await reporter.SendMessageAsync(CreateUserReportEmbed(message, reporter));
await _corePlugin.LogAsync(reporter.Guild, CreateStaffReportEmbed(message, reporter), StaffNotificationOptions.Here);
await _corePlugin.LogAsync(reporter.Guild, CreateStaffReportEmbed(message, reporter), notificationOptions);
}

/// <summary>
Expand Down

0 comments on commit fe42e2d

Please sign in to comment.