108 lines
3.6 KiB
Forth
108 lines
3.6 KiB
Forth
open System
|
|
open System.Threading.Tasks
|
|
open DSharpPlus.Entities
|
|
open DSharpPlus
|
|
open DSharpPlus.EventArgs
|
|
open DSharpPlus.SlashCommands
|
|
open DegenzGame
|
|
open DegenzGame.Shared
|
|
open Emzi0767.Utilities
|
|
|
|
module Commands =
|
|
let constructItemButtons playerInfo (items : 'a array) =
|
|
items
|
|
|> Seq.map (fun item -> DiscordButtonComponent(ButtonStyle.Primary, $"{playerInfo}-{item}", $"{item}"))
|
|
|
|
let viewStore (ctx : InteractionContext) =
|
|
async {
|
|
let builder = DiscordInteractionResponseBuilder()
|
|
let hacks = weaponInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n"
|
|
builder.AddEmbed (constructEmbed $"Hacks:\n{hacks}") |> ignore
|
|
let shields = shieldInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n"
|
|
builder.AddEmbed (constructEmbed $"Shields:\n{shields}") |> ignore
|
|
|
|
builder.AsEphemeral true |> ignore
|
|
|
|
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
|
|> Async.AwaitTask
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
let buyHack (ctx : InteractionContext) hackId =
|
|
async {
|
|
return ()
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
let buyShield (ctx : InteractionContext) shieldId =
|
|
async {
|
|
return ()
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
let sellItem (ctx : InteractionContext) =
|
|
async {
|
|
return ()
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
|
|
|
|
type Store() =
|
|
inherit ApplicationCommandModule ()
|
|
|
|
[<SlashCommand("store", "View items available for purchase")>]
|
|
member _.ViewStore (ctx : InteractionContext) = Commands.viewStore ctx
|
|
|
|
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
|
member _.BuyHack (ctx : InteractionContext, [<Option("hack-id", "The ID of the hack you wish to purchase")>] hackId : Weapon) =
|
|
Commands.buyHack ctx hackId
|
|
|
|
[<SlashCommand("buy-shield", "Purchase a hack shield so you can protect your GoodBoyTokenz")>]
|
|
member this.BuyShield (ctx : InteractionContext, [<Option("shield-id", "The ID of the shield you wish to purchase")>] shieldId : Shield) =
|
|
Commands.buyShield ctx shieldId
|
|
|
|
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
|
member this.SellItem (ctx : InteractionContext) =
|
|
Commands.sellItem ctx
|
|
|
|
let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
|
async {
|
|
let builder = DiscordInteractionResponseBuilder()
|
|
builder.IsEphemeral <- true
|
|
builder.Content <- $""
|
|
do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
|
|> Async.AwaitTask
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
let config = DiscordConfiguration()
|
|
config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk"
|
|
config.TokenType <- TokenType.Bot
|
|
config.Intents <- DiscordIntents.All
|
|
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
|
|
|
let client = new DiscordClient(config)
|
|
|
|
client.add_ComponentInteractionCreated(AsyncEventHandler(handleButtonEvent))
|
|
|
|
let slash = client.UseSlashCommands()
|
|
|
|
// My server
|
|
slash.RegisterCommands<Store>(922419263275425832uL);
|
|
// Degenz
|
|
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
|
|
|
|
client.ConnectAsync ()
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|
|
Task.Delay(-1)
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|
|
client.DisconnectAsync ()
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|