diff --git a/Bot/DbService.fs b/Bot/DbService.fs index 7ae2e5c..7c9a58d 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -29,7 +29,7 @@ let readItem (reader : RowReader) = | "Shield" -> ItemType.Shield | "Food" -> ItemType.Food | "Accessory" -> ItemType.Accessory - | _ -> ItemType.Accessory + | _ -> ItemType.Misc Item.Attributes = [ reader.intOrNone "buy_price" |> Option.map (fun a -> Buyable (a * 1)) reader.intOrNone "sell_price" |> Option.map (fun a -> Sellable (a * 1)) @@ -185,7 +185,7 @@ let updatePlayerCurrency (addAmount : int) (player : PlayerData) = "did", Sql.string (string player.DiscordId) "gbt", Sql.int (int addAmount) ] |> Sql.query """ - UPDATE "user" SET gbt = gbt + @gbt WHERE discord_id = @did; + UPDATE "user" SET gbt = gbt + GREATEST(gbt + @gbt, 0) WHERE discord_id = @did; """ |> Sql.executeNonQueryAsync |> Async.AwaitTask diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs index 5a0dc5f..8fb61f4 100644 --- a/Bot/GameHelpers.fs +++ b/Bot/GameHelpers.fs @@ -19,6 +19,7 @@ module Inventory = | ItemType.Shield -> inventory |> List.filter (fun item -> match item.Type with ItemType.Shield _ -> true | _ -> false) | ItemType.Food -> inventory |> List.filter (fun item -> match item.Type with ItemType.Food _ -> true | _ -> false) | ItemType.Accessory -> inventory |> List.filter (fun item -> match item.Type with ItemType.Accessory _ -> true | _ -> false) + | ItemType.Misc -> inventory |> List.filter (fun item -> match item.Type with ItemType.Misc _ -> true | _ -> false) let findItemById id (inventory : Inventory) = inventory |> List.find (fun item -> item.Id = id) diff --git a/Bot/GameTypes.fs b/Bot/GameTypes.fs index ddf003f..472a297 100644 --- a/Bot/GameTypes.fs +++ b/Bot/GameTypes.fs @@ -88,6 +88,7 @@ type ItemType = | Shield | Food | Accessory + | Misc type Effect = | Min of int diff --git a/Bot/Games/SlotMachine.fs b/Bot/Games/SlotMachine.fs index c7ed238..80317dd 100644 --- a/Bot/Games/SlotMachine.fs +++ b/Bot/Games/SlotMachine.fs @@ -128,7 +128,10 @@ let mutable anyEmoji : DiscordEmoji option = None let getJackpotAmount () = GuildEnvironment.connectionString |> Sql.connect - |> Sql.query "SELECT stock FROM item WHERE symbol = 'JACKPOT'" + |> Sql.query """ + SELECT stock FROM store_item + WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'JACKPOT') + """ |> Sql.executeRowAsync (fun read -> (read.int "stock") * 1) |> Async.AwaitTask @@ -136,7 +139,10 @@ let incrementJackpot amount = GuildEnvironment.connectionString |> Sql.connect |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] - |> Sql.query "UPDATE item SET stock = stock + @amount WHERE symbol = 'JACKPOT'" + |> Sql.query """ + UPDATE store_item SET stock = stock + @amount + WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'JACKPOT') + """ |> Sql.executeNonQueryAsync |> Async.AwaitTask @@ -144,7 +150,10 @@ let resetJackpot amount = GuildEnvironment.connectionString |> Sql.connect |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] - |> Sql.query "UPDATE item SET stock = @amount WHERE symbol = 'JACKPOT'" + |> Sql.query """ + UPDATE store_item SET stock = @amount + WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'JACKPOT') + """ |> Sql.executeNonQueryAsync |> Async.AwaitTask diff --git a/Bot/InviteTracker.fs b/Bot/InviteTracker.fs index e170fba..68f7a2f 100644 --- a/Bot/InviteTracker.fs +++ b/Bot/InviteTracker.fs @@ -182,9 +182,11 @@ let getWhitelistItem () = connStr |> Sql.connect |> Sql.query """ - SELECT stock, price FROM item WHERE symbol = 'WHITELIST' + SELECT stock, buy_price FROM store_item + JOIN item i on store_item.item_id = i.id + WHERE i.symbol = 'WHITELIST' """ - |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = (read.int "price") * 1 |}) + |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = (read.int "buy_price") * 1 |}) |> Async.AwaitTask let updateWhitelistStock () = async { @@ -192,7 +194,8 @@ let updateWhitelistStock () = async { do! connStr |> Sql.connect |> Sql.query """ - UPDATE item SET stock = stock - 1 WHERE symbol = 'WHITELIST' + UPDATE store_item SET stock = GREATEST(stock - 1, 0) + WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'WHITELIST') """ |> Sql.executeNonQueryAsync |> Async.AwaitTask @@ -207,7 +210,8 @@ let setWhitelistStock amount = async { |> Sql.connect |> Sql.parameters [ ( "amount" , Sql.int amount ) ] |> Sql.query """ - UPDATE item SET stock = @amount WHERE symbol = 'WHITELIST' + UPDATE store_item SET stock = @amount + WHERE store_item.item_id = (SELECT id FROM item WHERE symbol = 'WHITELIST') """ |> Sql.executeNonQueryAsync |> Async.AwaitTask