137 lines
4.7 KiB
C#
137 lines
4.7 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using DSharpPlus;
|
|||
|
using DSharpPlus.Entities;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
|
|||
|
namespace SupportChild;
|
|||
|
|
|||
|
public static class Interviewer
|
|||
|
{
|
|||
|
public enum QuestionType
|
|||
|
{
|
|||
|
DONE,
|
|||
|
FAIL,
|
|||
|
BUTTONS,
|
|||
|
SELECTOR,
|
|||
|
TEXT_INPUT
|
|||
|
}
|
|||
|
|
|||
|
// A tree of questions representing an interview.
|
|||
|
// The tree is generated by the config file when a new ticket is opened or the restart interview command is used.
|
|||
|
// Additional components not specified in the config file are populated as the interview progresses.
|
|||
|
// The entire interview tree is serialized and stored in the database in order to record responses as they are made.
|
|||
|
public struct InterviewQuestion
|
|||
|
{
|
|||
|
// Message contents sent to the user.
|
|||
|
public string message;
|
|||
|
|
|||
|
// The type of question.
|
|||
|
public QuestionType type;
|
|||
|
|
|||
|
// Colour of the message embed.
|
|||
|
public string color;
|
|||
|
|
|||
|
// The ID of this message, populated after it has been sent.
|
|||
|
public ulong messageID;
|
|||
|
|
|||
|
// Used as label for this question in the post-interview summary.
|
|||
|
public string summaryField;
|
|||
|
|
|||
|
// The user's response to the question.
|
|||
|
public string answer;
|
|||
|
|
|||
|
// The ID of the user's answer message, populated after it has been received.
|
|||
|
public ulong answerID;
|
|||
|
|
|||
|
// Possible questions to ask next, or DONE/FAIL type in order to finish interview.
|
|||
|
public Dictionary<string, InterviewQuestion> paths;
|
|||
|
}
|
|||
|
|
|||
|
private static Dictionary<ulong, InterviewQuestion> categoryInterviews = [];
|
|||
|
|
|||
|
public static void ParseConfig(JToken interviewConfig)
|
|||
|
{
|
|||
|
categoryInterviews = JsonConvert.DeserializeObject<Dictionary<ulong, InterviewQuestion>>(interviewConfig.ToString());
|
|||
|
}
|
|||
|
|
|||
|
public static void StartInterview(DiscordChannel channel)
|
|||
|
{
|
|||
|
if (channel.Parent == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (categoryInterviews.TryGetValue(channel.Parent.Id, out InterviewQuestion interview))
|
|||
|
{
|
|||
|
CreateQuestion(channel, interview);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static void ProcessResponse(DiscordChannel channel, string response)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private static async void CreateQuestion(DiscordChannel channel, InterviewQuestion question)
|
|||
|
{
|
|||
|
DiscordMessageBuilder msgBuilder = new DiscordMessageBuilder
|
|||
|
{
|
|||
|
Embed = new DiscordEmbedBuilder
|
|||
|
{
|
|||
|
Color = Utilities.StringToColor(question.color),
|
|||
|
Description = question.message
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
switch (question.type)
|
|||
|
{
|
|||
|
case QuestionType.BUTTONS:
|
|||
|
int nrOfButtons = 0;
|
|||
|
for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < question.paths.Count; nrOfButtonRows++)
|
|||
|
{
|
|||
|
List<DiscordButtonComponent> buttonRow = [];
|
|||
|
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < question.paths.Count; nrOfButtons++)
|
|||
|
{
|
|||
|
buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "supportboi_interviewbutton " + nrOfButtons, question.paths.ToArray()[nrOfButtons].Key));
|
|||
|
}
|
|||
|
msgBuilder.AddComponents(buttonRow);
|
|||
|
}
|
|||
|
break;
|
|||
|
case QuestionType.SELECTOR:
|
|||
|
List<DiscordSelectComponent> selectionComponents = [];
|
|||
|
|
|||
|
int selectionOptions = 0;
|
|||
|
for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < question.paths.Count; selectionBoxes++)
|
|||
|
{
|
|||
|
List<DiscordSelectComponentOption> categoryOptions = [];
|
|||
|
for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < question.paths.Count; selectionOptions++)
|
|||
|
{
|
|||
|
categoryOptions.Add(new DiscordSelectComponentOption(question.paths.ToArray()[selectionOptions].Key, selectionOptions.ToString()));
|
|||
|
}
|
|||
|
selectionComponents.Add(new DiscordSelectComponent("supportboi_interviewselector " + selectionBoxes, "Select an option...", categoryOptions, false, 0, 1));
|
|||
|
}
|
|||
|
|
|||
|
msgBuilder.AddComponents(selectionComponents);
|
|||
|
break;
|
|||
|
case QuestionType.TEXT_INPUT:
|
|||
|
// TODO: Add embed footer with response info
|
|||
|
break;
|
|||
|
case QuestionType.DONE:
|
|||
|
case QuestionType.FAIL:
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
DiscordMessage message = await channel.SendMessageAsync(msgBuilder);
|
|||
|
question.messageID = message.Id;
|
|||
|
|
|||
|
// TODO: Save interview progress
|
|||
|
}
|
|||
|
|
|||
|
public static void CreateSummary()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|