diff --git a/Bot/Admin.fs b/Bot/Admin.fs index ca85ce7..824e632 100644 --- a/Bot/Admin.fs +++ b/Bot/Admin.fs @@ -151,7 +151,7 @@ type AdminBot() = [] [] member this.SetStock (ctx : InteractionContext, [] amount : int64) = - enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setCurrentWhitelistStock (int amount)) + enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setCurrentWhitelistStock (int amount * 1)) [] [] diff --git a/Bot/DbService.fs b/Bot/DbService.fs index 4d307a7..83eb8bb 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -79,6 +79,16 @@ let addToPlayerInventory (did : uint64) (item : Item) = |> Sql.executeNonQueryAsync |> Async.AwaitTask +let removeFromPlayerInventory (did : uint64) (item : Item) = + connStr + |> Sql.connect + |> Sql.parameters [ ( "@did" , Sql.string (string did) ) ; ( "iid" , Sql.string item.Id )] + |> Sql.query """ + DELETE FROM inventory_item WHERE item_id = @iid AND user_id = @did + """ + |> Sql.executeNonQueryAsync + |> Async.AwaitTask + let getStoreSymbol (storeId : string) = connStr |> Sql.connect @@ -109,18 +119,71 @@ let getStoreItems (storeId : string) = }) |> Async.AwaitTask -let decrementItemStock (item : Item) = +let getStoreItemBySymbol (itemSymbol : string) = connStr |> Sql.connect - |> Sql.parameters [ ( "iid" , Sql.string item.Id) ] + |> Sql.parameters [ "iid", Sql.string itemSymbol ] |> Sql.query """ - UPDATE store_item SET stock = GREATEST(stock - 1, 0) + SELECT store_id,stock,available,limit_stock,i.id,name,description,icon_url,image_url,category,buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume, + attack_power,defense_power,class_name,max_stack,mods + FROM store_item + JOIN item i on store_item.item_id = i.id + WHERE item_id = @iid; + """ + |> Sql.executeRowAsync (fun reader -> { + StoreId = reader.string "store_id" + Stock = reader.int "stock" + LimitStock = reader.bool "limit_stock" + Available = reader.bool "available" + StoreItem.Item = readItem reader + }) + |> Async.AwaitTask + +let decrementItemStock (item : Item) = async { + try + do! connStr + |> Sql.connect + |> Sql.parameters [ ( "iid" , Sql.string item.Id) ] + |> Sql.query """ + UPDATE store_item SET stock = GREATEST(stock - 1, 0) + WHERE store_item.item_id = @iid + """ + |> Sql.executeNonQueryAsync + |> Async.AwaitTask + |> Async.Ignore + return true + with _ -> return false +} + +let incrementItemStock (amount : int) symbol = + connStr + |> Sql.connect + |> Sql.parameters [ ( "iid" , Sql.string symbol) ] + |> Sql.parameters [ ( "amount" , Sql.int (int amount)) ] + |> Sql.query """ + UPDATE store_item SET stock = stock + @amount WHERE store_item.item_id = @iid """ |> Sql.executeNonQueryAsync |> Async.AwaitTask |> Async.Ignore +let setItemStock (amount : int) symbol = async { + try + do! connStr + |> Sql.connect + |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] + |> Sql.parameters [ ( "iid" , Sql.string symbol ) ] + |> Sql.query """ + UPDATE store_item SET stock = @amount + WHERE store_item.item_id = (SELECT id FROM item WHERE id = @iid) + """ + |> Sql.executeNonQueryAsync + |> Async.AwaitTask + |> Async.Ignore + return true + with _ -> return false +} let getWeapons () = connStr |> Sql.connect @@ -234,11 +297,11 @@ let tryFindPlayer (discordId : uint64) = async { return None } -let updatePlayerCurrency (addAmount : int) (player : PlayerData) = +let updatePlayerCurrency (addAmount : int) (did : uint64) = connStr |> Sql.connect |> Sql.parameters [ - "did", Sql.string (string player.DiscordId) + "did", Sql.string (string did) "gbt", Sql.int (int addAmount) ] |> Sql.query """ UPDATE "user" SET gbt = gbt + GREATEST(gbt + @gbt, 0) WHERE discord_id = @did; diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs index dbc1fe8..3e60d4c 100644 --- a/Bot/GameHelpers.fs +++ b/Bot/GameHelpers.fs @@ -1,7 +1,6 @@ namespace Degenz open System -open System.Threading open DSharpPlus open DSharpPlus.Entities open Degenz @@ -18,6 +17,8 @@ module Inventory = let findItemById id (inventory : Inventory) = inventory |> List.find (fun item -> item.Id = id) + let getBuyPrice item = match item.Attributes with CanBuy price -> price | _ -> 0 + let getHackItem item = match item.Type , item.Attributes with | ItemType.Hack , CanBuy buyPrice & CanSell _ & CanAttack power & CanRateLimit cooldown & CanClass ``class``-> diff --git a/Bot/Games/SlotMachine.fs b/Bot/Games/SlotMachine.fs index 846fddd..c3d1926 100644 --- a/Bot/Games/SlotMachine.fs +++ b/Bot/Games/SlotMachine.fs @@ -125,38 +125,6 @@ let sleepTime = 1500 let mutable guildEmojis : Map option = None let mutable anyEmoji : DiscordEmoji option = None -let getJackpotAmount () = - GuildEnvironment.connectionString - |> Sql.connect - |> Sql.query """ - SELECT stock FROM store_item - WHERE store_item.item_id = (SELECT id FROM item WHERE id = 'JACKPOT') - """ - |> Sql.executeRowAsync (fun read -> (read.int "stock") * 1) - |> Async.AwaitTask - -let incrementJackpot amount = - GuildEnvironment.connectionString - |> Sql.connect - |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] - |> Sql.query """ - UPDATE store_item SET stock = stock + @amount - WHERE store_item.item_id = (SELECT id FROM item WHERE id = 'JACKPOT') - """ - |> Sql.executeNonQueryAsync - |> Async.AwaitTask - -let resetJackpot amount = - GuildEnvironment.connectionString - |> Sql.connect - |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] - |> Sql.query """ - UPDATE store_item SET stock = @amount - WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'JACKPOT') - """ - |> Sql.executeNonQueryAsync - |> Async.AwaitTask - let getLastPlayedSlotFromPlayer (did : uint64) = async { let! events = GuildEnvironment.connectionString @@ -205,10 +173,10 @@ let handlePrizeTable (ctx : IDiscordContext) = else $"{acc}\n{line} | {prizeTxt}" (i + 1) , text - let! jackpot = getJackpotAmount () + let! jackpot = DbService.getStoreItemBySymbol "WHITELIST" let _ , rows = Array.fold folder (0, "") prizeTable embed.Color <- DiscordColor.Green - embed.Title <- $"CURRENT JACKPOT: `{jackpot} 💰 $GBT`" + embed.Title <- $"CURRENT JACKPOT: `{jackpot.Stock} 💰 $GBT`" embed.Description <- embed.Description + $"\n\n**PRIZE TABLE **\n{rows}\n\n**ANY SAME 3** | **100** $GBT" do! ctx.FollowUp(DiscordFollowupMessageBuilder().AsEphemeral().AddEmbed(embed)) do! Analytics.prizeTableViewed (ctx.GetDiscordMember()) @@ -247,8 +215,8 @@ let spin multiplier (ctx : IDiscordContext) = | 1 -> PlayPricex1 | 2 -> PlayPricex2 | _ -> PlayPricex3 - let execute player = async { - do! DbService.updatePlayerCurrency -playAmount player |> Async.Ignore + let execute (player : PlayerData) = async { + do! DbService.updatePlayerCurrency -playAmount player.DiscordId |> Async.Ignore let random = System.Random(System.Guid.NewGuid().GetHashCode()) let results = [| reel1.[random.Next(0, reel1.Length)] ; reel2.[random.Next(0, reel2.Length)] ; reel3.[random.Next(0, reel3.Length)] |] @@ -288,7 +256,7 @@ let spin multiplier (ctx : IDiscordContext) = match prize with | Some (Money amount) -> let prizeWithMultiplier = amount * multiplier - do! DbService.updatePlayerCurrency prizeWithMultiplier player |> Async.Ignore + do! DbService.updatePlayerCurrency prizeWithMultiplier player.DiscordId |> Async.Ignore embed.Color <- DiscordColor.Green embed.Description <- $"You WIN `💰` **{prizeWithMultiplier}** GBT 🎉" embed.AddField("Bet", $"{playAmount}", true) |> ignore @@ -298,17 +266,17 @@ let spin multiplier (ctx : IDiscordContext) = // do! incrementJackpot multiplier |> Async.Ignore return "WON" , prizeWithMultiplier | Some (Jackpot) -> - let! jackpot = getJackpotAmount () + let! jackpot = DbService.getStoreItemBySymbol "JACKPOT" embed.Color <- DiscordColor.Green embed.Description <- $"🎉🎉 YOU HIT THE JACKPOT 🎉🎉" embed.AddField("Bet", $"{playAmount}", true) |> ignore embed.AddField("Prize", $"{jackpot}", true) |> ignore - addGBTField embed jackpot - do! DbService.updatePlayerCurrency jackpot player |> Async.Ignore - do! resetJackpot BaseJackpotAmount |> Async.Ignore - return "JACKPOT" , jackpot + addGBTField embed (Inventory.getBuyPrice jackpot.Item) + do! DbService.updatePlayerCurrency (Inventory.getBuyPrice jackpot.Item) player.DiscordId |> Async.Ignore + do! DbService.setItemStock BaseJackpotAmount "JACKPOT" |> Async.Ignore + return "JACKPOT" , Inventory.getBuyPrice jackpot.Item | None -> - do! incrementJackpot 1 |> Async.Ignore + do! DbService.incrementItemStock 1 "JACKPOT" |> Async.Ignore embed.Description <- $"You LOST `💰` **{playAmount}** $GBT 😭" embed.Color <- DiscordColor.Red embed.AddField("Bet", $"{playAmount}", true) |> ignore @@ -367,7 +335,7 @@ let handleButton (_ : DiscordClient) (event : ComponentInteractionCreateEventArg let handleGuildDownloadCompleted (_ : DiscordClient) (event : GuildDownloadCompletedEventArgs) = task { - let ( result , guild ) = event.Guilds.TryGetValue(GuildEnvironment.guildId) + let ( _ , guild ) = event.Guilds.TryGetValue(GuildEnvironment.guildId) guildEmojis <- guild.Emojis |> Seq.map (fun kvp -> kvp.Value) |> Seq.toArray @@ -393,8 +361,8 @@ let sendEmbed (jackpotNumChannel : DiscordChannel) slotsChannel (message : Disco embed.Title <- "Degenz Slot Machine" embed.ImageUrl <- "https://s7.gifyu.com/images/ezgif.com-gif-maker-268ecb6e4d28bd55a0.gif" embed.Description <- "Try Your Hand at a Game of SLOTS!\nEvery Spin Adds to The JACKPOT!\nGood luck Degenz ✊" - let! jackpot = getJackpotAmount () - embed.Title <- $"CURRENT JACKPOT: `{jackpot} 💰 $GBT`" + let! jackpot = DbService.getStoreItemBySymbol "JACKPOT" + embed.Title <- $"CURRENT JACKPOT: `{jackpot.Stock} 💰 $GBT`" // Update Jackpot channel // try diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs index 6a2362d..118cc78 100644 --- a/Bot/Games/Store.fs +++ b/Bot/Games/Store.fs @@ -10,6 +10,43 @@ open Degenz open Degenz.Messaging open Degenz.PlayerInteractions +let checkHasStock (item : StoreItem) player = + if item.Stock > 0 || item.LimitStock = false + then Ok player + else Error $"{item.Item.Name} is out of stock! Check back later to purchase" + +let checkHasSufficientFunds (item : Item) player = + match item.Attributes with + | CanBuy price -> + if player.Bank - price >= 0 + then Ok player + else Error $"You do not have sufficient funds to buy this item! Current balance: {player.Bank} GBT" + | _ -> Error $"{item.Name} item cannot be bought" + +let checkDoesntExceedStackCap (item : Item) player = + let itemCount = + player.Inventory + |> List.countBy (fun i -> i.Id) + |> List.tryFind (fst >> ((=) item.Id)) + |> Option.map snd + match item.Attributes , itemCount with + | CanStack max , Some count -> + if count >= max + then Error $"You own the maximum allowed amount {item.Name}!" + else Ok player + | _ , Some _ -> Error $"You already own this item" + | _ -> Ok player + +let checkSoldItemAlready (item : Item) player = + if player.Inventory |> List.exists (fun i -> item.Id = i.Id) + then Ok player + else Error $"{item.Name} not found in your inventory! Looks like you sold it already." + +let checkHasItemsInArsenal itemType items player = + if List.isEmpty items |> not + then Ok player + else Error $"You currently have no {itemType} in your arsenal to sell!" + let getItemEmbeds owned (items : StoreItem list) = items |> List.countBy (fun item -> item.Item.Id) @@ -80,6 +117,19 @@ let getBuyItemsEmbed storeId (playerInventory : Inventory) (storeInventory : Sto |> List.iter (fun btns -> builder.AddComponents(btns) |> ignore) builder +let purchaseItemEmbed (item : Item) = + let embed = DiscordEmbedBuilder() + embed.ImageUrl <- item.IconUrl + embed.Title <- $"Purchased {item.Name}" + match item.Type with + | ItemType.Jpeg -> + if item.Id.Contains "RAFFLE" then + embed.Description <- $"Congratulations! You are in the draw for the {item.Name}. The winner will be announced shortly" + embed.ImageUrl <- item.Description + else + embed.Description <- $"Congratulations! You own the rights to the {item.Name} NFT. Please create a ticket in the support channel and we will transfer to your wallet" + | _ -> embed.Description <- $"Purchased {item.Name}" + embed let getSellEmbed (items : Inventory) = let embeds , buttons = @@ -104,42 +154,15 @@ let getSellEmbed (items : Inventory) = .AddComponents(buttons) .AsEphemeral(true) -let checkHasStock (item : StoreItem) player = - if item.Stock > 0 || item.LimitStock = false - then Ok player - else Error $"{item.Item.Name} is out of stock! Check back later to purchase" - -let checkHasSufficientFunds (item : Item) player = - match item.Attributes with - | CanBuy price -> - if player.Bank - price >= 0 - then Ok player - else Error $"You do not have sufficient funds to buy this item! Current balance: {player.Bank} GBT" - | _ -> Error $"{item.Name} item cannot be bought" - -let checkDoesntExceedStackCap (item : Item) player = - let itemCount = +let showJpegsEmbed (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async { + let jpegs = player.Inventory - |> List.countBy (fun i -> i.Id) - |> List.tryFind (fst >> ((=) item.Id)) - |> Option.map snd - match item.Attributes , itemCount with - | CanStack max , Some count -> - if count >= max - then Error $"You own the maximum allowed amount {item.Name}!" - else Ok player - | _ , Some _ -> Error $"You already own this item" - | _ -> Ok player - -let checkSoldItemAlready (item : Item) player = - if player.Inventory |> List.exists (fun i -> item.Id = i.Id) - then Ok player - else Error $"{item.Name} not found in your inventory! Looks like you sold it already." - -let checkHasItemsInArsenal itemType items player = - if List.isEmpty items |> not - then Ok player - else Error $"You currently have no {itemType} in your arsenal to sell!" + |> Inventory.getItemsByType ItemType.Jpeg + |> List.map (fun i -> { StoreId = "BACKALLEY" ; Item = i ; Stock = 1 ; LimitStock = false ; Available = true }) + let embeds = getItemEmbeds true jpegs + let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true) + do! ctx.FollowUp builder |> Async.AwaitTask +}) let buy storeId (filterBy : ItemType option) (ctx : IDiscordContext) = executePlayerAction ctx (fun player -> async { @@ -168,20 +191,6 @@ let sell itemType getItems (ctx : IDiscordContext) = do! Analytics.buyItemCommand (ctx.GetDiscordMember()) itemType }) -let purchaseItemEmbed (item : Item) = - let embed = DiscordEmbedBuilder() - embed.ImageUrl <- item.IconUrl - embed.Title <- $"Purchased {item.Name}" - match item.Type with - | ItemType.Jpeg -> - if item.Id.Contains "RAFFLE" then - embed.Description <- $"Congratulations! You are in the draw for the {item.Name}. The winner will be announced shortly" - embed.ImageUrl <- item.Description - else - embed.Description <- $"Congratulations! You own the rights to the {item.Name} NFT. Please create a ticket in the support channel and we will transfer to your wallet" - | _ -> embed.Description <- $"Purchased {item.Name}" - embed - // TODO: When you buy a shield, prompt the user to activate it let handleBuyItem (ctx : IDiscordContext) itemId = executePlayerAction ctx (fun player -> async { @@ -195,9 +204,10 @@ let handleBuyItem (ctx : IDiscordContext) itemId = >>= checkDoesntExceedStackCap item |> handleResultWithResponse ctx (fun player -> async { let price = match item.Attributes with CanBuy price -> price | _ -> 0 - do! DbService.updatePlayerCurrency -price player |> Async.Ignore + do! DbService.updatePlayerCurrency -price player.DiscordId |> Async.Ignore do! DbService.addToPlayerInventory player.DiscordId item |> Async.Ignore - do! DbService.decrementItemStock item + if storeItem.LimitStock = true && storeItem.Stock > 0 then + do! DbService.decrementItemStock item |> Async.Ignore let builder = DiscordFollowupMessageBuilder().AsEphemeral(true) builder.AddEmbed(purchaseItemEmbed (item)) |> ignore do! ctx.FollowUp builder |> Async.AwaitTask @@ -214,15 +224,11 @@ let handleSell (ctx : IDiscordContext) itemId = |> handleResultWithResponse ctx (fun player -> async { match item.Attributes with | CanSell price -> - let updatedPlayer = { - player with - Bank = player.Bank + price - Inventory = player.Inventory |> List.filter (fun i -> i.Id <> itemId) - } do! - [ DbService.updatePlayer updatedPlayer |> Async.Ignore - DbService.removeShieldEvent updatedPlayer.DiscordId itemId |> Async.Ignore - sendFollowUpMessage ctx $"Sold {item.Name} for {price}! Current Balance: {updatedPlayer.Bank}" + [ DbService.updatePlayerCurrency price player.DiscordId |> Async.Ignore + DbService.removeFromPlayerInventory player.DiscordId item |> Async.Ignore + DbService.removeShieldEvent player.DiscordId itemId |> Async.Ignore + sendFollowUpMessage ctx $"Sold {item.Name} for {price}! New Balance: {player.Bank + price}" Analytics.sellWeaponButton (ctx.GetDiscordMember()) item price ] |> Async.Parallel |> Async.Ignore @@ -252,16 +258,6 @@ let handleConsume (ctx : IDiscordContext) itemId = PlayerInteractions.executePla do! ctx.FollowUp builder |> Async.AwaitTask }) -let showJpegsEmbed (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async { - let jpegs = - player.Inventory - |> Inventory.getItemsByType ItemType.Jpeg - |> List.map (fun i -> { StoreId = "BACKALLEY" ; Item = i ; Stock = 1 ; LimitStock = false ; Available = true }) - let embeds = getItemEmbeds true jpegs - let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true) - do! ctx.FollowUp builder |> Async.AwaitTask -}) - let showStats (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async { let embed = DiscordEmbedBuilder() PlayerStats.stats diff --git a/Bot/InviteTracker.fs b/Bot/InviteTracker.fs index 88bd2f8..51ec0ff 100644 --- a/Bot/InviteTracker.fs +++ b/Bot/InviteTracker.fs @@ -178,48 +178,6 @@ let getInvitedUserCount userId = |> Sql.executeRowAsync (fun read -> read.int "count") |> Async.AwaitTask -let getWhitelistItem () = - connStr - |> Sql.connect - |> Sql.query """ - SELECT stock, buy_price FROM store_item - JOIN item i on store_item.item_id = i.id - WHERE i.id = 'WHITELIST' - """ - |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = (read.int "buy_price") * 1 |}) - |> Async.AwaitTask - -let updateWhitelistStock () = async { - try - do! connStr - |> Sql.connect - |> Sql.query """ - UPDATE store_item SET stock = GREATEST(stock - 1, 0) - WHERE store_item.item_id = (SELECT id FROM item WHERE id = 'WHITELIST') - """ - |> Sql.executeNonQueryAsync - |> Async.AwaitTask - |> Async.Ignore - return true - with _ -> return false -} - -let setWhitelistStock amount = async { - try - do! connStr - |> Sql.connect - |> Sql.parameters [ ( "amount" , Sql.int amount ) ] - |> Sql.query """ - UPDATE store_item SET stock = @amount - WHERE store_item.item_id = (SELECT id FROM item WHERE id = 'WHITELIST') - """ - |> Sql.executeNonQueryAsync - |> Async.AwaitTask - |> Async.Ignore - return true - with _ -> return false -} - let guildInviteEmbed = let rewardMsg = $"**Your Mission:**\nCLICK THE BUTTON below, then share your **UNIQUE LINK** with any Degenz you want to invite into the Server.\n\n" + @@ -343,7 +301,7 @@ let acceptInvite (ctx : IDiscordContext) (invitedPlayer : PlayerData) = let! player = DbService.tryFindPlayer invite.Inviter match player with | Some player -> - do! DbService.updatePlayerCurrency InviteRewardAmount player |> Async.Ignore + do! DbService.updatePlayerCurrency InviteRewardAmount player.DiscordId |> Async.Ignore do! match GuildEnvironment.botClientRecruit with | Some recruitBot -> async { let builder = DiscordMessageBuilder() @@ -473,8 +431,9 @@ let handleGimmeWhitelist (ctx : IDiscordContext) = let builder = DiscordFollowupMessageBuilder().AsEphemeral(true) - let! wlItem = getWhitelistItem () - let! availability = tryGrantWhitelist ctx wlItem.Stock wlItem.Price + let! wlItem = DbService.getStoreItemBySymbol "WHITELIST" + let wlPrice = Inventory.getBuyPrice wlItem.Item + let! availability = tryGrantWhitelist ctx wlItem.Stock wlPrice match availability with | NotAHacker -> whitelistEmbed.Description <- notAHackerMsg | NotInGame -> whitelistEmbed.Description <- notInGameMsg @@ -485,11 +444,11 @@ let handleGimmeWhitelist (ctx : IDiscordContext) = whitelistEmbed.Description <- alreadyWhitelistedMsg | NotEnoughStock -> whitelistEmbed.Description <- "Oh no! We do not have any whitelist spots available for now. Check back later or go bother Kitty and ask him why the fuck you can't whitelist" | NotEnoughGBT total -> - includeInfo wlItem.Stock wlItem.Price + includeInfo wlItem.Stock wlPrice builder.AddComponents([ buyBtn ; recruitBtn ]) |> ignore - whitelistEmbed.Description <- notEnoughMoneyMsg wlItem.Price total + whitelistEmbed.Description <- notEnoughMoneyMsg wlPrice total | Granted _ -> - includeInfo wlItem.Stock wlItem.Price + includeInfo wlItem.Stock wlPrice whitelistEmbed.Color <- DiscordColor.Green whitelistEmbed.Color <- DiscordColor.Green builder.AddComponents([ buyActiveBtn ]) |> ignore @@ -522,9 +481,10 @@ let handleBuyWhitelist (ctx : IDiscordContext) = let builder = DiscordInteractionResponseBuilder().AsEphemeral(true) do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) - let! wlItem = getWhitelistItem () + let! wlItem = DbService.getStoreItemBySymbol "WHITELIST" let builder = DiscordFollowupMessageBuilder().AsEphemeral(true) - match! tryGrantWhitelist ctx wlItem.Stock wlItem.Price with + let wlPrice = Inventory.getBuyPrice wlItem.Item + match! tryGrantWhitelist ctx wlItem.Stock wlPrice with | NotAHacker -> builder.Content <- $"You are somehow not a hacker anymore, what exactly are you doing?" do! ctx.FollowUp(builder) @@ -541,7 +501,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) = builder.Content <- $"We just ran out of stock, tough shit" do! ctx.FollowUp(builder) | Granted player -> - match! updateWhitelistStock () with + match! DbService.decrementItemStock wlItem.Item with | true -> let embed = DiscordEmbedBuilder() embed.Description <- buyWhitelistMsg @@ -551,7 +511,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) = builder.AddComponents [ recruitBtn ] |> ignore let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist) do! ctx.GetDiscordMember().GrantRoleAsync(role) - let! _ = DbService.updatePlayerCurrency -wlItem.Price player + let! _ = DbService.updatePlayerCurrency -wlPrice player.DiscordId builder.AddEmbed(embed) |> ignore do! ctx.FollowUp(builder) @@ -563,7 +523,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) = |> Async.AwaitTask |> Async.Ignore let user = ctx.GetDiscordMember() - do! Analytics.whiteListPurchased wlItem.Price wlItem.Stock user.Id user.Username + do! Analytics.whiteListPurchased wlPrice wlItem.Stock user.Id user.Username | false -> let embed = DiscordEmbedBuilder() embed.Description <- "Oh no! Looks like the last Whitelist spot was taken. Don't worry you weren't charged..." @@ -633,7 +593,7 @@ let handleGuildMemberAdded _ (eventArgs : GuildMemberAddEventArgs) = let setCurrentWhitelistStock amount (ctx : IDiscordContext) = task { do! Messaging.defer ctx - let! result = setWhitelistStock amount + let! result = DbService.setItemStock amount "WHITELIST" if result then do! Messaging.sendFollowUpMessage ctx $"Set Whitelist stock to {amount}" else