diff --git a/Interviewer.cs b/Interviewer.cs index 7d52c04..92f9f60 100644 --- a/Interviewer.cs +++ b/Interviewer.cs @@ -323,13 +323,6 @@ public static class Interviewer } } - private static Dictionary activeInterviews = []; - - public static void ReloadInterviews() - { - activeInterviews = Database.GetAllInterviews(); - } - public static async void StartInterview(DiscordChannel channel) { if (channel.Parent == null) @@ -352,20 +345,18 @@ public static class Interviewer { await CreateQuestion(channel, interview); Database.SaveInterview(channel.Id, interview); - activeInterviews = Database.GetAllInterviews(); } } public static async Task RestartInterview(SlashCommandContext command) { - if (activeInterviews.TryGetValue(command.Channel.Id, out InterviewQuestion interviewRoot)) + if (Database.TryGetInterview(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); } @@ -385,7 +376,7 @@ public static class Interviewer } // Return if there is no active interview in this channel - if (!activeInterviews.TryGetValue(interaction.Channel.Id, out InterviewQuestion interviewRoot)) + if (!Database.TryGetInterview(interaction.Channel.Id, out InterviewQuestion interviewRoot)) { await interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder() .AddEmbed(new DiscordEmbedBuilder() @@ -515,7 +506,7 @@ public static class Interviewer } // The channel does not have an active interview. - if (!activeInterviews.TryGetValue(answerMessage.ReferencedMessage.Channel.Id, out InterviewQuestion interviewRoot)) + if (!Database.TryGetInterview(answerMessage.ReferencedMessage.Channel.Id, out InterviewQuestion interviewRoot)) { return; } @@ -638,7 +629,6 @@ public static class Interviewer { Logger.Error("Could not delete interview from database. Channel ID: " + channel.Id); } - ReloadInterviews(); return; case QuestionType.END_WITHOUT_SUMMARY: await channel.SendMessageAsync(new DiscordEmbedBuilder() @@ -653,7 +643,6 @@ public static class Interviewer { Logger.Error("Could not delete interview from database. Channel ID: " + channel.Id); } - ReloadInterviews(); break; case QuestionType.ERROR: default: diff --git a/SupportChild.cs b/SupportChild.cs index a96f4ad..ab642bd 100644 --- a/SupportChild.cs +++ b/SupportChild.cs @@ -149,17 +149,6 @@ internal static class SupportChild return false; } - try - { - Logger.Log("Loading interviews from database..."); - Interviewer.ReloadInterviews(); - } - catch (Exception e) - { - Logger.Fatal("Could not load interviews from database. Error: ", e); - return false; - } - Logger.Log("Setting up Discord client..."); DiscordClientBuilder clientBuilder = DiscordClientBuilder.CreateDefault(Config.token, DiscordIntents.All) .SetReconnectOnFatalGatewayErrors()