136 lines
5.1 KiB
Forth

module Degenz.Bot
open System.IO
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.SlashCommands
open Degenz
open Emzi0767.Utilities
//open Degenz.SlotMachine
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
let guild = GuildEnvironment.guildId
let hackerBattleConfig = DiscordConfiguration()
let storeConfig = DiscordConfiguration()
let stealConfig = DiscordConfiguration()
let inviterConfig = DiscordConfiguration()
//let slotMachineConfig = DiscordConfiguration()
//hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
//storeConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
hackerBattleConfig.TokenType <- TokenType.Bot
hackerBattleConfig.Intents <- DiscordIntents.All
storeConfig.TokenType <- TokenType.Bot
storeConfig.Intents <- DiscordIntents.All
stealConfig.TokenType <- TokenType.Bot
stealConfig.Intents <- DiscordIntents.All
inviterConfig.TokenType <- TokenType.Bot
inviterConfig.Intents <- DiscordIntents.All
hackerBattleConfig.Token <- GuildEnvironment.tokenHackerBattle
storeConfig.Token <- GuildEnvironment.tokenStore
stealConfig.Token <- GuildEnvironment.tokenSteal
inviterConfig.Token <- GuildEnvironment.tokenInviter
//slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE")
let hackerBattleBot = new DiscordClient(hackerBattleConfig)
let storeBot = new DiscordClient(storeConfig)
let stealBot = new DiscordClient(stealConfig)
let inviterBot = new DiscordClient(inviterConfig)
//let slotMachineBot = new DiscordClient(slotMachineConfig)
//let clients = [| hackerBattleBot ; storeBot ; slotMachineBot |]
let hackerCommands = hackerBattleBot.UseSlashCommands()
let storeCommands = storeBot.UseSlashCommands()
let stealCommands = stealBot.UseSlashCommands()
let inviterCommands = inviterBot.UseSlashCommands()
//let sc3 = slotMachineBot.UseSlashCommands()
hackerCommands.RegisterCommands<HackerBattle.HackerGame>(guild);
storeCommands.RegisterCommands<Store.Store>(guild);
stealCommands.RegisterCommands<Thief.StealGame>(guild);
inviterCommands.RegisterCommands<InviteTracker.Inviter>(guild);
//hackerCommands.RegisterCommands<RPSGame>(guild);
//sc3.RegisterCommands<SlotMachine>(guild);
hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent))
storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleStoreEvents))
stealBot.add_ComponentInteractionCreated(AsyncEventHandler(Thief.handleStealButton))
inviterBot.add_GuildMemberAdded(AsyncEventHandler(InviteTracker.handleGuildMemberAdded))
inviterBot.add_ComponentInteractionCreated(AsyncEventHandler(InviteTracker.handleButtonEvent))
//inviterBot.add_GuildMemberRemoved(AsyncEventHandler(InviteTracker.handleGuildMemberRemoved))
let asdf (_ : DiscordClient) (event : DSharpPlus.EventArgs.InteractionCreateEventArgs) =
async {
printfn "%A" event.Interaction.Type
match event.Interaction.Type with
| InteractionType.AutoComplete ->
printfn "%A" event.Interaction.Data.Options
let builder = DSharpPlus.Entities.DiscordInteractionResponseBuilder()
builder.AddAutoCompleteChoice(DSharpPlus.Entities.DiscordAutoCompleteChoice("Choice 1", "What does this represent?"))
|> ignore
do! event.Interaction.CreateResponseAsync(InteractionResponseType.AutoCompleteResult, builder)
|> Async.AwaitTask
| _ -> return ()
} |> Async.StartAsTask
:> Task
//hackerBattleBot.add_InteractionCreated(AsyncEventHandler(asdf))
//if guild <> 922419263275425832uL then
// Trainer.sendInitialEmbed hackerBattleBot
InviteTracker.sendInitialEmbed inviterBot
hackerBattleBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
GuildEnvironment.botUserHackerBattle <- Some hackerBattleBot.CurrentUser
storeBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
GuildEnvironment.botUserArmory <- Some storeBot.CurrentUser
//stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
inviterBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
let rec loop areBotsRunning =
async {
if not (File.Exists "fsharp-bots") then
use file = File.Create "fsharp-bots"
file.Flush()
let! file = File.ReadAllTextAsync("fsharp-bots") |> Async.AwaitTask
let! ran =
async {
if areBotsRunning && file.StartsWith "kill" then
printfn "Disconnecting bots"
do! hackerBattleBot.DisconnectAsync() |> Async.AwaitTask
do! storeBot.DisconnectAsync() |> Async.AwaitTask
return false
elif not areBotsRunning && not (file.StartsWith "kill") then
printfn "Reconnecting bots"
do! hackerBattleBot.ConnectAsync() |> Async.AwaitTask
do! storeBot.ConnectAsync() |> Async.AwaitTask
return true
else
return areBotsRunning
}
do! Async.Sleep 3000
return! loop (ran)
}
//Async.Start (loop true)
Task.Delay(-1)
|> Async.AwaitTask
|> Async.RunSynchronously