Skip to content

Commit

Permalink
Notify on invalid rule (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 24, 2022
1 parent 45d44a6 commit d4ac783
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Hammer/Commands/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ public async Task BanAsync(InteractionContext context,

TimeSpan? duration = durationRaw?.ToTimeSpan() ?? null;
var builder = new DiscordEmbedBuilder();
var message = new DiscordWebhookBuilder();

Rule? rule = null;
if (ruleBroken.HasValue)
rule = _ruleService.GetRuleById(context.Guild, (int) ruleBroken.Value);
{
var ruleId = (int) ruleBroken.Value;
if (_ruleService.GuildHasRule(context.Guild, ruleId))
rule = _ruleService.GetRuleById(context.Guild, ruleId);
else
message.WithContent("The specified rule does not exist - it will be omitted from the infraction.");
}

Task<Infraction> infractionTask = duration is null
? _banService.BanAsync(user, context.Member!, reason, rule)
Expand Down Expand Up @@ -105,7 +112,6 @@ public async Task BanAsync(InteractionContext context,
builder.WithFooter("See log for further details.");
}

var message = new DiscordWebhookBuilder();
message.AddEmbed(builder);
await context.EditResponseAsync(message).ConfigureAwait(false);
}
Expand Down
8 changes: 7 additions & 1 deletion Hammer/Commands/KickCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ public async Task KickAsync(InteractionContext context,
{
Rule? rule = null;
if (ruleBroken.HasValue)
rule = _ruleService.GetRuleById(context.Guild, (int) ruleBroken.Value);
{
var ruleId = (int) ruleBroken.Value;
if (_ruleService.GuildHasRule(context.Guild, ruleId))
rule = _ruleService.GetRuleById(context.Guild, ruleId);
else
message.WithContent("The specified rule does not exist - it will be omitted from the infraction.");
}

infraction = await _banService.KickAsync(member, context.Member!, reason, rule).ConfigureAwait(false);

Expand Down
10 changes: 8 additions & 2 deletions Hammer/Commands/MuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ public async Task MuteAsync(InteractionContext context,
}

TimeSpan? duration = durationRaw?.ToTimeSpan() ?? null;
var message = new DiscordWebhookBuilder();

Rule? rule = null;
if (ruleBroken.HasValue)
rule = _ruleService.GetRuleById(context.Guild, (int) ruleBroken.Value);
{
var ruleId = (int) ruleBroken.Value;
if (_ruleService.GuildHasRule(context.Guild, ruleId))
rule = _ruleService.GetRuleById(context.Guild, ruleId);
else
message.WithContent("The specified rule does not exist - it will be omitted from the infraction.");
}

Task<Infraction> infractionTask = duration is null
? _muteService.MuteAsync(user, context.Member!, reason, rule)
Expand Down Expand Up @@ -107,7 +114,6 @@ public async Task MuteAsync(InteractionContext context,
builder.WithFooter("See log for further details.");
}

var message = new DiscordWebhookBuilder();
message.AddEmbed(builder);
await context.EditResponseAsync(message).ConfigureAwait(false);
}
Expand Down

0 comments on commit d4ac783

Please sign in to comment.