Test out embeds with buttons. Add/Remove role
This commit is contained in:
parent
a770eaf82b
commit
db7126e642
98
Program.fs
98
Program.fs
@ -13,6 +13,7 @@ type HackType =
|
||||
| DDos = 2
|
||||
| Worm = 3
|
||||
| Crack = 4
|
||||
| SomeOtherThing = 4
|
||||
|
||||
type DefenseType =
|
||||
| Firewall
|
||||
@ -36,16 +37,39 @@ type Player = {
|
||||
Weapons : int array
|
||||
}
|
||||
|
||||
|
||||
type Match =
|
||||
{ scorePlayer1 : int
|
||||
round : int
|
||||
scorePlayer2 : int }
|
||||
|
||||
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
|
||||
|
||||
type JoeBot() =
|
||||
inherit ApplicationCommandModule ()
|
||||
|
||||
static let mutable currentMatch : Match option = None
|
||||
[<SlashCommand("redpill", "Take the redpill and become a hacker")>]
|
||||
member _.AddHackerRole (ctx : InteractionContext) =
|
||||
async {
|
||||
for role in ctx.Guild.Roles do
|
||||
if role.Value.Name = "Hacker" then
|
||||
do! ctx.Member.GrantRoleAsync(role.Value)
|
||||
|> Async.AwaitTask
|
||||
do! ctx.CreateResponseAsync("You are now an elite haxxor", true)
|
||||
|> Async.AwaitTask
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
[<SlashCommand("bluepill", "Take the bluepill and become lame")>]
|
||||
member _.RemoveHackerRole (ctx : InteractionContext) =
|
||||
async {
|
||||
for role in ctx.Member.Roles do
|
||||
if role.Name = "Hacker" then
|
||||
do! ctx.Member.RevokeRoleAsync(role)
|
||||
|> Async.AwaitTask
|
||||
do! ctx.CreateResponseAsync("You are now lame", true)
|
||||
|> Async.AwaitTask
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
[<SlashCommand("challenge", "Challenge another user")>]
|
||||
member _.StartMatch (ctx : InteractionContext, [<Option("player", "Player you want to challenge")>] player : DiscordUser) =
|
||||
@ -75,11 +99,11 @@ type JoeBot() =
|
||||
|> Async.Ignore
|
||||
|
||||
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
builder.IsEphemeral <- true
|
||||
builder.Content <- $"Sending challenge to {player.Username}"
|
||||
do! ctx.CreateResponseAsync (builder)
|
||||
|> Async.AwaitTask
|
||||
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
|
||||
@ -90,26 +114,73 @@ type JoeBot() =
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
[<SlashCommand("hack", "Send a hack attack to the player")>]
|
||||
member _.Hack (ctx : InteractionContext, [<Option("hack", "weapon attack")>] hackType : HackType) =
|
||||
member _.Embed () =
|
||||
let builder = DiscordEmbedBuilder()
|
||||
builder.Color <- Optional(DiscordColor.Blurple)
|
||||
builder.Description <- "This is a test embed"
|
||||
let author = DiscordEmbedBuilder.EmbedAuthor()
|
||||
author.Name <- "Joebot Pro"
|
||||
author.Url <- "https://ferano.io"
|
||||
author.IconUrl <- "https://i.kym-cdn.com/entries/icons/original/000/028/861/cover3.jpg"
|
||||
builder.Author <- author
|
||||
let footer = DiscordEmbedBuilder.EmbedFooter()
|
||||
footer.Text <- "This is a footer"
|
||||
footer.IconUrl <- "https://dg8krxphbh767.cloudfront.net/exercises/bird-watcher.svg"
|
||||
builder.Footer <- footer
|
||||
builder.Title <- "THIS IS A TITLE"
|
||||
builder.ImageUrl <- "https://avatars3.githubusercontent.com/u/2642263"
|
||||
builder.Build()
|
||||
|
||||
[<SlashCommand("hack", "Send a hack attack to another player")>]
|
||||
member this.Hack (ctx : InteractionContext, [<Option("player", "The player you want to hack")>] player : DiscordUser) =
|
||||
let constructButtons (weapons : HackType list) =
|
||||
weapons
|
||||
|> Seq.map (fun hack ->
|
||||
// TODO:L Button ID should be a GUID and we should keep an in-memory store of the buttons we're waiting for
|
||||
DiscordButtonComponent(
|
||||
ButtonStyle.Primary,
|
||||
$"{hack}{System.Guid.NewGuid()}",
|
||||
$"{hack}"))
|
||||
async {
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder.WithContent(sprintf "%A" hackType))
|
||||
builder.AddEmbed (this.Embed()) |> ignore
|
||||
|
||||
constructButtons [ HackType.Virus ; HackType.Crack ; HackType.Ransom ; HackType.Worm ; HackType.DDos ]
|
||||
|> Seq.cast<DiscordComponent>
|
||||
|> builder.AddComponents
|
||||
|> ignore
|
||||
|
||||
constructButtons [ HackType.Virus ; HackType.Crack ; HackType.Ransom ; HackType.Worm ; HackType.DDos ]
|
||||
|> Seq.cast<DiscordComponent>
|
||||
|> builder.AddComponents
|
||||
|> ignore
|
||||
|
||||
builder.AsEphemeral true |> ignore
|
||||
|
||||
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||
|> Async.AwaitTask
|
||||
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
[<SlashCommand("test", "testing the embeds")>]
|
||||
member this.TestEmbed (ctx : InteractionContext) =
|
||||
async {
|
||||
|
||||
do! ctx.CreateResponseAsync (this.Embed() , true)
|
||||
|> Async.AwaitTask
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
let mapper = FSharpBsonMapper()
|
||||
|
||||
let db = new LiteDatabase("hacker-game.db", mapper)
|
||||
|
||||
|
||||
let config = DiscordConfiguration()
|
||||
config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk"
|
||||
config.TokenType <- TokenType.Bot
|
||||
config.Intents <- DiscordIntents.All
|
||||
// config.MinimumLogLevel <- LogLevel.Trace
|
||||
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
||||
|
||||
let client = new DiscordClient(config)
|
||||
|
||||
@ -121,7 +192,8 @@ client.add_ComponentInteractionCreated(AsyncEventHandler(
|
||||
:> Task))
|
||||
|
||||
let slash = client.UseSlashCommands()
|
||||
slash.RegisterCommands<JoeBot>();
|
||||
|
||||
slash.RegisterCommands<JoeBot>(922419263275425832uL);
|
||||
|
||||
client.ConnectAsync ()
|
||||
|> Async.AwaitTask
|
||||
|
Loading…
x
Reference in New Issue
Block a user