Bring store back and fix typos
This commit is contained in:
parent
ad613064a8
commit
87e0c063a8
69
Bot/Store.fs
69
Bot/Store.fs
@ -1,6 +1,5 @@
|
|||||||
module Degenz.Store
|
module Degenz.Store
|
||||||
|
|
||||||
open System
|
|
||||||
open System.Threading.Tasks
|
open System.Threading.Tasks
|
||||||
open DSharpPlus.Entities
|
open DSharpPlus.Entities
|
||||||
open DSharpPlus
|
open DSharpPlus
|
||||||
@ -17,16 +16,23 @@ let viewStore (ctx : InteractionContext) =
|
|||||||
} |> Async.StartAsTask
|
} |> Async.StartAsTask
|
||||||
:> Task
|
:> Task
|
||||||
|
|
||||||
let buyItem (ctx : InteractionContext) itemType =
|
let buyItem (ctx : InteractionContext) itemId =
|
||||||
Game.executePlayerInteraction ctx (fun player -> async {
|
Game.executePlayerInteraction ctx (fun player -> async {
|
||||||
let embed = DiscordEmbedBuilder()
|
let item = Armory.getItem itemId
|
||||||
|
let newBalance = player.Bank - item.Cost
|
||||||
// embed.Fields
|
if newBalance >= 0<GBT> then
|
||||||
|
let playerHasItem = player.Arsenal |> Array.exists (fun w -> item.Id = w.Id)
|
||||||
do! ctx.CreateResponseAsync(embed, true)
|
if not playerHasItem then
|
||||||
|> Async.AwaitTask
|
let p = { player with Bank = newBalance ; Arsenal = Array.append [| item |] player.Arsenal }
|
||||||
|
do! DbService.updatePlayer p
|
||||||
|
do! sendSimpleResponse ctx $"Successfully purchased {item.Name}! You now have {newBalance} remaining"
|
||||||
|
else
|
||||||
|
do! sendSimpleResponse ctx $"You already own this item!"
|
||||||
|
else
|
||||||
|
do! sendSimpleResponse ctx $"You do not have sufficient funds to buy this item! Current balance: {player.Bank} GBT"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
let sell (ctx : InteractionContext) =
|
let sell (ctx : InteractionContext) =
|
||||||
Game.executePlayerInteraction ctx (fun player -> async {
|
Game.executePlayerInteraction ctx (fun player -> async {
|
||||||
let hasInventoryToSell = Array.length player.Arsenal > 0
|
let hasInventoryToSell = Array.length player.Arsenal > 0
|
||||||
@ -50,18 +56,6 @@ let sell (ctx : InteractionContext) =
|
|||||||
do! sendSimpleResponse ctx "You currently have no inventory to sell"
|
do! sendSimpleResponse ctx "You currently have no inventory to sell"
|
||||||
})
|
})
|
||||||
|
|
||||||
let sellItem (event : ComponentInteractionCreateEventArgs) player itemId =
|
|
||||||
async {
|
|
||||||
let item = Armory.battleItems |> Array.find (fun i -> i.Id = itemId)
|
|
||||||
let updatedPlayer = { player with Bank = player.Bank + item.Cost ; Arsenal = player.Arsenal |> Array.filter (fun w -> w.Id <> itemId)}
|
|
||||||
do! DbService.updatePlayer updatedPlayer
|
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
|
||||||
builder.IsEphemeral <- true
|
|
||||||
builder.Content <- $"Sold {item.Type} {item.Name} for {item.Cost}! Current Balance: {updatedPlayer.Bank}"
|
|
||||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
|
||||||
|> Async.AwaitTask
|
|
||||||
}
|
|
||||||
|
|
||||||
let handleBuyItem (ctx : InteractionContext) itemId =
|
let handleBuyItem (ctx : InteractionContext) itemId =
|
||||||
Game.executePlayerInteraction ctx (fun player -> async {
|
Game.executePlayerInteraction ctx (fun player -> async {
|
||||||
let item = Armory.battleItems |> Array.find (fun w -> w.Id = itemId)
|
let item = Armory.battleItems |> Array.find (fun w -> w.Id = itemId)
|
||||||
@ -79,20 +73,17 @@ let handleBuyItem (ctx : InteractionContext) itemId =
|
|||||||
})
|
})
|
||||||
|
|
||||||
let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
||||||
async {
|
Game.executePlayerEvent event (fun player -> async {
|
||||||
let! playerResult = DbService.tryFindPlayer event.User.Id
|
let itemId = int <| event.Id.Split("-").[1]
|
||||||
match playerResult with
|
let item = Armory.getItem itemId
|
||||||
| Some player ->
|
let updatedPlayer = { player with Bank = player.Bank + item.Cost ; Arsenal = player.Arsenal |> Array.filter (fun w -> w.Id <> itemId)}
|
||||||
let itemId = int <| event.Id.Split("-").[1]
|
do! DbService.updatePlayer updatedPlayer
|
||||||
do! sellItem event player itemId
|
let builder = DiscordInteractionResponseBuilder()
|
||||||
| None ->
|
builder.IsEphemeral <- true
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
builder.Content <- $"Sold {item.Type} {item.Name} for {item.Cost}! Current Balance: {updatedPlayer.Bank}"
|
||||||
builder.IsEphemeral <- true
|
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
||||||
builder.Content <- "An error occurred and the user doesn't not exist"
|
|> Async.AwaitTask
|
||||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
})
|
||||||
|> Async.AwaitTask
|
|
||||||
} |> Async.StartAsTask
|
|
||||||
:> Task
|
|
||||||
|
|
||||||
let status (ctx : InteractionContext) =
|
let status (ctx : InteractionContext) =
|
||||||
Game.executePlayerInteraction ctx (fun player -> async {
|
Game.executePlayerInteraction ctx (fun player -> async {
|
||||||
@ -110,18 +101,20 @@ let status (ctx : InteractionContext) =
|
|||||||
|
|
||||||
type Store() =
|
type Store() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
// [<SlashCommand("view-store", "View items available for purchase")>]
|
|
||||||
|
|
||||||
// member _.ViewStore (ctx : InteractionContext) = viewStore ctx
|
[<SlashCommand("armory", "View Hacks & Shields available for purchase")>]
|
||||||
|
member _.Armory (ctx : InteractionContext) = viewStore ctx
|
||||||
|
|
||||||
[<SlashCommand("arsenal", "Get the Hacks and Shields you own, and which ones are active")>]
|
[<SlashCommand("arsenal", "Get the Hacks and Shields you own, and which ones are active")>]
|
||||||
member this.Arsenal (ctx : InteractionContext) = status ctx
|
member this.Arsenal (ctx : InteractionContext) = status ctx
|
||||||
|
|
||||||
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
||||||
member _.BuyHack (ctx : InteractionContext) = buyItem ctx Hack
|
member _.BuyHack (ctx : InteractionContext, [<Option("hack-id", "The ID of the hack you wish to purchase")>] hackId : HackId) =
|
||||||
|
buyItem ctx (int hackId)
|
||||||
|
|
||||||
[<SlashCommand("buy-shield", "Purchase a hack shield so you can protect your GoodBoyTokenz")>]
|
[<SlashCommand("buy-shield", "Purchase a hack shield so you can protect your GoodBoyTokenz")>]
|
||||||
member this.BuyShield (ctx : InteractionContext) = buyItem ctx Shield
|
member this.BuyShield (ctx : InteractionContext, [<Option("shield-id", "The ID of the shield you wish to purchase")>] shieldId : ShieldId) =
|
||||||
|
buyItem ctx (int shieldId)
|
||||||
|
|
||||||
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
||||||
member this.SellItem (ctx : InteractionContext) = sell ctx
|
member this.SellItem (ctx : InteractionContext) = sell ctx
|
||||||
|
@ -34,8 +34,8 @@ let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) =
|
|||||||
|
|
||||||
let shieldMessage =
|
let shieldMessage =
|
||||||
if Player.shields player |> Array.isEmpty
|
if Player.shields player |> Array.isEmpty
|
||||||
then $"You do not have any Shields in your arsenal, take this {defaultShield.Name}, you can use it for now"
|
then $"You do not have any Shields in your arsenal, take this {defaultShield.Name}, you can use it for now.\n\n"
|
||||||
else $"Looks like you have `{weaponName}` in your arsenal… 👀\n"
|
else $"Looks like you have `{weaponName}` in your arsenal… 👀\n\n"
|
||||||
|
|
||||||
do! sendInteractionEvent event
|
do! sendInteractionEvent event
|
||||||
("Beautopia© is a dangerous place...\n"
|
("Beautopia© is a dangerous place...\n"
|
||||||
@ -89,8 +89,8 @@ let handleTrainerStep3 (event : ComponentInteractionCreateEventArgs) =
|
|||||||
|
|
||||||
let hackMessage =
|
let hackMessage =
|
||||||
if Player.shields player |> Array.isEmpty
|
if Player.shields player |> Array.isEmpty
|
||||||
then $"You do not have any Hacks in your arsenal, take this {defaultHack.Name}, you can use it for now"
|
then $"You do not have any Hacks in your arsenal, take this {defaultHack.Name}, you can use it for now.\n\n"
|
||||||
else $"Looks like you have `{weaponName}` in your arsenal..."
|
else $"Looks like you have `{weaponName}` in your arsenal...\n\n"
|
||||||
|
|
||||||
do! sendFollowUpMessage event
|
do! sendFollowUpMessage event
|
||||||
("Now let’s **HACK!** 💻\n\n"
|
("Now let’s **HACK!** 💻\n\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user