Whitelist stock and price from DB
This commit is contained in:
parent
1f98d05d3e
commit
6fe647f9f1
@ -6,18 +6,6 @@ open Degenz
|
||||
|
||||
let connStr = GuildEnvironment.connectionString
|
||||
|
||||
type User = {
|
||||
Name : string
|
||||
DiscordId : uint64
|
||||
Bank : int<GBT>
|
||||
Inventory : int list
|
||||
Strength : int
|
||||
Focus : int
|
||||
Charisma : int
|
||||
Luck : int
|
||||
Active : bool
|
||||
}
|
||||
|
||||
let getPlayerEvents (did : uint64) =
|
||||
connStr
|
||||
|> Sql.connect
|
||||
@ -81,7 +69,7 @@ let tryFindPlayer (discordId : uint64) = async {
|
||||
"""
|
||||
|> Sql.executeAsync (fun read ->
|
||||
let inv = read.intArray "inventory"
|
||||
{
|
||||
{|
|
||||
DiscordId = read.string "discord_id" |> uint64
|
||||
Name = read.string "display_name"
|
||||
Bank = read.intOrNone "gbt" |> Option.map ((*) 1<GBT>) |> Option.defaultValue 0<GBT>
|
||||
@ -91,7 +79,7 @@ let tryFindPlayer (discordId : uint64) = async {
|
||||
Charisma = read.intOrNone "charisma" |> Option.defaultValue 0
|
||||
Luck = read.intOrNone "luck" |> Option.defaultValue 0
|
||||
Active = read.bool "in_game"
|
||||
})
|
||||
|})
|
||||
|> Async.AwaitTask
|
||||
match List.tryHead user with
|
||||
| None -> return None
|
||||
@ -248,3 +236,21 @@ let addPlayerEvent (did : uint64) (playerEvent : PlayerEvent) =
|
||||
|> Sql.query query
|
||||
|> Sql.executeNonQueryAsync
|
||||
|> Async.AwaitTask
|
||||
|
||||
let getWhitelistItem () =
|
||||
connStr
|
||||
|> Sql.connect
|
||||
|> Sql.query """
|
||||
SELECT stock, price FROM item WHERE symbol = 'WHITELIST'
|
||||
"""
|
||||
|> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = read.int "price" |})
|
||||
|> Async.AwaitTask
|
||||
|
||||
let updateWhitelistStock () =
|
||||
connStr
|
||||
|> Sql.connect
|
||||
|> Sql.query """
|
||||
UPDATE item SET stock = stock - 1 WHERE symbol = 'WHITELIST'
|
||||
"""
|
||||
|> Sql.executeNonQueryAsync
|
||||
|> Async.AwaitTask
|
||||
|
@ -347,10 +347,11 @@ type WhitelistResult =
|
||||
| NotInGame
|
||||
| NotAHacker
|
||||
| NotEnoughGBT of currentAmount : int
|
||||
| NotEnoughStock
|
||||
| Granted of PlayerData
|
||||
| AlreadyWhitelisted
|
||||
|
||||
let tryGrantWhitelist (ctx : IDiscordContext) =
|
||||
let tryGrantWhitelist (ctx : IDiscordContext) stock price =
|
||||
task {
|
||||
let user = ctx.GetDiscordMember()
|
||||
match! DbService.tryFindPlayer user.Id with
|
||||
@ -361,10 +362,12 @@ let tryGrantWhitelist (ctx : IDiscordContext) =
|
||||
elif player.Active then
|
||||
let hackerRole = ctx.GetGuild().GetRole(GuildEnvironment.roleHacker)
|
||||
if Seq.contains hackerRole user.Roles then
|
||||
if int player.Bank >= WhitelistPrice then
|
||||
if int player.Bank >= price then
|
||||
return Granted player
|
||||
else
|
||||
elif stock > 0 then
|
||||
return NotEnoughGBT (int player.Bank)
|
||||
else
|
||||
return NotEnoughStock
|
||||
else
|
||||
return NotAHacker
|
||||
else
|
||||
@ -420,18 +423,20 @@ let handleGimmeWhitelist (ctx : IDiscordContext) =
|
||||
|
||||
let whitelistEmbed = DiscordEmbedBuilder()
|
||||
whitelistEmbed.Title <- "1x Degenz Game Whitelist "
|
||||
let includeInfo () =
|
||||
let includeInfo stock price =
|
||||
whitelistEmbed.ImageUrl <- "https://s7.gifyu.com/images/whitelist-item-mock-banner18.png"
|
||||
whitelistEmbed.AddField("Item", "`1x Whitelist`", true) |> ignore
|
||||
whitelistEmbed.AddField("Available", "`750`", true) |> ignore
|
||||
whitelistEmbed.AddField("Price 💰", $"`{WhitelistPrice} $GBT`", true) |> ignore
|
||||
whitelistEmbed.AddField("Available", $"`{stock}`", true) |> ignore
|
||||
whitelistEmbed.AddField("Price 💰", $"`{price} $GBT`", true) |> ignore
|
||||
whitelistEmbed.Color <- DiscordColor.Red
|
||||
let buyBtn = DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now", true) :> DiscordComponent
|
||||
let buyActiveBtn = DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now") :> DiscordComponent
|
||||
let recruitBtn = DiscordButtonComponent(ButtonStyle.Danger, $"ShowRecruitmentEmbed", $"Recruit Now") :> DiscordComponent
|
||||
|
||||
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||
let! availability = tryGrantWhitelist ctx
|
||||
|
||||
let! wlItem = DbService.getWhitelistItem ()
|
||||
let! availability = tryGrantWhitelist ctx wlItem.Stock wlItem.Price
|
||||
match availability with
|
||||
| NotAHacker -> whitelistEmbed.Description <- notAHackerMsg
|
||||
| NotInGame -> whitelistEmbed.Description <- notInGameMsg
|
||||
@ -440,12 +445,13 @@ let handleGimmeWhitelist (ctx : IDiscordContext) =
|
||||
whitelistEmbed.Color <- DiscordColor.Green
|
||||
whitelistEmbed.Color <- DiscordColor.Green
|
||||
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()
|
||||
includeInfo wlItem.Stock wlItem.Price
|
||||
builder.AddComponents([ buyBtn ; recruitBtn ]) |> ignore
|
||||
whitelistEmbed.Description <- notEnoughMoneyMsg total
|
||||
| Granted _ ->
|
||||
includeInfo()
|
||||
includeInfo wlItem.Stock wlItem.Price
|
||||
whitelistEmbed.Color <- DiscordColor.Green
|
||||
whitelistEmbed.Color <- DiscordColor.Green
|
||||
builder.AddComponents([ buyActiveBtn ]) |> ignore
|
||||
@ -478,8 +484,9 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
||||
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder)
|
||||
|
||||
let! wlItem = DbService.getWhitelistItem ()
|
||||
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||
match! tryGrantWhitelist ctx with
|
||||
match! tryGrantWhitelist ctx wlItem.Stock wlItem.Price with
|
||||
| NotAHacker ->
|
||||
builder.Content <- $"You are somehow not a hacker anymore, what exactly are you doing?"
|
||||
do! ctx.FollowUp(builder)
|
||||
@ -492,6 +499,9 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
||||
| NotEnoughGBT _ ->
|
||||
builder.Content <- $"You somehow do not have enough $GBT, what exactly are you doing?"
|
||||
do! ctx.FollowUp(builder)
|
||||
| NotEnoughStock ->
|
||||
builder.Content <- $"We just ran out of stock, tough shit"
|
||||
do! ctx.FollowUp(builder)
|
||||
| Granted player ->
|
||||
let embed = DiscordEmbedBuilder()
|
||||
embed.Description <- buyWhitelistMsg
|
||||
|
Loading…
x
Reference in New Issue
Block a user