-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the format: warn <id> [reason] or warn <user> [reason]
- Loading branch information
1 parent
59a09ff
commit 9728fab
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |