use of net.robinfriedli.jxp.api.XmlElement in project aiode by robinfriedli.
the class InitialiseCommandContributionsTask method validateReferencedArguments.
private void validateReferencedArguments(CommandHierarchyNode<?> commandHierarchyNode, ArgumentContribution argumentContribution, Collection<XmlElement> arguments) {
for (XmlElement argument : arguments) {
String argumentIdentifier = argument.getAttribute("argument").getValue();
ArgumentContribution referencedArgument = commandHierarchyNode.getArgument(argumentIdentifier).unwrapArgumentContribution();
if (referencedArgument == null) {
throw new IllegalStateException(String.format("Invalid command configuration for node '%s'. Cannot find referenced argument identifier '%s' required for element %s on argument %s.", commandHierarchyNode.getId(), argumentIdentifier, argument, argumentContribution));
}
}
}
use of net.robinfriedli.jxp.api.XmlElement 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.api.XmlElement in project aiode by robinfriedli.
the class MigrateGuildSpecificationsTask method migrateSpecification.
private void migrateSpecification(JDA shard, XmlElement specification, Session session) {
String guildId = specification.getAttribute("guildId").getValue();
Guild guild = shard.getGuildById(guildId);
if (guild != null) {
Optional<GuildSpecification> existingGuildSpecification = session.createQuery("from " + GuildSpecification.class.getName() + " where guildId = '" + guild.getId() + "'", GuildSpecification.class).uniqueResultOptional();
if (existingGuildSpecification.isPresent()) {
return;
}
String botifyName = specification.getAttribute("botifyName").getValue();
String guildName = specification.getAttribute("guildName").getValue();
String prefix;
if (specification.hasAttribute("prefix")) {
prefix = specification.getAttribute("prefix").getValue();
} else {
prefix = null;
}
GuildSpecification guildSpecification = new GuildSpecification();
guildSpecification.setGuildName(guildName);
guildSpecification.setGuildId(guildId);
guildSpecification.setBotName(botifyName);
guildSpecification.setPrefix(prefix);
List<XmlElement> accessConfigurations = specification.query(tagName("accessConfiguration")).collect();
for (XmlElement accessConfiguration : accessConfigurations) {
String commandIdentifier = accessConfiguration.getAttribute("commandIdentifier").getValue();
AccessConfiguration ac = new AccessConfiguration(commandIdentifier, session);
String roleIdString = accessConfiguration.getAttribute("roleIds").getValue();
Iterable<String> roleIds = splitter.split(roleIdString);
for (String roleId : roleIds) {
Role role = guild.getRoleById(roleId);
if (role != null) {
GrantedRole grantedRole = new GrantedRole(role);
session.persist(grantedRole);
ac.addRole(grantedRole);
}
}
guildSpecification.addAccessConfiguration(ac);
session.persist(ac);
}
session.persist(guildSpecification);
}
}
use of net.robinfriedli.jxp.api.XmlElement in project aiode by robinfriedli.
the class SetRedirectedSpotifyTrackNameTask method migrate.
private void migrate(Context context, SpotifyApi spotifyApi) throws IOException, SpotifyWebApiException, ParseException {
for (XmlElement playlist : context.query(tagName("playlist")).collect()) {
Map<String, XmlElement> itemsToMigrate = new HashMap<>();
for (XmlElement playlistItem : playlist.getSubElements()) {
if (playlistItem.hasAttribute("redirectedSpotifyId") && !playlistItem.hasAttribute("spotifyTrackName")) {
String trackId = playlistItem.getAttribute("redirectedSpotifyId").getValue();
itemsToMigrate.put(trackId, playlistItem);
}
}
List<List<String>> batches = Lists.partition(Lists.newArrayList(itemsToMigrate.keySet()), 50);
for (List<String> batch : batches) {
Track[] tracks = spotifyApi.getSeveralTracks(batch.toArray(new String[0])).build().execute();
for (Track track : tracks) {
XmlElement playlistItem = itemsToMigrate.get(track.getId());
playlistItem.setAttribute("spotifyTrackName", track.getName());
}
}
}
}
use of net.robinfriedli.jxp.api.XmlElement in project aiode by robinfriedli.
the class EmbedDocumentContribution method buildEmbed.
public EmbedBuilder buildEmbed() {
Aiode aiode = Aiode.get();
groovyShell.setProperty("aiode", aiode);
groovyShell.setProperty("properties", aiode.getSpringPropertiesConfig());
String title = getAttribute("title").getValue();
String description = getAttribute("description").getValue();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle(title);
embedBuilder.setDescription(description);
for (XmlElement field : getSubElements()) {
if (field.hasAttribute("displayPredicate")) {
Object displayPredicateResult = groovyShell.evaluate(field.getAttribute("displayPredicate").getValue());
if (!(displayPredicateResult instanceof Boolean)) {
throw new IllegalStateException("displayPredicate did not return a boolean");
}
if (!((boolean) displayPredicateResult)) {
continue;
}
}
String fieldTitle = field.getAttribute("title").getValue();
boolean inline = field.getAttribute("inline").getBool();
embedBuilder.addField(fieldTitle, field.getTextContent(), inline);
}
return embedBuilder;
}
Aggregations