Search in sources :

Example 6 with Context

use of net.robinfriedli.jxp.persist.Context in project aiode by robinfriedli.

the class InitialiseCommandContributionsTask method perform.

@Override
public void perform(@Nullable JDA shard) throws Exception {
    Context commandContributionContext = commandManager.getCommandContributionContext();
    @SuppressWarnings("rawtypes") List<CommandHierarchyNode> commandHierarchyNodes = commandContributionContext.getInstancesOf(CommandHierarchyNode.class);
    for (@SuppressWarnings("unchecked") CommandHierarchyNode<ArgumentContributionDelegate> commandHierarchyNode : commandHierarchyNodes) {
        Map<String, ArgumentContributionDelegate> argumentContributions = commandHierarchyNode.getArguments();
        for (ArgumentContributionDelegate argumentContributionDelegate : argumentContributions.values()) {
            ArgumentContribution argumentContribution = argumentContributionDelegate.unwrapArgumentContribution();
            List<XmlElement> excludedArguments = argumentContribution.getExcludedArguments();
            List<XmlElement> requiredArguments = argumentContribution.getRequiredArguments();
            validateReferencedArguments(commandHierarchyNode, argumentContribution, excludedArguments);
            validateReferencedArguments(commandHierarchyNode, argumentContribution, requiredArguments);
        }
    }
}
Also used : Context(net.robinfriedli.jxp.persist.Context) CommandHierarchyNode(net.robinfriedli.aiode.entities.xml.CommandHierarchyNode) XmlElement(net.robinfriedli.jxp.api.XmlElement) ArgumentContributionDelegate(net.robinfriedli.aiode.command.argument.ArgumentContributionDelegate) ArgumentContribution(net.robinfriedli.aiode.entities.xml.ArgumentContribution)

Example 7 with Context

use of net.robinfriedli.jxp.persist.Context in project aiode by robinfriedli.

the class MigrateGuildSpecificationsTask method migrateSpecifications.

private void migrateSpecifications(JDA shard, File file, Session session) throws IOException {
    try (Context context = jxpBackend.getContext(file)) {
        List<XmlElement> guildSpecifications = context.query(tagName("guildSpecification")).collect();
        for (XmlElement guildSpecification : guildSpecifications) {
            migrateSpecification(shard, guildSpecification, session);
        }
    }
    File directory = new File("./resources/archive");
    if (!directory.exists()) {
        directory.mkdir();
    }
    Objects.requireNonNull(file);
    Files.move(file, new File(directory.getPath() + "/" + file.getName()));
}
Also used : Context(net.robinfriedli.jxp.persist.Context) XmlElement(net.robinfriedli.jxp.api.XmlElement) File(java.io.File)

Example 8 with Context

use of net.robinfriedli.jxp.persist.Context in project aiode by robinfriedli.

the class SetRedirectedSpotifyTrackNameTask method perform.

@Override
public void perform(@Nullable JDA shard) throws Exception {
    ClientCredentials clientCredentials = spotifyApi.clientCredentials().build().execute();
    spotifyApi.setAccessToken(clientCredentials.getAccessToken());
    File file = new File("src/main/resources/playlists.xml");
    if (file.exists()) {
        try (Context context = jxpBackend.getContext(file)) {
            context.invoke(() -> {
                try {
                    migrate(context, spotifyApi);
                } catch (IOException | SpotifyWebApiException | ParseException e) {
                    throw new RuntimeException(e);
                }
            });
        }
    }
    spotifyApi.setAccessToken(null);
}
Also used : Context(net.robinfriedli.jxp.persist.Context) IOException(java.io.IOException) ParseException(org.apache.hc.core5.http.ParseException) ClientCredentials(se.michaelthelin.spotify.model_objects.credentials.ClientCredentials) File(java.io.File) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException)

Example 9 with Context

use of net.robinfriedli.jxp.persist.Context in project aiode by robinfriedli.

the class VersionUpdateAlertTask method perform.

@Override
public void perform(@Nullable JDA shard) {
    Logger logger = LoggerFactory.getLogger(getClass());
    Version versionElem = versionManager.getCurrentVersion();
    if (versionElem != null) {
        Context context = versionManager.getContext();
        if (UPDATED || !versionElem.getAttribute("launched").getBool()) {
            UPDATED = true;
            if (!(versionElem.hasAttribute("silent") && versionElem.getAttribute("silent").getBool())) {
                sendUpdateAlert(context, versionElem, shard);
            }
            context.invoke(() -> versionElem.setAttribute("launched", true));
        }
    } else {
        logger.warn("Current version has no version element in versions.xml");
    }
}
Also used : Context(net.robinfriedli.jxp.persist.Context) Version(net.robinfriedli.aiode.entities.xml.Version) Logger(org.slf4j.Logger)

Example 10 with Context

use of net.robinfriedli.jxp.persist.Context 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

Context (net.robinfriedli.jxp.persist.Context)10 XmlElement (net.robinfriedli.jxp.api.XmlElement)4 Logger (org.slf4j.Logger)4 File (java.io.File)3 JxpBackend (net.robinfriedli.jxp.api.JxpBackend)3 Conditions (net.robinfriedli.jxp.queries.Conditions)3 Session (org.hibernate.Session)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 Guild (net.dv8tion.jda.api.entities.Guild)2 Aiode (net.robinfriedli.aiode.Aiode)2 MessageService (net.robinfriedli.aiode.discord.MessageService)2 StartupTaskContribution (net.robinfriedli.aiode.entities.xml.StartupTaskContribution)2 LoggerFactory (org.slf4j.LoggerFactory)2 Sets (com.google.api.client.util.Sets)1 Lists (com.google.common.collect.Lists)1