Some clean up

This commit is contained in:
Joseph Ferano 2022-01-20 14:15:33 +07:00
parent 116ab79e8a
commit a08c66a84d
5 changed files with 63 additions and 101 deletions

View File

@ -4,8 +4,6 @@ open System
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.SlashCommands
open Degenz.Shared
open Emzi0767.Utilities
open Degenz.PlayerInteractions
open Degenz.SlotMachine
open Degenz.Trainer
@ -29,7 +27,6 @@ for conf in configs do
conf.Intents <- DiscordIntents.All
//DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 4))
DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 5, overwriteExistingVars = false))
let guild = Environment.GetEnvironmentVariable("DISCORD_GUILD") |> uint64
@ -61,8 +58,6 @@ sc2.RegisterCommands<Trainer>(guild);
sc3.RegisterCommands<HackerGame>(guild);
sc4.RegisterCommands<Store>(guild);
sc5.RegisterCommands<SlotMachine>(guild);
// Degenz
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
let run (client : DiscordClient) =
async {

View File

@ -7,7 +7,6 @@ open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz
open Emzi0767.Utilities
open Degenz.Shared
[<Literal>]

View File

@ -4,7 +4,6 @@ open System
open System.Threading.Tasks
open DSharpPlus.Entities
open DSharpPlus
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz
open Degenz.Shared

View File

@ -7,7 +7,6 @@ open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz
open Degenz.Shared
open Emzi0767.Utilities
open Newtonsoft.Json
let store =

View File

@ -6,68 +6,6 @@ open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz.Shared
open Emzi0767.Utilities
type Trainer() =
inherit ApplicationCommandModule ()
[<SlashCommand("defend", "Create a passive defense that will last 24 hours")>]
member this.DefendCommand (ctx : InteractionContext) =
async {
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
match playerResult with
| Some player ->
let builder = DiscordInteractionResponseBuilder()
builder.AddEmbed (constructEmbed "Pick a defense to mount for 24 hours") |> ignore
constructButtons "Defend" (string player.DiscordId) player.Shields
|> Seq.cast<DiscordComponent>
|> builder.AddComponents
|> ignore
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
| None ->
let builder = DiscordInteractionResponseBuilder()
builder.Content <- "Error, please contact a moderator"
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task
[<SlashCommand("hack", "Send a hack attack to another player")>]
member this.Attack (ctx : InteractionContext) =
async {
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
match playerResult with
| Some player ->
let builder = DiscordInteractionResponseBuilder()
builder.AddEmbed (constructEmbed "Pick an attack to use on your target") |> ignore
constructButtons "Attack" (string player.DiscordId) player.Weapons
|> Seq.cast<DiscordComponent>
|> builder.AddComponents
|> ignore
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
| None ->
let builder = DiscordInteractionResponseBuilder()
builder.Content <- "Error, please contact a moderator"
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task
let sendMessage (event : ComponentInteractionCreateEventArgs) msg =
async {
@ -146,44 +84,76 @@ let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEve
|> Async.StartAsTask
:> Task
let config = DiscordConfiguration()
config.Token <- "OTMzMDg4MTQyNDM5ODk5MTg4.YeccDQ.AbysjlHICgbNQVyduG6aGIHNpdE"
config.TokenType <- TokenType.Bot
config.Intents <- DiscordIntents.All
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
let sendInitialEmbed (client : DiscordClient) =
async {
let! channel = client.GetChannelAsync(933298431521333258uL) |> Async.AwaitTask
let builder = DiscordMessageBuilder()
builder.Content <- "Welcome to the trainer bot, are you ready to get started?"
let button = DiscordButtonComponent(ButtonStyle.Success, $"Trainer-trainer-1", $"Get started") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! channel.SendMessageAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
} |> Async.RunSynchronously
let client = new DiscordClient(config)
type Trainer() =
inherit ApplicationCommandModule ()
let slash = client.UseSlashCommands()
[<SlashCommand("defend", "Create a passive defense that will last 24 hours")>]
member this.DefendCommand (ctx : InteractionContext) =
async {
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
match playerResult with
| Some player ->
let builder = DiscordInteractionResponseBuilder()
builder.AddEmbed (constructEmbed "Pick a defense to mount for 24 hours") |> ignore
client.add_ComponentInteractionCreated(AsyncEventHandler(handleButtonEvent))
constructButtons "Defend" (string player.DiscordId) player.Shields
|> Seq.cast<DiscordComponent>
|> builder.AddComponents
|> ignore
// My server
slash.RegisterCommands<Trainer>(922419263275425832uL);
// Degenz
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
builder.AsEphemeral true |> ignore
client.ConnectAsync ()
|> Async.AwaitTask
|> Async.RunSynchronously
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
| None ->
let builder = DiscordInteractionResponseBuilder()
builder.Content <- "Error, please contact a moderator"
async {
let! channel = client.GetChannelAsync(933298431521333258uL) |> Async.AwaitTask
let builder = DiscordMessageBuilder()
builder.Content <- "Welcome to the trainer bot, are you ready to get started?"
let button = DiscordButtonComponent(ButtonStyle.Success, $"Trainer-trainer-1", $"Get started") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! channel.SendMessageAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
} |> Async.RunSynchronously
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task
Task.Delay(-1)
|> Async.AwaitTask
|> Async.RunSynchronously
[<SlashCommand("hack", "Send a hack attack to another player")>]
member this.Attack (ctx : InteractionContext) =
async {
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
match playerResult with
| Some player ->
let builder = DiscordInteractionResponseBuilder()
builder.AddEmbed (constructEmbed "Pick an attack to use on your target") |> ignore
client.DisconnectAsync ()
|> Async.AwaitTask
|> Async.RunSynchronously
constructButtons "Attack" (string player.DiscordId) player.Weapons
|> Seq.cast<DiscordComponent>
|> builder.AddComponents
|> ignore
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
| None ->
let builder = DiscordInteractionResponseBuilder()
builder.Content <- "Error, please contact a moderator"
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task