Skip to content

Commit

Permalink
Query message deletion count from MessageDeletionService (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Sep 1, 2022
1 parent e0c388e commit 67469b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Hammer/Commands/Infractions/InfractionCommand.Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task StatsAsync(InteractionContext context)
embed.AddField("Bans", infractions.Count(i => i.Type is InfractionType.TemporaryBan or InfractionType.Ban).ToString("N0"), true);
embed.AddField("Kicks", infractions.Count(i => i.Type is InfractionType.Kick).ToString("N0"), true);
embed.AddField("Gags", infractions.Count(i => i.Type is InfractionType.Gag).ToString("N0"), true);
embed.AddField("Messages Deleted", infractions.Count(i => i.Type is InfractionType.MessageDeletion).ToString("N0"), true);
embed.AddField("Messages Deleted", (await _messageDeletionService.CountMessageDeletionsAsync(context.Guild)).ToString("N0"), true);
}

var builder = new DiscordWebhookBuilder();
Expand Down
3 changes: 3 additions & 0 deletions Hammer/Commands/Infractions/InfractionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal sealed partial class InfractionCommand : ApplicationCommandModule
{
private readonly ConfigurationService _configurationService;
private readonly InfractionService _infractionService;
private readonly MessageDeletionService _messageDeletionService;
private readonly RuleService _ruleService;

/// <summary>
Expand All @@ -19,11 +20,13 @@ internal sealed partial class InfractionCommand : ApplicationCommandModule
public InfractionCommand(
ConfigurationService configurationService,
InfractionService infractionService,
MessageDeletionService messageDeletionService,
RuleService ruleService
)
{
_configurationService = configurationService;
_infractionService = infractionService;
_messageDeletionService = messageDeletionService;
_ruleService = ruleService;
}
}
14 changes: 14 additions & 0 deletions Hammer/Services/MessageDeletionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ DiscordLogService logService
_logService = logService;
}

/// <summary>
/// Returns the count of deleted messages in the specified guild.
/// </summary>
/// <param name="guild">The guild whose deleted messages to count.</param>
/// <returns>The count of deleted messages in <paramref name="guild" />.</returns>
public async Task<int> CountMessageDeletionsAsync(DiscordGuild guild)
{
ArgumentNullException.ThrowIfNull(guild);

await using AsyncServiceScope scope = _scopeFactory.CreateAsyncScope();
await using var context = scope.ServiceProvider.GetRequiredService<HammerContext>();
return context.DeletedMessages.Count(m => m.GuildId == guild.Id);
}

/// <summary>
/// Deletes a specified message, logging the deletion in the staff log and optionally notifying the author.
/// </summary>
Expand Down

0 comments on commit 67469b2

Please sign in to comment.