discord-bot-game/Bot/Games/SlotMachine.fs

199 lines
8.3 KiB
Forth

module Degenz.SlotMachine
open System
open System.IO
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz.Messaging
open Degenz.Types
let slots =
// [|
// "https://s7.gifyu.com/images/A-bottle-of-pills.png"
// "https://s7.gifyu.com/images/an-eye.png"
// "https://s7.gifyu.com/images/anon-face-mask.png"
// "https://s7.gifyu.com/images/a-piece-of-sushi.png"
// "https://s7.gifyu.com/images/Circuit-board.png"
// "https://s7.gifyu.com/images/OBEY.png"
// "https://s7.gifyu.com/images/old-tv-screen.png"
// "https://s7.gifyu.com/images/pizza.png"
// "https://s7.gifyu.com/images/ramen.png"
// "https://s7.gifyu.com/images/rat.png"
//|]
// [|
// "https://s7.gifyu.com/images/A-bottle-of-pills0a3006d0170e08df.png"
// "https://s7.gifyu.com/images/an-eyec362d8152ae2382b.png"
// "https://s7.gifyu.com/images/anon-face-mask6c7624821c89fc08.png"
// "https://s7.gifyu.com/images/a-piece-of-sushi77071d30f60a89c6.png"
// "https://s7.gifyu.com/images/Circuit-board89056017b80f1d13.png"
// "https://s7.gifyu.com/images/OBEYf2a8234109836c03.png"
// "https://s7.gifyu.com/images/old-tv-screendc6bc9d4b6c1fd65.png"
// "https://s7.gifyu.com/images/pizza030ffc00ff50da0e.png"
// "https://s7.gifyu.com/images/ramen08336d448018c98f.png"
// "https://s7.gifyu.com/images/rat14f65f54f0d75036.png"
//|]
[|
"<:sushi:>"
"<:pizza:>"
"<:ramen:>"
"<:circuitboard:>"
"<:obey:>"
"<:pills:>"
"<:oldtv:>"
"<:rat:>"
"<:aneye:>"
"<:anon:>"
|]
let slotsLocal =
[|
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/A bottle of pills.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/a piece of sushi.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/an eye.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/anon face mask.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/Circuit board.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/OBEY.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/old tv screen.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/pizza.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/ramen.png"
"/home/joe/Development/DegenzGame/Images/SlotMachine/new/rat.png"
|]
let PlayPrice = 10<GBT>
let twoOfAKindPrize = 100<GBT>
let threeOfAKindPrize = 1000<GBT>
let fourOfAKindPrize = 10000<GBT>
let spin (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async {
let sleepTime = 1000
let random = Random(System.Guid.NewGuid().GetHashCode())
let slotCount = slots.Length
let results = [ random.Next(0, slotCount) ; random.Next(0, slotCount) ; random.Next(0, slotCount) ]
let winConditions = (results.[0] = results.[1] && results.[0] = results.[2])
|| (results.[0] <> results.[1] && results.[1] <> results.[2] && results.[0] <> results.[2])
if winConditions
then do! DbService.updatePlayerCurrency twoOfAKindPrize player |> Async.Ignore
else do! DbService.updatePlayerCurrency -PlayPrice player |> Async.Ignore
// let embed1 = DiscordEmbedBuilder()
// embed1.ImageUrl <- slots.[results.[0]]
// let embed2 = DiscordEmbedBuilder()
// embed2.ImageUrl <- slots.[results.[1]]
// let embed3 = DiscordEmbedBuilder()
// embed3.ImageUrl <- slots.[results.[2]]
let embed4 = DiscordEmbedBuilder()
embed4.Title <- "Slot Machine"
embed4.Description <- "You hit the jackpot!"
let iCtx = ctx.GetInteraction()
let builder = DiscordFollowupMessageBuilder()
// let embed = DiscordEmbedBuilder()
// embed.ImageUrl <- slots.[results.[0]]
// builder.AddEmbed(embed.Build()) |> ignore
builder.Content <- "Spinning!"
builder.IsEphemeral <- true
let emojis = ctx.GetGuild().Emojis |> Seq.map (fun kvp -> kvp.Value) |> Seq.toArray
let! followUp = iCtx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask
do! Async.Sleep 1500
let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(Formatter.Emoji(emojis.[results.[0]]))) |> Async.AwaitTask
do! Async.Sleep 1500
let! _ = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent($"{Formatter.Emoji(emojis.[results.[0]])}{Formatter.Emoji(emojis.[results.[1]])}")) |> Async.AwaitTask
do! Async.Sleep 1500
let! asdf = iCtx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder()
.WithContent($"{Formatter.Emoji(emojis.[results.[0]])}{Formatter.Emoji(emojis.[results.[1]])}{Formatter.Emoji(emojis.[results.[2]])}")
.AddEmbed(embed4)
) |> Async.AwaitTask
do! Async.Sleep 1500
let builder = DiscordFollowupMessageBuilder()
builder.AddEmbeds([ embed4.Build() ]) |> ignore
builder.IsEphemeral <- true
// let! _ = iCtx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask
return ()
// if winConditions then
// do! Async.Sleep sleepTime
// let builder = DiscordFollowupMessageBuilder()
// builder.Content <- "You win 10 GBT!"
// do! ctx.FollowUp(builder)
// |> Async.AwaitTask
// |> Async.Ignore
// else
// do! Async.Sleep sleepTime
// let builder = DiscordFollowupMessageBuilder()
// builder.Content <- "You lose 0.5 GBT! Try your luck again!"
// do! ctx.FollowUp(builder)
// |> Async.AwaitTask
// |> Async.Ignore
})
let handleSpin (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
task {
do! spin (DiscordEventContext event)
} :> Task
let spinCommand (ctx : IDiscordContext) =
async {
try
let builder = DiscordInteractionResponseBuilder()
builder.Content <- "The message"
builder.IsEphemeral <- true
let button = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin Me Right Around") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
|> Async.Ignore
with e ->
printfn $"Error trying to get channel Casino\n\n{e.Message}"
} |> Async.StartAsTask :> Task
let sendInitialEmbed (client : DiscordClient) =
async {
try
let! channel = client.GetChannelAsync(961472561319903352uL) |> Async.AwaitTask
let builder = DiscordMessageBuilder()
let embed = DiscordEmbedBuilder()
embed.Title <- "Degenz Slot Machine"
embed.Description <- "Hello I am an embed"
embed.ImageUrl <- "https://i.kym-cdn.com/photos/images/original/001/169/608/a43.gif"
builder.AddEmbed(embed) |> ignore
let button = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin Me Right Around") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! channel.SendMessageAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
with e ->
printfn $"Error trying to get channel Training Dojo\n\n{e.Message}"
} |> Async.RunSynchronously
type SlotMachine() =
inherit ApplicationCommandModule ()
let enforceChannel (ctx : IDiscordContext) (spinFn : IDiscordContext -> Task) =
match ctx.GetChannel().Id with
| id when id = 961472561319903352uL -> spinFn ctx
| _ ->
task {
let msg = $"You must go to <#961472561319903352> channel to spin"
do! Messaging.sendSimpleResponse ctx msg
}
[<SlashCommand("spin", "Want to try your luck?")>]
member this.Spin (ctx : InteractionContext) = enforceChannel (DiscordInteractionContext ctx) spinCommand
[<SlashCommand("spin-simple", "Want to try your luck?")>]
member this.SpinSimple (ctx : InteractionContext) = enforceChannel (DiscordInteractionContext ctx) spin