Some clean up
This commit is contained in:
		
							parent
							
								
									116ab79e8a
								
							
						
					
					
						commit
						a08c66a84d
					
				@ -4,8 +4,6 @@ open System
 | 
				
			|||||||
open System.Threading.Tasks
 | 
					open System.Threading.Tasks
 | 
				
			||||||
open DSharpPlus
 | 
					open DSharpPlus
 | 
				
			||||||
open DSharpPlus.SlashCommands
 | 
					open DSharpPlus.SlashCommands
 | 
				
			||||||
open Degenz.Shared
 | 
					 | 
				
			||||||
open Emzi0767.Utilities
 | 
					 | 
				
			||||||
open Degenz.PlayerInteractions
 | 
					open Degenz.PlayerInteractions
 | 
				
			||||||
open Degenz.SlotMachine
 | 
					open Degenz.SlotMachine
 | 
				
			||||||
open Degenz.Trainer
 | 
					open Degenz.Trainer
 | 
				
			||||||
@ -29,7 +27,6 @@ for conf in configs do
 | 
				
			|||||||
    conf.Intents <- DiscordIntents.All
 | 
					    conf.Intents <- DiscordIntents.All
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 4))
 | 
					 | 
				
			||||||
DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 5, overwriteExistingVars = false))
 | 
					DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 5, overwriteExistingVars = false))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let guild = Environment.GetEnvironmentVariable("DISCORD_GUILD") |> uint64
 | 
					let guild = Environment.GetEnvironmentVariable("DISCORD_GUILD") |> uint64
 | 
				
			||||||
@ -61,8 +58,6 @@ sc2.RegisterCommands<Trainer>(guild);
 | 
				
			|||||||
sc3.RegisterCommands<HackerGame>(guild);
 | 
					sc3.RegisterCommands<HackerGame>(guild);
 | 
				
			||||||
sc4.RegisterCommands<Store>(guild);
 | 
					sc4.RegisterCommands<Store>(guild);
 | 
				
			||||||
sc5.RegisterCommands<SlotMachine>(guild);
 | 
					sc5.RegisterCommands<SlotMachine>(guild);
 | 
				
			||||||
// Degenz
 | 
					 | 
				
			||||||
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
let run (client : DiscordClient) =
 | 
					let run (client : DiscordClient) =
 | 
				
			||||||
    async {
 | 
					    async {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,6 @@ open DSharpPlus.Entities
 | 
				
			|||||||
open DSharpPlus.EventArgs
 | 
					open DSharpPlus.EventArgs
 | 
				
			||||||
open DSharpPlus.SlashCommands
 | 
					open DSharpPlus.SlashCommands
 | 
				
			||||||
open Degenz
 | 
					open Degenz
 | 
				
			||||||
open Emzi0767.Utilities
 | 
					 | 
				
			||||||
open Degenz.Shared
 | 
					open Degenz.Shared
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[<Literal>]
 | 
					[<Literal>]
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@ open System
 | 
				
			|||||||
open System.Threading.Tasks
 | 
					open System.Threading.Tasks
 | 
				
			||||||
open DSharpPlus.Entities
 | 
					open DSharpPlus.Entities
 | 
				
			||||||
open DSharpPlus
 | 
					open DSharpPlus
 | 
				
			||||||
open DSharpPlus.EventArgs
 | 
					 | 
				
			||||||
open DSharpPlus.SlashCommands
 | 
					open DSharpPlus.SlashCommands
 | 
				
			||||||
open Degenz
 | 
					open Degenz
 | 
				
			||||||
open Degenz.Shared
 | 
					open Degenz.Shared
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,6 @@ open DSharpPlus.EventArgs
 | 
				
			|||||||
open DSharpPlus.SlashCommands
 | 
					open DSharpPlus.SlashCommands
 | 
				
			||||||
open Degenz
 | 
					open Degenz
 | 
				
			||||||
open Degenz.Shared
 | 
					open Degenz.Shared
 | 
				
			||||||
open Emzi0767.Utilities
 | 
					 | 
				
			||||||
open Newtonsoft.Json
 | 
					open Newtonsoft.Json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let store =
 | 
					let store =
 | 
				
			||||||
 | 
				
			|||||||
@ -6,68 +6,6 @@ open DSharpPlus.Entities
 | 
				
			|||||||
open DSharpPlus.EventArgs
 | 
					open DSharpPlus.EventArgs
 | 
				
			||||||
open DSharpPlus.SlashCommands
 | 
					open DSharpPlus.SlashCommands
 | 
				
			||||||
open Degenz.Shared
 | 
					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 =
 | 
					let sendMessage (event : ComponentInteractionCreateEventArgs) msg =
 | 
				
			||||||
    async {
 | 
					    async {
 | 
				
			||||||
@ -146,44 +84,76 @@ let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEve
 | 
				
			|||||||
    |> Async.StartAsTask
 | 
					    |> Async.StartAsTask
 | 
				
			||||||
    :> Task
 | 
					    :> Task
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let config = DiscordConfiguration()
 | 
					let sendInitialEmbed (client : DiscordClient)  =
 | 
				
			||||||
config.Token <- "OTMzMDg4MTQyNDM5ODk5MTg4.YeccDQ.AbysjlHICgbNQVyduG6aGIHNpdE"
 | 
					    async {
 | 
				
			||||||
config.TokenType <- TokenType.Bot
 | 
					        let! channel = client.GetChannelAsync(933298431521333258uL) |> Async.AwaitTask
 | 
				
			||||||
config.Intents <- DiscordIntents.All
 | 
					        let builder = DiscordMessageBuilder()
 | 
				
			||||||
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
 | 
					        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
 | 
					                builder.AsEphemeral true |> ignore
 | 
				
			||||||
slash.RegisterCommands<Trainer>(922419263275425832uL);
 | 
					 | 
				
			||||||
// Degenz
 | 
					 | 
				
			||||||
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
client.ConnectAsync ()
 | 
					                do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
 | 
				
			||||||
|> Async.AwaitTask
 | 
					                    |> Async.AwaitTask
 | 
				
			||||||
|> Async.RunSynchronously
 | 
					            | None ->
 | 
				
			||||||
 | 
					                let builder = DiscordInteractionResponseBuilder()
 | 
				
			||||||
 | 
					                builder.Content <- "Error, please contact a moderator"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async {
 | 
					                builder.AsEphemeral true |> ignore
 | 
				
			||||||
    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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
 | 
				
			||||||
 | 
					                    |> Async.AwaitTask
 | 
				
			||||||
 | 
					        } |> Async.StartAsTask
 | 
				
			||||||
 | 
					        :> Task
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Task.Delay(-1)
 | 
					    [<SlashCommand("hack", "Send a hack attack to another player")>]
 | 
				
			||||||
|> Async.AwaitTask
 | 
					    member this.Attack (ctx : InteractionContext) =
 | 
				
			||||||
|> Async.RunSynchronously
 | 
					        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 ()
 | 
					                constructButtons "Attack" (string player.DiscordId) player.Weapons
 | 
				
			||||||
|> Async.AwaitTask
 | 
					                |> Seq.cast<DiscordComponent>
 | 
				
			||||||
|> Async.RunSynchronously
 | 
					                |> 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user