From cab6240cbfda640fd64890c48ebea96661b152d4 Mon Sep 17 00:00:00 2001 From: Davran Dilshat Date: Wed, 29 Sep 2021 23:26:26 +0100 Subject: [PATCH] begin adding flow for adding select menus --- wow2.Bot/BotService.cs | 7 +++++ wow2.Bot/Verbose/Messages/ActionSelectMenu.cs | 24 +++++++++++++++ .../Messages/ActionSelectMenuOption.cs | 17 +++++++++++ .../Verbose/Messages/InteractiveMessage.cs | 29 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 wow2.Bot/Verbose/Messages/ActionSelectMenu.cs create mode 100644 wow2.Bot/Verbose/Messages/ActionSelectMenuOption.cs diff --git a/wow2.Bot/BotService.cs b/wow2.Bot/BotService.cs index b8eafd9a..5307a814 100644 --- a/wow2.Bot/BotService.cs +++ b/wow2.Bot/BotService.cs @@ -159,6 +159,7 @@ public static async Task ReadyAsync() Client.JoinedGuild += JoinedGuildAsync; Client.LeftGuild += LeftGuildAsync; Client.ButtonExecuted += ButtonExecutedAsync; + Client.SelectMenuExecuted += SelectMenuExecuted; } } @@ -264,6 +265,12 @@ public static Task ButtonExecutedAsync(SocketMessageComponent component) return Task.CompletedTask; } + public static Task SelectMenuExecuted(SocketMessageComponent component) + { + _ = InteractiveMessage.ActOnSelectMenuAsync(component); + return Task.CompletedTask; + } + public static async Task MessageRecievedAsync(SocketMessage socketMessage) { if (socketMessage.Author.Id == Client.CurrentUser.Id) diff --git a/wow2.Bot/Verbose/Messages/ActionSelectMenu.cs b/wow2.Bot/Verbose/Messages/ActionSelectMenu.cs new file mode 100644 index 00000000..3f36ab02 --- /dev/null +++ b/wow2.Bot/Verbose/Messages/ActionSelectMenu.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Discord.WebSocket; + +namespace wow2.Bot.Verbose.Messages +{ + public class ActionSelectMenu + { + public string Placeholder { get; set; } + + public List Options { get; set; } + + public int MinValues { get; set; } = 1; + + public int MaxValues { get; set; } = 1; + + public bool Disabled { get; set; } + + public int Row { get; set; } + + public Func Action { get; set; } + } +} \ No newline at end of file diff --git a/wow2.Bot/Verbose/Messages/ActionSelectMenuOption.cs b/wow2.Bot/Verbose/Messages/ActionSelectMenuOption.cs new file mode 100644 index 00000000..9ffdc89f --- /dev/null +++ b/wow2.Bot/Verbose/Messages/ActionSelectMenuOption.cs @@ -0,0 +1,17 @@ +using Discord; + +namespace wow2.Bot.Verbose.Messages +{ + public class ActionSelectMenuOption + { + public string Label { get; set; } + + public string Value => Label; + + public string Description { get; set; } + + public IEmote Emote { get; set; } + + public bool Default { get; set; } + } +} \ No newline at end of file diff --git a/wow2.Bot/Verbose/Messages/InteractiveMessage.cs b/wow2.Bot/Verbose/Messages/InteractiveMessage.cs index f6edd5a8..55792d9f 100644 --- a/wow2.Bot/Verbose/Messages/InteractiveMessage.cs +++ b/wow2.Bot/Verbose/Messages/InteractiveMessage.cs @@ -49,10 +49,21 @@ public static async Task ActOnButtonAsync(SocketMessageComponent component return false; } + public static async Task ActOnSelectMenuAsync(SocketMessageComponent component) + { + var interactiveMessage = FromMessageId(DataManager.AllGuildData[component.Channel.GetGuild().Id], component.Message.Id); + if (interactiveMessage == null) + return false; + + return false; + } + public List ExtraActionButtons { get; set; } = new(); protected virtual ActionButton[] ActionButtons => Array.Empty(); + protected virtual ActionSelectMenu[] ActionSelectMenu => Array.Empty(); + /// Gets all the objects that will be sent with the message. public ActionButton[] GetActionButtons() => ActionButtons.Concat(ExtraActionButtons).ToArray(); @@ -111,6 +122,24 @@ private ComponentBuilder GetComponentBuilder(bool forceDisableActions = false) row: button.Row); } + foreach (var select in ActionSelectMenu) + { + components.WithSelectMenu( + label: "This is a label!", + customId: GetHashCode().ToString(), + options: select.Options.ConvertAll(o => new SelectMenuOptionBuilder( + label: o.Label, + value: o.Value, + description: o.Description, + emote: o.Emote, + @default: o.Default)), + placeholder: select.Placeholder, + minValues: select.MinValues, + maxValues: select.MaxValues, + disabled: select.Disabled, + row: select.Row); + } + return components; } }