diff --git a/PlayerInteractions/Program.fs b/PlayerInteractions/Program.fs index 06546c5..57393d4 100644 --- a/PlayerInteractions/Program.fs +++ b/PlayerInteractions/Program.fs @@ -8,18 +8,18 @@ open DegenzGame.Shared module Commands = let newPlayer nickname (membr : uint64) = - let h1 = [| Weapon.Virus ; Weapon.Ransom |] - let h2 = [| Weapon.DDos ; Weapon.Worm |] - let h3 = [| Weapon.Crack ; Weapon.Injection |] - let d1 = [| Shield.Firewall ; Shield.PortScan |] - let d2 = [| Shield.Encryption ; Shield.Cypher |] - let d3 = [| Shield.Hardening ; Shield.Sanitation |] +// let h1 = [| Weapon.Virus ; Weapon.Ransom |] +// let h2 = [| Weapon.DDos ; Weapon.Worm |] +// let h3 = [| Weapon.Crack ; Weapon.Injection |] +// let d1 = [| Shield.Firewall ; Shield.PortScan |] +// let d2 = [| Shield.Encryption ; Shield.Cypher |] +// let d3 = [| Shield.Hardening ; Shield.Sanitation |] let rand = System.Random(System.Guid.NewGuid().GetHashCode()) - let getRandom (actions : 'a array) = actions.[rand.Next(0,2)] + let getRandom (actions : 'a array) = actions.[rand.Next(0, Math.Max(0, actions.Length - 1))] - let weapons = [| getRandom h1 ; getRandom h2 ; getRandom h3 |] - let shields = [| getRandom d1 ; getRandom d2 ; getRandom d3 |] + let weapons = [| getRandom weaponInventory |] + let shields = [| getRandom shieldInventory |] { DiscordId = membr Name = nickname diff --git a/Shared/Shared.fs b/Shared/Shared.fs index f6657e2..2f3a5be 100644 --- a/Shared/Shared.fs +++ b/Shared/Shared.fs @@ -5,6 +5,10 @@ open DSharpPlus open DSharpPlus.Entities open DSharpPlus.SlashCommands +type ItemType = + | Weapon = 0 + | Shield = 1 + type ActionClass = | Network | Exploit @@ -63,6 +67,10 @@ type Player = Defenses: Defense array Bank: single } + +let weaponInventory = [| Weapon.Virus ; Weapon.Ransom ; Weapon.DDos ; Weapon.Worm ; Weapon.Crack ; Weapon.Injection |] +let shieldInventory = [| Shield.Firewall ; Shield.PortScan ; Shield.Encryption ; Shield.Cypher ; Shield.Hardening ; Shield.Sanitation |] + let createSimpleResponseAsync msg (ctx: InteractionContext) = async { let builder = DiscordInteractionResponseBuilder() diff --git a/Store/Program.fs b/Store/Program.fs index f115430..1aff4a7 100644 --- a/Store/Program.fs +++ b/Store/Program.fs @@ -1,4 +1,107 @@ +open System +open System.Threading.Tasks +open DSharpPlus.Entities +open DSharpPlus +open DSharpPlus.EventArgs +open DSharpPlus.SlashCommands +open DegenzGame +open DegenzGame.Shared +open Emzi0767.Utilities +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() + let hacks = weaponInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n" + builder.AddEmbed (constructEmbed $"Hacks:\n{hacks}") |> ignore + let shields = shieldInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n" + builder.AddEmbed (constructEmbed $"Shields:\n{shields}") |> ignore + + 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 -// For more information see https://aka.ms/fsharp-console-apps -printfn "Hello from F#" \ No newline at end of file