Store: view store command, create semblance of an inventory
This commit is contained in:
parent
5ab49e674e
commit
f92e253dac
@ -8,18 +8,18 @@ open DegenzGame.Shared
|
|||||||
|
|
||||||
module Commands =
|
module Commands =
|
||||||
let newPlayer nickname (membr : uint64) =
|
let newPlayer nickname (membr : uint64) =
|
||||||
let h1 = [| Weapon.Virus ; Weapon.Ransom |]
|
// let h1 = [| Weapon.Virus ; Weapon.Ransom |]
|
||||||
let h2 = [| Weapon.DDos ; Weapon.Worm |]
|
// let h2 = [| Weapon.DDos ; Weapon.Worm |]
|
||||||
let h3 = [| Weapon.Crack ; Weapon.Injection |]
|
// let h3 = [| Weapon.Crack ; Weapon.Injection |]
|
||||||
let d1 = [| Shield.Firewall ; Shield.PortScan |]
|
// let d1 = [| Shield.Firewall ; Shield.PortScan |]
|
||||||
let d2 = [| Shield.Encryption ; Shield.Cypher |]
|
// let d2 = [| Shield.Encryption ; Shield.Cypher |]
|
||||||
let d3 = [| Shield.Hardening ; Shield.Sanitation |]
|
// let d3 = [| Shield.Hardening ; Shield.Sanitation |]
|
||||||
|
|
||||||
let rand = System.Random(System.Guid.NewGuid().GetHashCode())
|
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 weapons = [| getRandom weaponInventory |]
|
||||||
let shields = [| getRandom d1 ; getRandom d2 ; getRandom d3 |]
|
let shields = [| getRandom shieldInventory |]
|
||||||
|
|
||||||
{ DiscordId = membr
|
{ DiscordId = membr
|
||||||
Name = nickname
|
Name = nickname
|
||||||
|
@ -5,6 +5,10 @@ open DSharpPlus
|
|||||||
open DSharpPlus.Entities
|
open DSharpPlus.Entities
|
||||||
open DSharpPlus.SlashCommands
|
open DSharpPlus.SlashCommands
|
||||||
|
|
||||||
|
type ItemType =
|
||||||
|
| Weapon = 0
|
||||||
|
| Shield = 1
|
||||||
|
|
||||||
type ActionClass =
|
type ActionClass =
|
||||||
| Network
|
| Network
|
||||||
| Exploit
|
| Exploit
|
||||||
@ -63,6 +67,10 @@ type Player =
|
|||||||
Defenses: Defense array
|
Defenses: Defense array
|
||||||
Bank: single }
|
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) =
|
let createSimpleResponseAsync msg (ctx: InteractionContext) =
|
||||||
async {
|
async {
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
let builder = DiscordInteractionResponseBuilder()
|
||||||
|
107
Store/Program.fs
107
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 ()
|
||||||
|
|
||||||
|
[<SlashCommand("store", "View items available for purchase")>]
|
||||||
|
member _.ViewStore (ctx : InteractionContext) = Commands.viewStore ctx
|
||||||
|
|
||||||
|
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
||||||
|
member _.BuyHack (ctx : InteractionContext, [<Option("hack-id", "The ID of the hack you wish to purchase")>] hackId : Weapon) =
|
||||||
|
Commands.buyHack ctx hackId
|
||||||
|
|
||||||
|
[<SlashCommand("buy-shield", "Purchase a hack shield so you can protect your GoodBoyTokenz")>]
|
||||||
|
member this.BuyShield (ctx : InteractionContext, [<Option("shield-id", "The ID of the shield you wish to purchase")>] shieldId : Shield) =
|
||||||
|
Commands.buyShield ctx shieldId
|
||||||
|
|
||||||
|
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
||||||
|
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<Store>(922419263275425832uL);
|
||||||
|
// Degenz
|
||||||
|
//slash.RegisterCommands<HackerGame>(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#"
|
|
Loading…
x
Reference in New Issue
Block a user