diff --git a/Commands/AdminCommands.cs b/Commands/AdminCommands.cs index b7fcfeb..7daead7 100644 --- a/Commands/AdminCommands.cs +++ b/Commands/AdminCommands.cs @@ -211,6 +211,7 @@ public class AdminCommands } } + [RequireGuild] [Command("reload")] [Description("Reloads the bot config.")] public async Task Reload(SlashCommandContext command) @@ -224,6 +225,7 @@ public class AdminCommands await SupportChild.Reload(); } + [RequireGuild] [Command("getinterviewtemplates")] [Description("Provides a copy of the interview templates which you can edit and then reupload.")] public async Task GetInterviewTemplates(SlashCommandContext command) @@ -232,6 +234,7 @@ public class AdminCommands await command.RespondAsync(new DiscordInteractionResponseBuilder().AddFile("interview-templates.json", stream).AsEphemeral()); } + [RequireGuild] [Command("setinterviewtemplates")] [Description("Uploads an interview template file.")] public async Task SetInterviewTemplates(SlashCommandContext command, [Parameter("file")] DiscordAttachment file) diff --git a/Commands/RestartInterviewCommand.cs b/Commands/RestartInterviewCommand.cs new file mode 100644 index 0000000..9b0bbdf --- /dev/null +++ b/Commands/RestartInterviewCommand.cs @@ -0,0 +1,23 @@ +using System.ComponentModel; +using System.Threading.Tasks; +using DSharpPlus.Commands; +using DSharpPlus.Commands.Processors.SlashCommands; +using DSharpPlus.Entities; + +namespace SupportChild.Commands; + +public class RestartInterviewCommand +{ + [Command("restartinterview")] + [Description("Restarts the automated interview in this channel, using an updated template if available.")] + public async Task OnExecute(SlashCommandContext command) + { + await command.DeferResponseAsync(); + await Interviewer.RestartInterview(command); + await command.RespondAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = "Interview restarted." + }, true); + } +} \ No newline at end of file diff --git a/Interviewer.cs b/Interviewer.cs index 3f548d2..fa6ccd6 100644 --- a/Interviewer.cs +++ b/Interviewer.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using DSharpPlus.Commands.Processors.SlashCommands; using DSharpPlus.Entities; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -251,6 +252,20 @@ public static class Interviewer } } + public static async Task RestartInterview(SlashCommandContext command) + { + if (activeInterviews.TryGetValue(command.Channel.Id, out InterviewQuestion interviewRoot)) + { + await DeletePreviousMessages(interviewRoot, command.Channel); + if (!Database.TryDeleteInterview(command.Channel.Id)) + { + Logger.Error("Could not delete interview from database. Channel ID: " + command.Channel.Id); + } + ReloadInterviews(); + } + StartInterview(command.Channel); + } + public static async Task ProcessButtonOrSelectorResponse(DiscordInteraction interaction) { if (interaction?.Channel == null || interaction?.Message == null) diff --git a/SupportChild.cs b/SupportChild.cs index 8bff6e9..a96f4ad 100644 --- a/SupportChild.cs +++ b/SupportChild.cs @@ -190,6 +190,7 @@ internal static class SupportChild typeof(AddCommand), typeof(AddMessageCommand), typeof(AddStaffCommand), + typeof(AdminCommands), typeof(AssignCommand), typeof(BlacklistCommand), typeof(CloseCommand), @@ -205,6 +206,7 @@ internal static class SupportChild typeof(RemoveCategoryCommand), typeof(RemoveMessageCommand), typeof(RemoveStaffCommand), + typeof(RestartInterviewCommand), typeof(SayCommand), typeof(SetSummaryCommand), typeof(StatusCommand), @@ -212,8 +214,7 @@ internal static class SupportChild typeof(ToggleActiveCommand), typeof(TranscriptCommand), typeof(UnassignCommand), - typeof(UnblacklistCommand), - typeof(AdminCommands) + typeof(UnblacklistCommand) ]); extension.AddProcessor(new SlashCommandProcessor()); extension.CommandErrored += EventHandler.OnCommandError;