open System open System.Threading.Tasks open DSharpPlus.Entities open DSharpPlus open DSharpPlus.EventArgs open DSharpPlus.SlashCommands open DegenzGame.Shared open Emzi0767.Utilities open Newtonsoft.Json module Commands = let constructItemButtons playerInfo (items : 'a array) = items |> Seq.map (fun item -> DiscordButtonComponent(ButtonStyle.Primary, $"{playerInfo}-{item}", $"{item}")) let viewStore (ctx : InteractionContext) = async { let builder = DiscordInteractionResponseBuilder() try let file = System.IO.File.ReadAllText("Items.json") JsonConvert.DeserializeObject(file) |> Array.groupBy (fun (i : Item) -> i.ItemType) |> Array.iter (fun ( itemType , items ) -> let itemList = items |> Array.map (fun i -> $"{i.Name} - {i.Cost} GBT") |> String.concat "\n" builder.AddEmbed (constructEmbed $"{itemType}:\n{itemList}") |> ignore) with _ -> builder.Content <- "System error preparing inventory for viewing" builder.AsEphemeral true |> ignore do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder) |> Async.AwaitTask } |> Async.StartAsTask :> Task let buyHack (ctx : InteractionContext) hackId = async { return () } |> Async.StartAsTask :> Task let buyShield (ctx : InteractionContext) shieldId = async { return () } |> Async.StartAsTask :> Task let sellItem (ctx : InteractionContext) = async { return () } |> Async.StartAsTask :> Task type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule () type Store() = inherit ApplicationCommandModule () [] member _.ViewStore (ctx : InteractionContext) = Commands.viewStore ctx [] member _.BuyHack (ctx : InteractionContext, [] hackId : Weapon) = Commands.buyHack ctx hackId [] member this.BuyShield (ctx : InteractionContext, [] shieldId : Shield) = Commands.buyShield ctx shieldId [] member this.SellItem (ctx : InteractionContext) = Commands.sellItem ctx let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) = async { let builder = DiscordInteractionResponseBuilder() builder.IsEphemeral <- true builder.Content <- $"" do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder) |> Async.AwaitTask } |> Async.StartAsTask :> Task let config = DiscordConfiguration() config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk" config.TokenType <- TokenType.Bot config.Intents <- DiscordIntents.All //config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace let client = new DiscordClient(config) client.add_ComponentInteractionCreated(AsyncEventHandler(handleButtonEvent)) let slash = client.UseSlashCommands() // My server slash.RegisterCommands(922419263275425832uL); // Degenz //slash.RegisterCommands(922414052708327494uL); client.ConnectAsync () |> Async.AwaitTask |> Async.RunSynchronously Task.Delay(-1) |> Async.AwaitTask |> Async.RunSynchronously client.DisconnectAsync () |> Async.AwaitTask |> Async.RunSynchronously