Add command to restart interviews

This commit is contained in:
Toastie 2024-12-26 20:47:07 +13:00
parent d9fcef449a
commit e2494c73d4
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 44 additions and 2 deletions

View file

@ -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)

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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;