Skip to content

Commit

Permalink
Merge important notes to embed field
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 25, 2022
1 parent ed14de0 commit eabb07e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Hammer/Commands/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async Task BanAsync(InteractionContext context,
TimeSpan? duration = durationRaw?.ToTimeSpan() ?? null;
var builder = new DiscordEmbedBuilder();
var message = new DiscordWebhookBuilder();
var importantNotes = new List<string>();

Rule? rule = null;
if (ruleBroken.HasValue)
Expand All @@ -74,7 +75,7 @@ public async Task BanAsync(InteractionContext context,
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.");
importantNotes.Add("The specified rule does not exist - it will be omitted from the infraction.");
}

Task<(Infraction, bool)> infractionTask = duration is null
Expand All @@ -85,7 +86,10 @@ public async Task BanAsync(InteractionContext context,
(infraction, bool dmSuccess) = await infractionTask.ConfigureAwait(false);

if (!dmSuccess)
builder.AddField("⚠️ Important", "The ban was successfully issued, but the user could not be DM'd.");
importantNotes.Add("The ban was successfully issued, but the user could not be DM'd.");

if (importantNotes.Count > 0)
builder.AddField("⚠️ Important Notes", string.Join("\n", importantNotes.Select(n => $"• {n}")));

builder.WithAuthor(user);
builder.WithColor(DiscordColor.Red);
Expand Down
8 changes: 6 additions & 2 deletions Hammer/Commands/KickCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task KickAsync(InteractionContext context,

var builder = new DiscordEmbedBuilder();
var message = new DiscordWebhookBuilder();
var importantNotes = new List<string>();
DiscordMember member;

try
Expand Down Expand Up @@ -91,14 +92,17 @@ public async Task KickAsync(InteractionContext context,
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.");
importantNotes.Add("The specified rule does not exist - it will be omitted from the infraction.");
}

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

if (!dmSuccess)
builder.AddField("⚠️ Important", "The kick was successfully issued, but the user could not be DM'd.");
importantNotes.Add("The kick was successfully issued, but the user could not be DM'd.");

if (importantNotes.Count > 0)
builder.AddField("⚠️ Important Notes", string.Join("\n", importantNotes.Select(n => $"• {n}")));

builder.WithAuthor(member);
builder.WithColor(DiscordColor.Red);
Expand Down
9 changes: 7 additions & 2 deletions Hammer/Commands/MuteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public async Task MuteAsync(InteractionContext context,

TimeSpan? duration = durationRaw?.ToTimeSpan() ?? null;
var message = new DiscordWebhookBuilder();
var importantNotes = new List<string>();

Rule? rule = null;
if (ruleBroken.HasValue)
Expand All @@ -72,20 +73,24 @@ public async Task MuteAsync(InteractionContext context,
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.");
importantNotes.Add("The specified rule does not exist - it will be omitted from the infraction.");
}

Task<(Infraction, bool)> infractionTask = duration is null
? _muteService.MuteAsync(user, context.Member!, reason, rule)
: _muteService.TemporaryMuteAsync(user, context.Member!, reason, duration.Value, rule);

var builder = new DiscordEmbedBuilder();

try
{
(infraction, bool dmSuccess) = await infractionTask.ConfigureAwait(false);

if (!dmSuccess)
builder.AddField("⚠️ Important", "The mute was successfully issued, but the user could not be DM'd.");
importantNotes.Add("The mute was successfully issued, but the user could not be DM'd.");

if (importantNotes.Count > 0)
builder.AddField("⚠️ Important Notes", string.Join("\n", importantNotes.Select(n => $"• {n}")));

builder.WithAuthor(user);
builder.WithColor(DiscordColor.Red);
Expand Down
8 changes: 6 additions & 2 deletions Hammer/Commands/WarnCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public async Task WarnAsync(InteractionContext context,

var builder = new DiscordEmbedBuilder();
var message = new DiscordWebhookBuilder();
var importantNotes = new List<string>();

try
{
Expand All @@ -72,14 +73,17 @@ public async Task WarnAsync(InteractionContext context,
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.");
importantNotes.Add("The specified rule does not exist - it will be omitted from the infraction.");
}

(infraction, bool dmSuccess) =
await _warningService.WarnAsync(user, context.Member, reason, rule).ConfigureAwait(false);

if (!dmSuccess)
builder.AddField("⚠️ Important", "The warning was successfully issued, but the user could not be DM'd.");
importantNotes.Add("The warning was successfully issued, but the user could not be DM'd.");

if (importantNotes.Count > 0)
builder.AddField("⚠️ Important Notes", string.Join("\n", importantNotes.Select(n => $"• {n}")));

builder.WithAuthor(user);
builder.WithColor(DiscordColor.Orange);
Expand Down

0 comments on commit eabb07e

Please sign in to comment.