Skip to content

Commit

Permalink
Remove infraction, don't redact
Browse files Browse the repository at this point in the history
EF migration required
  • Loading branch information
oliverbooth committed May 3, 2022
1 parent 4dbbe8c commit 4dbbae1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
9 changes: 1 addition & 8 deletions Hammer.API/IInfraction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Hammer.API;

Expand All @@ -19,13 +19,6 @@ public interface IInfraction : IEquatable<IInfraction>, IComparable<IInfraction>
/// <value>The infraction ID.</value>
long Id { get; }

/// <summary>
/// Gets a value indicating whether this infraction has been redacted.
/// </summary>
/// <value><see langword="true" /> if this infraction has been redacted; otherwise, <see langword="false" />.</value>
/// <remarks>This applies to an infraction which has been deleted, or a permanent mute/ban which has been revoked.</remarks>
bool IsRedacted { get; }

/// <summary>
/// Gets the date and time at which this infraction was issued.
/// </summary>
Expand Down
8 changes: 2 additions & 6 deletions Hammer/Data/Infraction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using DSharpPlus.Entities;
using Hammer.API;

Expand All @@ -13,10 +13,7 @@ internal sealed class Infraction : IInfraction
public ulong GuildId { get; private set; }

/// <inheritdoc />
public long Id { get; private set; }

/// <inheritdoc />
public bool IsRedacted { get; internal set; }
public long Id { get; internal set; }

/// <inheritdoc />
public DateTimeOffset IssuedAt { get; private set; }
Expand Down Expand Up @@ -53,7 +50,6 @@ public static Infraction Create(InfractionType type, ulong userId, ulong staffMe
return new Infraction
{
GuildId = guildId,
IsRedacted = false,
IssuedAt = issuedAt ?? DateTimeOffset.UtcNow,
Reason = reason,
RuleId = ruleBroken,
Expand Down
10 changes: 4 additions & 6 deletions Hammer/Services/InfractionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,15 @@ public async Task LogInfractionAsync(DiscordGuild guild, Infraction infraction,
/// </summary>
/// <param name="infraction">The infraction to redact.</param>
/// <exception cref="ArgumentNullException"><paramref name="infraction" /> is <see langword="null" />.</exception>
public async Task RedactInfractionAsync(Infraction infraction)
public async Task RemoveInfractionAsync(Infraction infraction)
{
if (infraction is null) throw new ArgumentNullException(nameof(infraction));

_infractionCache[infraction.GuildId].Remove(infraction);
infraction.IsRedacted = true;

await using AsyncServiceScope scope = _scopeFactory.CreateAsyncScope();
await using var context = scope.ServiceProvider.GetRequiredService<HammerContext>();
context.Update(infraction);
context.Remove(infraction);
await context.SaveChangesAsync().ConfigureAwait(false);
}

Expand All @@ -429,7 +428,7 @@ public async Task RedactInfractionAsync(Infraction infraction)
/// </summary>
/// <param name="infractions">The infractions to redact.</param>
/// <exception cref="ArgumentNullException"><paramref name="infractions" /> is <see langword="null" />.</exception>
public async Task RedactInfractionsAsync(IEnumerable<Infraction> infractions)
public async Task RemoveInfractionsAsync(IEnumerable<Infraction> infractions)
{
if (infractions is null) throw new ArgumentNullException(nameof(infractions));

Expand All @@ -441,8 +440,7 @@ public async Task RedactInfractionsAsync(IEnumerable<Infraction> infractions)
List<Infraction> list = _infractionCache[group.Key];
foreach (Infraction infraction in group)
{
infraction.IsRedacted = true;
context.Update(infraction);
context.Remove(infraction);
list.Remove(infraction);
}
}
Expand Down

0 comments on commit 4dbbae1

Please sign in to comment.