Move some of the DB stuff
This commit is contained in:
parent
f044963470
commit
7661c1944a
@ -143,7 +143,7 @@ type AdminBot() =
|
||||
|
||||
[<SlashCommand("admin-whitelist-stock", "Set whitelist stock", false)>]
|
||||
member this.SetStock (ctx : InteractionContext, [<Option("amount", "Set the amount of WL available for purchase")>] amount : int64) =
|
||||
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setWhitelistStock (int amount))
|
||||
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setCurrentWhitelistStock (int amount))
|
||||
|
||||
[<SlashCommand("admin-send-embed", "Set whitelist stock", false)>]
|
||||
member this.SendEmbedToChannel (ctx : InteractionContext, [<Option("embed", "Which embed to send")>] embed : InitEmbeds) =
|
||||
|
@ -253,40 +253,3 @@ let getRandomHackablePlayers (did : uint64) =
|
||||
|> Sql.executeAsync (fun read -> {| Id = read.string "discord_id" |> uint64 ; Name = read.string "display_name" |})
|
||||
|> 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") * 1<GBT> |})
|
||||
|> Async.AwaitTask
|
||||
|
||||
let updateWhitelistStock () = async {
|
||||
try
|
||||
do! connStr
|
||||
|> Sql.connect
|
||||
|> Sql.query """
|
||||
UPDATE item SET stock = stock - 1 WHERE symbol = '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 item SET stock = @amount WHERE symbol = 'WHITELIST'
|
||||
"""
|
||||
|> Sql.executeNonQueryAsync
|
||||
|> Async.AwaitTask
|
||||
|> Async.Ignore
|
||||
return true
|
||||
with _ -> return false
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ type Store() =
|
||||
|
||||
[<SlashCommand("consume", "Consume a food item")>]
|
||||
member this.Consume (ctx : InteractionContext) =
|
||||
enforceChannel (DiscordInteractionContext ctx) (sell "Shields" (Inventory.getItemsByType ItemType.Food))
|
||||
enforceChannel (DiscordInteractionContext ctx) (sell "Food" (Inventory.getItemsByType ItemType.Food))
|
||||
|
||||
[<SlashCommand("inventory", "Check your inventory")>]
|
||||
member this.Inventory (ctx : InteractionContext) =
|
||||
|
@ -178,6 +178,44 @@ let getInvitedUserCount userId =
|
||||
|> Sql.executeRowAsync (fun read -> read.int "count")
|
||||
|> 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") * 1<GBT> |})
|
||||
|> Async.AwaitTask
|
||||
|
||||
let updateWhitelistStock () = async {
|
||||
try
|
||||
do! connStr
|
||||
|> Sql.connect
|
||||
|> Sql.query """
|
||||
UPDATE item SET stock = stock - 1 WHERE symbol = '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 item SET stock = @amount WHERE symbol = '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" +
|
||||
@ -431,7 +469,7 @@ let handleGimmeWhitelist (ctx : IDiscordContext) =
|
||||
|
||||
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||
|
||||
let! wlItem = DbService.getWhitelistItem ()
|
||||
let! wlItem = getWhitelistItem ()
|
||||
let! availability = tryGrantWhitelist ctx wlItem.Stock wlItem.Price
|
||||
match availability with
|
||||
| NotAHacker -> whitelistEmbed.Description <- notAHackerMsg
|
||||
@ -480,7 +518,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
||||
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder)
|
||||
|
||||
let! wlItem = DbService.getWhitelistItem ()
|
||||
let! wlItem = getWhitelistItem ()
|
||||
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||
match! tryGrantWhitelist ctx wlItem.Stock wlItem.Price with
|
||||
| NotAHacker ->
|
||||
@ -499,7 +537,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
||||
builder.Content <- $"We just ran out of stock, tough shit"
|
||||
do! ctx.FollowUp(builder)
|
||||
| Granted player ->
|
||||
match! DbService.updateWhitelistStock () with
|
||||
match! updateWhitelistStock () with
|
||||
| true ->
|
||||
let embed = DiscordEmbedBuilder()
|
||||
embed.Description <- buyWhitelistMsg
|
||||
@ -588,10 +626,10 @@ let handleGuildMemberAdded _ (eventArgs : GuildMemberAddEventArgs) =
|
||||
do! processNewUser eventArgs
|
||||
} :> Task
|
||||
|
||||
let rec setWhitelistStock amount (ctx : IDiscordContext) =
|
||||
let setCurrentWhitelistStock amount (ctx : IDiscordContext) =
|
||||
task {
|
||||
do! Messaging.defer ctx
|
||||
let! result = DbService.setWhitelistStock amount
|
||||
let! result = setWhitelistStock amount
|
||||
if result then
|
||||
do! Messaging.sendFollowUpMessage ctx $"Set Whitelist stock to {amount}"
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user