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)>]
|
[<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) =
|
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)>]
|
[<SlashCommand("admin-send-embed", "Set whitelist stock", false)>]
|
||||||
member this.SendEmbedToChannel (ctx : InteractionContext, [<Option("embed", "Which embed to send")>] embed : InitEmbeds) =
|
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" |})
|
|> Sql.executeAsync (fun read -> {| Id = read.string "discord_id" |> uint64 ; Name = read.string "display_name" |})
|
||||||
|> Async.AwaitTask
|
|> 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")>]
|
[<SlashCommand("consume", "Consume a food item")>]
|
||||||
member this.Consume (ctx : InteractionContext) =
|
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")>]
|
[<SlashCommand("inventory", "Check your inventory")>]
|
||||||
member this.Inventory (ctx : InteractionContext) =
|
member this.Inventory (ctx : InteractionContext) =
|
||||||
|
@ -178,6 +178,44 @@ let getInvitedUserCount userId =
|
|||||||
|> Sql.executeRowAsync (fun read -> read.int "count")
|
|> Sql.executeRowAsync (fun read -> read.int "count")
|
||||||
|> Async.AwaitTask
|
|> 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 guildInviteEmbed =
|
||||||
let rewardMsg =
|
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" +
|
$"**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 builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||||
|
|
||||||
let! wlItem = DbService.getWhitelistItem ()
|
let! wlItem = getWhitelistItem ()
|
||||||
let! availability = tryGrantWhitelist ctx wlItem.Stock wlItem.Price
|
let! availability = tryGrantWhitelist ctx wlItem.Stock wlItem.Price
|
||||||
match availability with
|
match availability with
|
||||||
| NotAHacker -> whitelistEmbed.Description <- notAHackerMsg
|
| NotAHacker -> whitelistEmbed.Description <- notAHackerMsg
|
||||||
@ -480,7 +518,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
|||||||
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
||||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder)
|
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder)
|
||||||
|
|
||||||
let! wlItem = DbService.getWhitelistItem ()
|
let! wlItem = getWhitelistItem ()
|
||||||
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
|
||||||
match! tryGrantWhitelist ctx wlItem.Stock wlItem.Price with
|
match! tryGrantWhitelist ctx wlItem.Stock wlItem.Price with
|
||||||
| NotAHacker ->
|
| NotAHacker ->
|
||||||
@ -499,7 +537,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
|
|||||||
builder.Content <- $"We just ran out of stock, tough shit"
|
builder.Content <- $"We just ran out of stock, tough shit"
|
||||||
do! ctx.FollowUp(builder)
|
do! ctx.FollowUp(builder)
|
||||||
| Granted player ->
|
| Granted player ->
|
||||||
match! DbService.updateWhitelistStock () with
|
match! updateWhitelistStock () with
|
||||||
| true ->
|
| true ->
|
||||||
let embed = DiscordEmbedBuilder()
|
let embed = DiscordEmbedBuilder()
|
||||||
embed.Description <- buyWhitelistMsg
|
embed.Description <- buyWhitelistMsg
|
||||||
@ -588,10 +626,10 @@ let handleGuildMemberAdded _ (eventArgs : GuildMemberAddEventArgs) =
|
|||||||
do! processNewUser eventArgs
|
do! processNewUser eventArgs
|
||||||
} :> Task
|
} :> Task
|
||||||
|
|
||||||
let rec setWhitelistStock amount (ctx : IDiscordContext) =
|
let setCurrentWhitelistStock amount (ctx : IDiscordContext) =
|
||||||
task {
|
task {
|
||||||
do! Messaging.defer ctx
|
do! Messaging.defer ctx
|
||||||
let! result = DbService.setWhitelistStock amount
|
let! result = setWhitelistStock amount
|
||||||
if result then
|
if result then
|
||||||
do! Messaging.sendFollowUpMessage ctx $"Set Whitelist stock to {amount}"
|
do! Messaging.sendFollowUpMessage ctx $"Set Whitelist stock to {amount}"
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user