Search in sources :

Example 1 with JxpBackend

use of net.robinfriedli.jxp.api.JxpBackend in project aiode by robinfriedli.

the class SpringBootstrap method run.

@Override
public void run(String... args) {
    Logger logger = LoggerFactory.getLogger(SpringBootstrap.class);
    logger.info("Using java version " + System.getProperty("java.runtime.version"));
    try {
        Aiode aiode = Aiode.get();
        CommandManager commandManager = aiode.getCommandManager();
        HttpServerManager serverManager = aiode.getHttpServerManager();
        JxpBackend jxpBackend = aiode.getJxpBackend();
        CronJobService cronJobService = aiode.getCronJobService();
        commandManager.initializeInterceptorChain();
        serverManager.start();
        // run startup tasks
        InputStream startupTasksFile = getClass().getResourceAsStream("/xml-contributions/startupTasks.xml");
        Context context = jxpBackend.createContext(startupTasksFile);
        for (StartupTaskContribution element : context.getInstancesOf(StartupTaskContribution.class)) {
            if (!aiode.isMainInstance() && element.getAttribute("mainInstanceOnly").getBool()) {
                continue;
            }
            if (!element.getAttribute("runForEachShard").getBool()) {
                element.instantiate().runTask(null);
            }
        }
        cronJobService.scheduleAll();
        Aiode.registerListeners();
        logger.info("All starters done");
    } catch (Throwable e) {
        logger.error("Exception in starter. Application will terminate.", e);
        System.exit(1);
    }
}
Also used : CronJobService(net.robinfriedli.aiode.cron.CronJobService) Context(net.robinfriedli.jxp.persist.Context) CommandManager(net.robinfriedli.aiode.command.CommandManager) InputStream(java.io.InputStream) JxpBackend(net.robinfriedli.jxp.api.JxpBackend) StartupTaskContribution(net.robinfriedli.aiode.entities.xml.StartupTaskContribution) Logger(org.slf4j.Logger) Aiode(net.robinfriedli.aiode.Aiode) HttpServerManager(net.robinfriedli.aiode.servers.HttpServerManager)

Example 2 with JxpBackend

use of net.robinfriedli.jxp.api.JxpBackend in project aiode by robinfriedli.

the class LoadDocumentCommand method runAdmin.

@Override
public void runAdmin() {
    JxpBackend jxpBackend = Aiode.get().getJxpBackend();
    EmbedBuilder embedBuilder;
    InputStream embedDocumentResource = getClass().getResourceAsStream("/xml-contributions/embedDocuments.xml");
    try (Context context = jxpBackend.createLazyContext(embedDocumentResource)) {
        if (getCommandInput().isBlank()) {
            List<EmbedDocumentContribution> documents = context.getInstancesOf(EmbedDocumentContribution.class);
            embedBuilder = new EmbedBuilder();
            Util.appendEmbedList(embedBuilder, documents, EmbedDocumentContribution::getName, "Documents");
        } else {
            EmbedDocumentContribution document = context.query(attribute("name").fuzzyIs(getCommandInput()), EmbedDocumentContribution.class).getOnlyResult();
            if (document == null) {
                throw new InvalidCommandException(String.format("No embed document found for '%s'", getCommandInput()));
            }
            embedBuilder = document.buildEmbed();
        }
    }
    sendMessage(embedBuilder);
}
Also used : Context(net.robinfriedli.jxp.persist.Context) CommandContext(net.robinfriedli.aiode.command.CommandContext) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) InputStream(java.io.InputStream) JxpBackend(net.robinfriedli.jxp.api.JxpBackend) EmbedDocumentContribution(net.robinfriedli.aiode.entities.xml.EmbedDocumentContribution)

Aggregations

InputStream (java.io.InputStream)2 JxpBackend (net.robinfriedli.jxp.api.JxpBackend)2 Context (net.robinfriedli.jxp.persist.Context)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 Aiode (net.robinfriedli.aiode.Aiode)1 CommandContext (net.robinfriedli.aiode.command.CommandContext)1 CommandManager (net.robinfriedli.aiode.command.CommandManager)1 CronJobService (net.robinfriedli.aiode.cron.CronJobService)1 EmbedDocumentContribution (net.robinfriedli.aiode.entities.xml.EmbedDocumentContribution)1 StartupTaskContribution (net.robinfriedli.aiode.entities.xml.StartupTaskContribution)1 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)1 HttpServerManager (net.robinfriedli.aiode.servers.HttpServerManager)1 Logger (org.slf4j.Logger)1