Update whitelist and jackpot to use new tables
This commit is contained in:
parent
f26d51701d
commit
6dda9dd8a3
@ -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<GBT>))
|
||||
reader.intOrNone "sell_price" |> Option.map (fun a -> Sellable (a * 1<GBT>))
|
||||
@ -185,7 +185,7 @@ let updatePlayerCurrency (addAmount : int<GBT>) (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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -88,6 +88,7 @@ type ItemType =
|
||||
| Shield
|
||||
| Food
|
||||
| Accessory
|
||||
| Misc
|
||||
|
||||
type Effect =
|
||||
| Min of int
|
||||
|
@ -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<GBT>)
|
||||
|> 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
|
||||
|
||||
|
@ -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<GBT> |})
|
||||
|> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = (read.int "buy_price") * 1<GBT> |})
|
||||
|> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user