2022-01-20 20:24:21 +07:00

83 lines
2.7 KiB
Forth

module Degenz.Bot
open System
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.SlashCommands
open Degenz.PlayerInteractions
open Degenz.SlotMachine
open Degenz.Trainer
open Degenz.HackerBattle
open Degenz.Store
open Emzi0767.Utilities
open dotenv.net
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
let playerInteractionsConfig = DiscordConfiguration()
let trainerConfig = DiscordConfiguration()
let hackerBattleConfig = DiscordConfiguration()
let storeConfig = DiscordConfiguration()
let slotMachineConfig = DiscordConfiguration()
let configs = [| playerInteractionsConfig ; trainerConfig ; hackerBattleConfig ; storeConfig ; slotMachineConfig ; |]
for conf in configs do
conf.TokenType <- TokenType.Bot
conf.Intents <- DiscordIntents.All
DotEnv.Load(DotEnvOptions(probeForEnv = true, probeLevelsToSearch = 5, overwriteExistingVars = false))
let guild = Environment.GetEnvironmentVariable("DISCORD_GUILD") |> uint64
playerInteractionsConfig.Token <- Environment.GetEnvironmentVariable("BOT_PLAYER_INTERACTIONS")
trainerConfig.Token <- Environment.GetEnvironmentVariable("BOT_TRAINER")
hackerBattleConfig.Token <- Environment.GetEnvironmentVariable("BOT_HACKER_BATTLE")
storeConfig.Token <- Environment.GetEnvironmentVariable("BOT_STORE")
slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE")
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
let playerInteractionsBot = new DiscordClient(playerInteractionsConfig)
let trainerBot = new DiscordClient(trainerConfig)
let hackerBattleBot = new DiscordClient(hackerBattleConfig)
let storeBot = new DiscordClient(storeConfig)
let slotMachineBot = new DiscordClient(slotMachineConfig)
hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent))
trainerBot.add_ComponentInteractionCreated(AsyncEventHandler(Trainer.handleButtonEvent))
let clients = [| playerInteractionsBot ; trainerBot ; hackerBattleBot ; storeBot ; slotMachineBot |]
let sc1 = playerInteractionsBot.UseSlashCommands()
let sc2 = trainerBot.UseSlashCommands()
let sc3 = hackerBattleBot.UseSlashCommands()
let sc4 = storeBot.UseSlashCommands()
let sc5 = slotMachineBot.UseSlashCommands()
sc1.RegisterCommands<PlayerInteractions>(guild);
sc2.RegisterCommands<Trainer>(guild);
sc3.RegisterCommands<HackerGame>(guild);
sc4.RegisterCommands<Store>(guild);
sc5.RegisterCommands<SlotMachine>(guild);
let run (client : DiscordClient) =
async {
do! client.ConnectAsync () |> Async.AwaitTask
}
clients
|> Array.map run
|> Array.toSeq
|> Async.Sequential
|> Async.RunSynchronously
|> ignore
Task.Delay(-1)
|> Async.AwaitTask
|> Async.RunSynchronously