-
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.
- Loading branch information
1 parent
7847bf5
commit 2b4f474
Showing
3 changed files
with
71 additions
and
97 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,70 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using BrackeysBot.API.Extensions; | ||
using BrackeysBot.Core.API; | ||
using BrackeysBot.Core.API.Attributes; | ||
using DSharpPlus.CommandsNext; | ||
using DSharpPlus.CommandsNext.Attributes; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.Exceptions; | ||
using DSharpPlus.SlashCommands; | ||
using DSharpPlus.SlashCommands.Attributes; | ||
using Hammer.Extensions; | ||
using Hammer.Services; | ||
using NLog; | ||
|
||
namespace Hammer.CommandModules; | ||
|
||
/// <summary> | ||
/// Represents a module which implements the <c>unmute</c> command. | ||
/// </summary> | ||
internal sealed class UnmuteCommand : ApplicationCommandModule | ||
{ | ||
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); | ||
private readonly MuteService _muteService; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UnmuteCommand" /> class. | ||
/// </summary> | ||
/// <param name="muteService">The mute service.</param> | ||
public UnmuteCommand(MuteService muteService) | ||
{ | ||
_muteService = muteService; | ||
} | ||
|
||
[SlashCommand("unmute", "Unmutes a user.", false)] | ||
[SlashRequireGuild] | ||
public async Task UnmuteSlashCommandAsync(InteractionContext context, | ||
[Option("user", "The user to unmute.")] DiscordUser user, | ||
[Option("reason", "The reason for the mute revocation."), RemainingText] string? reason = null) | ||
{ | ||
await context.DeferAsync(true).ConfigureAwait(false); | ||
|
||
var embed = new DiscordEmbedBuilder(); | ||
try | ||
{ | ||
await _muteService.RevokeMuteAsync(user, context.Member!, reason).ConfigureAwait(false); | ||
|
||
embed.WithAuthor(user); | ||
embed.WithColor(DiscordColor.SpringGreen); | ||
embed.WithTitle("Unmuted user"); | ||
embed.WithDescription(reason); | ||
|
||
reason = reason.WithWhiteSpaceAlternative("None"); | ||
Logger.Info($"{context.Member} unmuted {user}. Reason: {reason}"); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Logger.Error(exception, "Could not revoke mute"); | ||
|
||
embed.WithColor(DiscordColor.Red); | ||
embed.WithTitle("⚠️ Error revoking mute"); | ||
embed.WithDescription($"{exception.GetType().Name} was thrown while revoking the mute."); | ||
embed.WithFooter("See log for further details."); | ||
} | ||
|
||
var builder = new DiscordWebhookBuilder(); | ||
builder.AddEmbed(embed); | ||
await context.EditResponseAsync(builder).ConfigureAwait(false); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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