From 4bd2d06b0bd5102ec5afe221da3d9db1dcb9e18b Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 30 May 2021 16:45:29 +0200 Subject: [PATCH] Add basic interactivity framework --- .../Types/Application/ApplicationCommand.cs | 4 +- .../ApplicationCommandInteractionData.cs | 2 +- ...teractionApplicationCommandCallbackData.cs | 7 +- Myriad/Types/Component/ButtonStyle.cs | 11 ++ Myriad/Types/Component/ComponentType.cs | 8 ++ .../Types/{ => Component}/MessageComponent.cs | 15 --- Myriad/Types/Message.cs | 2 - PluralKit.Bot/Interactive/BaseInteractive.cs | 125 ++++++++++++++++++ PluralKit.Bot/Interactive/Button.cs | 25 ++++ PluralKit.Bot/Interactive/YesNoPrompt.cs | 43 ++++++ .../Services/InteractionDispatchService.cs | 8 ++ PluralKit.Bot/Utils/InteractionContext.cs | 22 ++- 12 files changed, 245 insertions(+), 27 deletions(-) create mode 100644 Myriad/Types/Component/ButtonStyle.cs create mode 100644 Myriad/Types/Component/ComponentType.cs rename Myriad/Types/{ => Component}/MessageComponent.cs (60%) create mode 100644 PluralKit.Bot/Interactive/BaseInteractive.cs create mode 100644 PluralKit.Bot/Interactive/Button.cs create mode 100644 PluralKit.Bot/Interactive/YesNoPrompt.cs diff --git a/Myriad/Types/Application/ApplicationCommand.cs b/Myriad/Types/Application/ApplicationCommand.cs index 92ecd856..53f88dd6 100644 --- a/Myriad/Types/Application/ApplicationCommand.cs +++ b/Myriad/Types/Application/ApplicationCommand.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace Myriad.Types +namespace Myriad.Types { public record ApplicationCommand { diff --git a/Myriad/Types/Application/ApplicationCommandInteractionData.cs b/Myriad/Types/Application/ApplicationCommandInteractionData.cs index e9401485..768f9e85 100644 --- a/Myriad/Types/Application/ApplicationCommandInteractionData.cs +++ b/Myriad/Types/Application/ApplicationCommandInteractionData.cs @@ -6,6 +6,6 @@ public string? Name { get; init; } public ApplicationCommandInteractionDataOption[]? Options { get; init; } public string? CustomId { get; init; } - public MessageComponent.ComponentType? ComponentType { get; init; } + public ComponentType? ComponentType { get; init; } } } \ No newline at end of file diff --git a/Myriad/Types/Application/InteractionApplicationCommandCallbackData.cs b/Myriad/Types/Application/InteractionApplicationCommandCallbackData.cs index 2718aa0e..b9ac4372 100644 --- a/Myriad/Types/Application/InteractionApplicationCommandCallbackData.cs +++ b/Myriad/Types/Application/InteractionApplicationCommandCallbackData.cs @@ -1,15 +1,14 @@ -using System.Collections.Generic; - -using Myriad.Rest.Types; +using Myriad.Rest.Types; namespace Myriad.Types { public record InteractionApplicationCommandCallbackData { public bool? Tts { get; init; } - public string Content { get; init; } + public string? Content { get; init; } public Embed[]? Embeds { get; init; } public AllowedMentions? AllowedMentions { get; init; } public Message.MessageFlags Flags { get; init; } + public MessageComponent[]? Components { get; init; } } } \ No newline at end of file diff --git a/Myriad/Types/Component/ButtonStyle.cs b/Myriad/Types/Component/ButtonStyle.cs new file mode 100644 index 00000000..de88ee7e --- /dev/null +++ b/Myriad/Types/Component/ButtonStyle.cs @@ -0,0 +1,11 @@ +namespace Myriad.Types +{ + public enum ButtonStyle + { + Primary = 1, + Secondary = 2, + Success = 3, + Danger = 4, + Link = 5 + } +} \ No newline at end of file diff --git a/Myriad/Types/Component/ComponentType.cs b/Myriad/Types/Component/ComponentType.cs new file mode 100644 index 00000000..5641c08a --- /dev/null +++ b/Myriad/Types/Component/ComponentType.cs @@ -0,0 +1,8 @@ +namespace Myriad.Types +{ + public enum ComponentType + { + ActionRow = 1, + Button = 2 + } +} \ No newline at end of file diff --git a/Myriad/Types/MessageComponent.cs b/Myriad/Types/Component/MessageComponent.cs similarity index 60% rename from Myriad/Types/MessageComponent.cs rename to Myriad/Types/Component/MessageComponent.cs index f68e50c9..4beee8de 100644 --- a/Myriad/Types/MessageComponent.cs +++ b/Myriad/Types/Component/MessageComponent.cs @@ -10,20 +10,5 @@ namespace Myriad.Types public string? Url { get; init; } public bool? Disabled { get; init; } public MessageComponent[]? Components { get; init; } - - public enum ComponentType - { - ActionRow = 1, - Button = 2 - } - - public enum ButtonStyle - { - Primary = 1, - Secondary = 2, - Success = 3, - Danger = 4, - Link = 5 - } } } \ No newline at end of file diff --git a/Myriad/Types/Message.cs b/Myriad/Types/Message.cs index 1b7ec77d..479fca4e 100644 --- a/Myriad/Types/Message.cs +++ b/Myriad/Types/Message.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Net.Mail; using System.Text.Json.Serialization; using Myriad.Utils; diff --git a/PluralKit.Bot/Interactive/BaseInteractive.cs b/PluralKit.Bot/Interactive/BaseInteractive.cs new file mode 100644 index 00000000..36cbf29f --- /dev/null +++ b/PluralKit.Bot/Interactive/BaseInteractive.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +using Autofac; + +using Myriad.Rest.Types.Requests; +using Myriad.Types; + +using NodaTime; + +namespace PluralKit.Bot.Interactive +{ + public abstract class BaseInteractive + { + private readonly Context _ctx; + private readonly List