diff --git a/Bot/Games/SlotMachine.fs b/Bot/Games/SlotMachine.fs index 1df20a2..744317f 100644 --- a/Bot/Games/SlotMachine.fs +++ b/Bot/Games/SlotMachine.fs @@ -131,6 +131,7 @@ let slotEmojiNames = let PlayPricex1 = 5 let PlayPricex2 = 10 let PlayPricex3 = 20 +let BaseJackpotAmount = 0 let sleepTime = 1500 let mutable guildEmojis : Map option = None let mutable anyEmoji : DiscordEmoji option = None @@ -147,6 +148,7 @@ let getJackpotAmount () = |> Sql.connect |> Sql.query "SELECT stock FROM item WHERE symbol = 'JACKPOT'" |> Sql.executeRowAsync (fun read -> (read.int "stock") * 1) + |> Async.AwaitTask let incrementJackpot amount = GuildEnvironment.connectionString @@ -154,6 +156,15 @@ let incrementJackpot amount = |> Sql.parameters [ ( "amount" , Sql.int (int amount) ) ] |> Sql.query "UPDATE item SET stock = stock + @amount WHERE symbol = 'JACKPOT'" |> Sql.executeNonQueryAsync + |> Async.AwaitTask + +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.executeNonQueryAsync + |> Async.AwaitTask let handlePrizeTable (ctx : IDiscordContext) = task { @@ -188,13 +199,9 @@ let handlePrizeTable (ctx : IDiscordContext) = | _ , _ -> return () } :> Task -let spinEmojis (results : SlotSymbol array) (ctx : IDiscordContext) = +let spinEmojis (builder : DiscordFollowupMessageBuilder) (results : SlotSymbol array) (itx : DiscordInteraction) = async { - let itx = ctx.GetInteraction() - let builder = DiscordFollowupMessageBuilder() - builder.Content <- "Spinning!" - builder.IsEphemeral <- true let! followUp = itx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask match guildEmojis with @@ -211,8 +218,10 @@ let spinEmojis (results : SlotSymbol array) (ctx : IDiscordContext) = do! Async.Sleep sleepTime let content = $"{e1}{e2}{e3}" let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask - return () - | None -> return () + return followUp , content + | None -> + let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent("An error occurred, please contact an Admin")) |> Async.AwaitTask + return followUp , "" } let spin multiplier (ctx : IDiscordContext) = @@ -229,49 +238,75 @@ let spin multiplier (ctx : IDiscordContext) = | Symbol s1' , Any , Any when s1'.index = symbols.[0].index -> Some prize | _ -> None) - do! spinEmojis symbols ctx - - do! Async.Sleep 2000 let builder = DiscordFollowupMessageBuilder() builder.IsEphemeral <- true - let embed4 = DiscordEmbedBuilder() - embed4.Title <- "Results" + + let itx = ctx.GetInteraction() + let! followUpMessage , slotsContent = spinEmojis builder symbols itx + + do! Async.Sleep 2000 + let embed = DiscordEmbedBuilder() + embed.Author <- DiscordEmbedBuilder.EmbedAuthor() + embed.Author.Name <- player.Name + embed.Author.IconUrl <- ctx.GetDiscordMember().AvatarUrl + embed.Title <- "Slots Results" + let addGBTField (embed : DiscordEmbedBuilder) prize = + let sym = if prize > 0 then "+" else "-" + embed.AddField("New 💰$GBT Balance", $"`💰` {player.Bank} ⋙ `💰` {player.Bank + prize} `({sym}{abs prize} $GBT)`") |> ignore match prize with | Some (Money amount) -> - do! DbService.updatePlayerCurrency (amount * multiplier) player |> Async.Ignore - embed4.ImageUrl <- "https://s7.gifyu.com/images/youwin.png" - embed4.Description <- $"You win **{amount}** GBT!" + let prizeWithMultiplier = amount * multiplier + do! DbService.updatePlayerCurrency prizeWithMultiplier player |> Async.Ignore + embed.ImageUrl <- "https://s7.gifyu.com/images/youwin.png" + embed.Color <- DiscordColor.Green + embed.Color <- DiscordColor.Purple + embed.Description <- $"You win **{prizeWithMultiplier}** GBT!" + embed.AddField("Result", $"{slotsContent}", true) |> ignore + addGBTField embed prizeWithMultiplier | Some (Jackpot) -> - embed4.ImageUrl <- "https://s7.gifyu.com/images/jackpot2ac30c9823f6a91c.png" - embed4.Description <- $"YOU HIT THE JACKPOT!!!" + let! jackpot = getJackpotAmount () + embed.ImageUrl <- "https://s7.gifyu.com/images/jackpot2ac30c9823f6a91c.png" + embed.Color <- DiscordColor.Purple + embed.Description <- $"YOU HIT THE JACKPOT!!!" + embed.AddField("Result", $"{slotsContent}", true) |> ignore + addGBTField embed jackpot + do! resetJackpot BaseJackpotAmount |> Async.Ignore | None -> let playAmount = match multiplier with - | 0 -> PlayPricex1 - | 1 -> PlayPricex2 + | 1 -> PlayPricex1 + | 2 -> PlayPricex2 | _ -> PlayPricex3 + // TODO: We have to make sure we don't go below zero do! DbService.updatePlayerCurrency -playAmount player |> Async.Ignore - do! incrementJackpot PlayPricex1 |> Async.AwaitTask |> Async.Ignore - embed4.Description <- $"Better luck next time! You paid {playAmount} $GBT" - builder.AddComponents embedButtons |> ignore - builder.AddEmbed(embed4) |> ignore - do! ctx.FollowUp(builder) |> Async.AwaitTask |> Async.Ignore + do! incrementJackpot playAmount |> Async.Ignore + let! jackpot = getJackpotAmount () + embed.Description <- $"Better luck next time! You paid {playAmount} $GBT" + embed.Color <- DiscordColor.Red + embed.AddField("New 🎉JACKPOT🎉", $"`💰` {jackpot} `$GBT`", true) |> ignore + embed.AddField("Result", $"{slotsContent}", true) |> ignore + addGBTField embed -playAmount + let dwb = DiscordWebhookBuilder() + dwb.AddComponents(embedButtons).AddEmbed(embed).WithContent(slotsContent) |> ignore + do! itx.EditFollowupMessageAsync(followUpMessage.Id, dwb) |> Async.AwaitTask |> Async.Ignore return () }) let handleButton (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) = let ctx = DiscordEventContext event - task { - match event.Id with - | "spin-1x" -> do! spin 1 ctx - | "spin-2x" -> do! spin 2 ctx - | "spin-3x" -> do! spin 3 ctx - | "prizes" -> do! handlePrizeTable ctx - | _ -> - printfn "Wrong Spin ID" - return () - } :> Task + // TODO: We have to make sure the player has enough money + match event.Id with + | "spin-1x" -> spin 1 ctx + | "spin-2x" -> spin 2 ctx + | "spin-3x" -> spin 3 ctx + | "prizes" -> handlePrizeTable ctx + | _ -> + printfn "Wrong Spin ID" + Task.CompletedTask + |> Async.AwaitTask + |> Async.Start + Task.CompletedTask let handleGuildDownloadCompleted (_ : DiscordClient) (event : GuildDownloadCompletedEventArgs) = task { @@ -296,7 +331,7 @@ let sendInitialEmbed (ctx : IDiscordContext) = let embed = DiscordEmbedBuilder() embed.Title <- "Degenz Slot Machine" embed.Description <- "Want to try your luck?" - embed.ImageUrl <- "https://s7.gifyu.com/images/ezgif.com-gif-maker-241e68d2027b0efd54.gif" + embed.ImageUrl <- "https://s7.gifyu.com/images/ezgif.com-gif-maker-268ecb6e4d28bd55a0.gif" builder.AddEmbed(embed) |> ignore