diff --git a/Program.fs b/Program.fs index 6aa4e25..4c9039a 100644 --- a/Program.fs +++ b/Program.fs @@ -1,7 +1,9 @@ -open System.Threading.Tasks +open System.IO +open System.Threading.Tasks open DSharpPlus open DSharpPlus.Entities open DSharpPlus.SlashCommands +open Microsoft.Extensions.Logging type Move = | Rock @@ -36,22 +38,55 @@ type JoeBot() = static let mutable currentMatch : Match option = None - [] - member _.StartMatch (ctx : InteractionContext, [] player1 : DiscordUser, [] player2 : DiscordUser) = + [] + member _.StartMatch (ctx : InteractionContext, [] player : DiscordUser) = async { currentMatch <- Some { - player1 = player1 - player2 = player2 + player1 = ctx.User + player2 = player round = 0 scorePlayer1 = 0 scorePlayer2 = 0 turn = WaitingForBoth } - do! ctx.CreateResponseAsync (sprintf "Match started between %s and %s. May the best hacker win!" player1.Username player2.Username) - |> Async.AwaitTask - |> Async.Ignore - + // We won't be able to find the user if they are Away or Sleeping apparently + let ( result , discordMember ) = ctx.Guild.Members.TryGetValue(player.Id) + + if result then + let yes = DiscordButtonComponent( + ButtonStyle.Primary, + "first_button", + "I do") + let no = DiscordButtonComponent( + ButtonStyle.Danger, + "second_button", + "No thank you") + let builder = DiscordMessageBuilder() + let builder = builder.AddComponents(yes, no) + use img = new FileStream("challenge.jpg", FileMode.Open) + builder.WithFile(img) |> ignore + builder.Content <- $"You have been challenged by {player.Username}, do you accept?" + + for channel in ctx.Guild.Channels do + if channel.Value.Name = "battle-1" then + do! channel.Value.SendMessageAsync builder + |> Async.AwaitTask + |> Async.Ignore + + + let builder = DiscordInteractionResponseBuilder() + builder.IsEphemeral <- true + builder.Content <- $"Sending challenge to {player.Username}" + do! ctx.CreateResponseAsync (builder) + |> Async.AwaitTask + else + let builder = DiscordInteractionResponseBuilder() + builder.IsEphemeral <- true + builder.Content <- $"Unable to find user in this server" + do! ctx.CreateResponseAsync (builder) + |> Async.AwaitTask + } |> Async.StartAsTask :> Task @@ -162,9 +197,11 @@ type JoeBot() = let config = DiscordConfiguration() config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk" config.TokenType <- TokenType.Bot +config.Intents <- DiscordIntents.All +// config.MinimumLogLevel <- LogLevel.Trace let client = new DiscordClient(config) -let slash = client.UseSlashCommands(); +let slash = client.UseSlashCommands() slash.RegisterCommands(); client.ConnectAsync () diff --git a/challenge.jpg b/challenge.jpg new file mode 100644 index 0000000..bce5e38 Binary files /dev/null and b/challenge.jpg differ diff --git a/discord-bot.fsproj b/discord-bot.fsproj index 5a24393..76763d2 100644 --- a/discord-bot.fsproj +++ b/discord-bot.fsproj @@ -7,6 +7,9 @@ + + PreserveNewest +