Skip to content

Commit

Permalink
Add warn command (#3)
Browse files Browse the repository at this point in the history
In the format:
warn <id> [reason]
or
warn <user> [reason]
  • Loading branch information
oliverbooth committed Mar 14, 2022
1 parent 59a09ff commit 9728fab
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Hammer/CommandModules/Staff/StaffModule.Warn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Threading.Tasks;
using BrackeysBot.API.Extensions;
using DisCatSharp;
using DisCatSharp.CommandsNext;
using DisCatSharp.CommandsNext.Attributes;
using DisCatSharp.Entities;
using Hammer.Attributes;
using Hammer.Data;
using Hammer.Extensions;
using Hammer.Resources;
using Humanizer;
using SmartFormat;
using PermissionLevel = Hammer.Data.PermissionLevel;

namespace Hammer.CommandModules.Staff;

internal sealed partial class StaffModule
{
[Command("warn")]
[Description("Issues a warning to a user.")]
[RequirePermissionLevel(PermissionLevel.Moderator)]
public async Task WarnCommandAsync(CommandContext context, [Description("The ID of the user to warn.")] ulong userId,
[Description("The reason for the warning")] [RemainingText]
string? reason = null)
{
DiscordUser user = await context.Client.GetUserAsync(userId);

if (user is null)
{
var embed = new DiscordEmbedBuilder();
embed.WithColor(0xFF0000);
embed.WithTitle(EmbedTitles.NoSuchUser);
embed.WithDescription(EmbedMessages.NoSuchUser.FormatSmart(new {id = userId}));
await context.RespondAsync(embed);
return;
}

await WarnCommandAsync(context, user, reason);
}

[Command("warn")]
[Description("Issues a warning to a user.")]
[RequirePermissionLevel(PermissionLevel.Moderator)]
public async Task WarnCommandAsync(CommandContext context, [Description("The user to warn.")] DiscordUser user,
[Description("The reason for the warning")] [RemainingText]
string? reason = null)
{
await context.AcknowledgeAsync();

Infraction infraction = await _infractionService.WarnAsync(user, context.Member, reason);
var embed = new DiscordEmbedBuilder();
embed.WithColor(0xFF0000);
embed.WithTitle(infraction.Type.Humanize());
embed.WithDescription(infraction.Reason.WithWhiteSpaceAlternative(Formatter.Italic("<no reason specified>")));
embed.WithAuthor(user);
embed.WithFooter($"Infraction #{infraction.Id} \u2022 User #{user.Id}");

await context.RespondAsync(embed);
}
}

0 comments on commit 9728fab

Please sign in to comment.