module Degenz.RockPaperScissors open System open System.Threading.Tasks open DSharpPlus open DSharpPlus.Entities open DSharpPlus.SlashCommands open Degenz.Messaging type Move = | Rock | Paper | Scissor type RoundResult = | P1Win | P2Win | Draw let player1Won p1m p2m = match p1m , p2m with | Rock , Paper -> P2Win | Rock , Scissor -> P1Win | Paper , Rock -> P1Win | Paper , Scissor -> P2Win | Scissor , Rock -> P2Win | Scissor , Paper -> P1Win | _ , _ -> Draw let playRPS target ctx = Game.executePlayerActionWithTarget target ctx (fun attacker defender -> async { let buttons = [ DiscordButtonComponent(ButtonStyle.Primary, $"RPS-rock-{defender.DiscordId}-{defender.Name}", "🪨 Rock") DiscordButtonComponent(ButtonStyle.Primary, $"RPS-paper", "📜 Paper") DiscordButtonComponent(ButtonStyle.Primary, $"RPS-scissors", "✂ Scissors") ] |> Seq.cast let builder = DiscordFollowupMessageBuilder() builder.AddComponents(buttons) |> ignore builder.IsEphemeral <- true do! ctx.FollowUp builder |> Async.AwaitTask }) let handleRPS ctx = async.Zero() |> Async.StartAsTask type RPSGame() = inherit ApplicationCommandModule () let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) = match ctx.GetChannel().Id with | id when id = GuildEnvironment.channelArmory -> storeFn ctx | _ -> task { let msg = $"You must go to <#{GuildEnvironment.channelArmory}> channel to buy or sell weapons" do! Messaging.sendSimpleResponse ctx msg } [] member this.RPS (ctx : InteractionContext, [] target : DiscordUser) = // enforceChannel (DiscordInteractionContext ctx) (steal target) playRPS target (DiscordInteractionContext ctx)