diff --git a/Bot/Admin.fs b/Bot/Admin.fs index dbead26..ad2fa71 100644 --- a/Bot/Admin.fs +++ b/Bot/Admin.fs @@ -143,7 +143,7 @@ type AdminBot() = [] member this.SetStock (ctx : InteractionContext, [] amount : int64) = - enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setWhitelistStock (int amount)) + enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setCurrentWhitelistStock (int amount)) [] member this.SendEmbedToChannel (ctx : InteractionContext, [] embed : InitEmbeds) = diff --git a/Bot/DbService.fs b/Bot/DbService.fs index 522a50d..27da3c9 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -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 |}) - |> 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 -} diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs index b0e97dd..08b8081 100644 --- a/Bot/Games/Store.fs +++ b/Bot/Games/Store.fs @@ -299,7 +299,7 @@ type Store() = [] member this.Consume (ctx : InteractionContext) = - enforceChannel (DiscordInteractionContext ctx) (sell "Shields" (Inventory.getItemsByType ItemType.Food)) + enforceChannel (DiscordInteractionContext ctx) (sell "Food" (Inventory.getItemsByType ItemType.Food)) [] member this.Inventory (ctx : InteractionContext) = diff --git a/Bot/InviteTracker.fs b/Bot/InviteTracker.fs index 9bd5c45..b28d79e 100644 --- a/Bot/InviteTracker.fs +++ b/Bot/InviteTracker.fs @@ -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 |}) + |> 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