Switch to interactions with buttons and images for challenges

This commit is contained in:
Joseph Ferano 2022-01-03 14:53:41 +07:00
parent 73b9aeaec4
commit d72e5376e9
3 changed files with 50 additions and 10 deletions

View File

@ -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
[<SlashCommand("match", "Start the match")>]
member _.StartMatch (ctx : InteractionContext, [<Option("player1", "first player")>] player1 : DiscordUser, [<Option("player2", "seceond player")>] player2 : DiscordUser) =
[<SlashCommand("challenge", "Challenge another user")>]
member _.StartMatch (ctx : InteractionContext, [<Option("player", "Player you want to challenge")>] 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<JoeBot>();
client.ConnectAsync ()

BIN
challenge.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -7,6 +7,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<Content Include="challenge.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ReferencePathWithRefAssemblies Update="\home\joe\.nuget\packages\dsharpplus.slashcommands\4.2.0-nightly-01054\lib\netstandard2.0\DSharpPlus.SlashCommands.dll" />