diff --git a/Modules/SlashCommands.cs b/Modules/SlashCommands.cs index aa9ae285..e597cf0c 100644 --- a/Modules/SlashCommands.cs +++ b/Modules/SlashCommands.cs @@ -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")]