From 3d2d987dfefe73e84f0f339526f9ce32d5db8e1f Mon Sep 17 00:00:00 2001 From: Toastie Date: Thu, 26 Dec 2024 23:47:55 +1300 Subject: [PATCH] Add config entries for interviews --- Commands/NewCommand.cs | 10 +++++++++- Config.cs | 13 ++++++++++--- Interviewer.cs | 18 +++++++++++++++--- default_config.yml | 13 ++++++++++++- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Commands/NewCommand.cs b/Commands/NewCommand.cs index ed5bfa8..089af54 100644 --- a/Commands/NewCommand.cs +++ b/Commands/NewCommand.cs @@ -114,7 +114,9 @@ public class NewCommand return (false, "You cannot use this command in a ticket channel."); } - if (!Database.IsStaff(userID) && Database.TryGetOpenTickets(userID, out List ownTickets) && ownTickets.Count >= Config.ticketLimit) + if (!Database.IsStaff(userID) + && Database.TryGetOpenTickets(userID, out List ownTickets) + && (ownTickets.Count >= Config.ticketLimit && Config.ticketLimit != 0)) { return (false, "You have reached the limit for maximum open tickets."); } @@ -187,6 +189,7 @@ public class NewCommand } DiscordMessage message = await ticketChannel.SendMessageAsync("Hello, " + member.Mention + "!\n" + Config.welcomeMessage); + if (Config.pinFirstMessage) { try @@ -202,6 +205,11 @@ public class NewCommand // Refreshes the channel as changes were made to it above ticketChannel = await SupportChild.client.GetChannelAsync(ticketChannel.Id); + if (Config.interviewsEnabled) + { + Interviewer.StartInterview(ticketChannel); + } + if (staffID != 0) { await ticketChannel.SendMessageAsync(new DiscordEmbedBuilder diff --git a/Config.cs b/Config.cs index 351ecdc..0dd3e51 100644 --- a/Config.cs +++ b/Config.cs @@ -26,6 +26,10 @@ internal static class Config internal static bool assignmentNotifications = false; internal static bool closingNotifications = false; + internal static bool interviewsEnabled = false; + internal static bool deleteMessagesAfterSummary = false; + internal static bool deleteMessagesAfterNoSummary = false; + internal static string hostName = "127.0.0.1"; internal static int port = 3306; internal static string database = "supportchild"; @@ -69,16 +73,15 @@ internal static class Config if (!Enum.TryParse(stringLogLevel, true, out LogLevel logLevel)) { logLevel = LogLevel.Information; - Logger.Warn("Log level '" + stringLogLevel + "' invalid, using 'Information' instead."); + Logger.Warn("Log level '" + stringLogLevel + "' is invalid, using 'Information' instead."); } Logger.SetLogLevel(logLevel); string stringTimestampFormat = json.SelectToken("bot.timestamp-format")?.Value() ?? "RelativeTime"; - if (!Enum.TryParse(stringTimestampFormat, true, out timestampFormat)) { timestampFormat = TimestampFormat.RelativeTime; - Logger.Warn("Timestamp '" + stringTimestampFormat + "' invalid, using 'RelativeTime' instead."); + Logger.Warn("Timestamp '" + stringTimestampFormat + "' is invalid, using 'RelativeTime' instead."); } randomAssignment = json.SelectToken("bot.random-assignment")?.Value() ?? false; @@ -94,6 +97,10 @@ internal static class Config assignmentNotifications = json.SelectToken("notifications.assignment")?.Value() ?? false; closingNotifications = json.SelectToken("notifications.closing")?.Value() ?? false; + interviewsEnabled = json.SelectToken("interviews.enabled")?.Value() ?? false; + deleteMessagesAfterSummary = json.SelectToken("interviews.delete-messages-after-summary")?.Value() ?? false; + deleteMessagesAfterNoSummary = json.SelectToken("interviews.delete-messages-after-no-summary")?.Value() ?? false; + // Reads database info hostName = json.SelectToken("database.address")?.Value() ?? ""; port = json.SelectToken("database.port")?.Value() ?? 3306; diff --git a/Interviewer.cs b/Interviewer.cs index 92f9f60..ada880a 100644 --- a/Interviewer.cs +++ b/Interviewer.cs @@ -352,7 +352,11 @@ public static class Interviewer { if (Database.TryGetInterview(command.Channel.Id, out InterviewQuestion interviewRoot)) { - await DeletePreviousMessages(interviewRoot, command.Channel); + if (Config.deleteMessagesAfterNoSummary) + { + await DeletePreviousMessages(interviewRoot, command.Channel); + } + if (!Database.TryDeleteInterview(command.Channel.Id)) { Logger.Error("Could not delete interview from database. Channel ID: " + command.Channel.Id); @@ -624,7 +628,11 @@ public static class Interviewer await channel.SendMessageAsync(embed); - await DeletePreviousMessages(interviewRoot, channel); + if (Config.deleteMessagesAfterSummary) + { + await DeletePreviousMessages(interviewRoot, channel); + } + if (!Database.TryDeleteInterview(channel.Id)) { Logger.Error("Could not delete interview from database. Channel ID: " + channel.Id); @@ -638,7 +646,11 @@ public static class Interviewer Description = nextQuestion.message }); - await DeletePreviousMessages(interviewRoot, channel); + if (Config.deleteMessagesAfterNoSummary) + { + await DeletePreviousMessages(interviewRoot, channel); + } + if (!Database.TryDeleteInterview(channel.Id)) { Logger.Error("Could not delete interview from database. Channel ID: " + channel.Id); diff --git a/default_config.yml b/default_config.yml index 70a012d..2cc9c53 100644 --- a/default_config.yml +++ b/default_config.yml @@ -48,11 +48,22 @@ notifications: ticket-updated-delay: 0.5 # Notifies staff when they are assigned to tickets. - assignment: true + assignment: true # TODO: Add option to be notified only when the initial interview is finished. # Notifies the user opening the ticket that their ticket was closed and includes the transcript. closing: true +interviews: # TODO: Implement + # Enable the interview system. You must use the admin commands to set up interview templates before you can start using it. + # Any existing interviews can still be completed while interviews are disabled, but new ones will not be created. + enabled: true + + # Whether to delete the interview question and answer messages after an interview summary is posted. + delete-messages-after-summary: true + + # Whether to delete the interview question and answer messages after an interview ends without a summary. + delete-messages-after-no-summary: true + database: # Address and port of the mysql server. address: "127.0.0.1"