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);
}
}
}
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()));
}
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);
}
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");
}
}
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);
}
Aggregations