|
|
|
@ -18,10 +18,12 @@ import net.fortuna.ical4j.model.Date |
|
|
|
import net.fortuna.ical4j.model.DateTime |
|
|
|
import net.fortuna.ical4j.model.Period |
|
|
|
import net.fortuna.ical4j.model.component.VEvent |
|
|
|
import org.reflections.Reflections |
|
|
|
import org.slf4j.LoggerFactory |
|
|
|
import org.yaml.snakeyaml.Yaml |
|
|
|
import tech.junodevs.discord.kriess.impl.managers.CommandManager |
|
|
|
import tech.junodevs.discord.kriess.menus.MenuListener |
|
|
|
import tech.junodevs.discord.kriess.services.Service |
|
|
|
import xyz.brettb.discord.ieeevents.commands.CommandBase |
|
|
|
import xyz.brettb.discord.ieeevents.commands.info.HelpCommand |
|
|
|
import xyz.brettb.discord.ieeevents.commands.info.UpcomingEventsCommand |
|
|
|
@ -29,6 +31,7 @@ import xyz.brettb.discord.ieeevents.commands.settings.ChangePrefixCommand |
|
|
|
import xyz.brettb.discord.ieeevents.data.settings.IEEEventsGuildSettings |
|
|
|
import xyz.brettb.discord.ieeevents.data.settings.IEEEventsGuildSettingsManager |
|
|
|
import xyz.brettb.discord.ieeevents.services.StatusService |
|
|
|
import xyz.brettb.discord.ieeevents.services.ToggleableService |
|
|
|
import java.io.File |
|
|
|
import java.io.FileInputStream |
|
|
|
import java.nio.file.Files |
|
|
|
@ -40,7 +43,7 @@ val logger = LoggerFactory.getLogger(IEEEventsBot.javaClass) |
|
|
|
|
|
|
|
fun main() { |
|
|
|
logger.info("IEEEvents Bot") |
|
|
|
|
|
|
|
|
|
|
|
IEEEventsBot.load() |
|
|
|
|
|
|
|
IEEEventsBot.JDA = JDABuilder |
|
|
|
@ -66,7 +69,9 @@ fun main() { |
|
|
|
|
|
|
|
// Ensure the StatusService stops correctly |
|
|
|
Runtime.getRuntime().addShutdownHook(Thread { |
|
|
|
StatusService.shutdown() |
|
|
|
IEEEventsBot.services.forEach{ service -> |
|
|
|
(service.getDeclaredField("INSTANCE")[null] as ToggleableService).shutdown() |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
@ -139,13 +144,33 @@ object IEEEventsBot : EventListener { |
|
|
|
/** |
|
|
|
* The commands the bot has. |
|
|
|
*/ |
|
|
|
val commands: List<CommandBase> = listOf( |
|
|
|
// SetEventsChannelCommand, |
|
|
|
HelpCommand, |
|
|
|
ChangePrefixCommand, |
|
|
|
UpcomingEventsCommand, |
|
|
|
// PingCommand |
|
|
|
) |
|
|
|
val commands: List<Class<out CommandBase>> = |
|
|
|
Reflections("xyz.brettb.discord.ieeevents.commands").getSubTypesOf(CommandBase::class.java) |
|
|
|
.filterNot { |
|
|
|
it.isMemberClass |
|
|
|
} |
|
|
|
.filter { |
|
|
|
try { |
|
|
|
it.getDeclaredField("INSTANCE")[null]; true |
|
|
|
} catch (_: Throwable) { |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
.sortedBy { it.name } |
|
|
|
|
|
|
|
/** |
|
|
|
* The services the bot is using. |
|
|
|
*/ |
|
|
|
val services: List<Class<out ToggleableService>> = |
|
|
|
Reflections("xyz.brettb.discord.ieeevents.services").getSubTypesOf(ToggleableService::class.java) |
|
|
|
.filter { |
|
|
|
try { |
|
|
|
val ts = it.getDeclaredField("INSTANCE")[null] as ToggleableService |
|
|
|
ts.enabled |
|
|
|
} catch (_: Throwable) { |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes the bot |
|
|
|
@ -180,14 +205,16 @@ object IEEEventsBot : EventListener { |
|
|
|
|
|
|
|
// Initialize the commands |
|
|
|
commands.forEach { command -> |
|
|
|
commandManager.addCommand(command) |
|
|
|
commandManager.addCommand((command.getDeclaredField("INSTANCE")[null] as CommandBase)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
override fun onEvent(event: GenericEvent) { |
|
|
|
when (event) { |
|
|
|
is ReadyEvent -> { |
|
|
|
StatusService.start() |
|
|
|
services.forEach { service -> |
|
|
|
(service.getDeclaredField("INSTANCE")[null] as ToggleableService).start() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |