Skip to content

Commit

Permalink
Add /transfer_warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Aug 13, 2021
1 parent 8d0b6a2 commit 85f04ee
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Modules/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ public async Task WarningsSlashCommand(InteractionContext ctx,
eout.AsEphemeral(true);

await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, eout);
}

[SlashCommand("transfer_warnings", "Transfer warnings from one user to another.")]
[SlashRequireHomeserverPerm(ServerPermLevel.Mod)]
public async Task TransferWarningsSlashCommand(InteractionContext ctx,
[Option("source_user", "The user currently holding the warnings.")] DiscordUser sourceUser,
[Option("target_user", "The user recieving the warnings.")] DiscordUser targetUser,
[Option("force_override", "DESTRUCTIVE OPERATION: Whether to OVERRIDE and REMOVE the target users existing warnings.")] bool forceOverride = false
)
{
var sourceWarnings = await Program.db.HashGetAllAsync(sourceUser.Id.ToString());
var targetWarnings = await Program.db.HashGetAllAsync(targetUser.Id.ToString());

if (sourceWarnings.Length == 0)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} The source user has no warnings to transfer.", Warnings.GenerateWarningsEmbed(sourceUser));
return;
}
else if (targetWarnings.Length > 0 && !forceOverride)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Warning} **CAUTION**: The target user has warnings.\n\n" +
$"If you are sure you want to **OVERRIDE** and **DELETE** these warnings, please consider the consequences before adding `force_override: true` to the command.",
Warnings.GenerateWarningsEmbed(targetUser));
return;
}
else if (targetWarnings.Length > 0 && forceOverride)
{
await Program.db.KeyDeleteAsync(targetUser.Id.ToString());
await Program.db.KeyRenameAsync(sourceUser.Id.ToString(), targetUser.Id.ToString());
} else
{
await Program.db.KeyRenameAsync(sourceUser.Id.ToString(), targetUser.Id.ToString());
}
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successully transferred warnings from {sourceUser.Mention} to {targetUser.Mention}!");
}

[ContextMenu(ApplicationCommandType.UserContextMenu, "Show Warnings")]
Expand Down

0 comments on commit 85f04ee

Please sign in to comment.