use of net.robinfriedli.aiode.entities.xml.EmbedDocumentContribution 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);
}
use of net.robinfriedli.aiode.entities.xml.EmbedDocumentContribution in project aiode by robinfriedli.
the class GuildManager method handleNewGuild.
private void handleNewGuild(Guild guild, GuildContext guildContext) {
Aiode aiode = Aiode.get();
MessageService messageService = aiode.getMessageService();
try {
EmbedDocumentContribution embedDocumentContribution = embedDocumentContext.query(attribute("name").is("getting-started"), EmbedDocumentContribution.class).getOnlyResult();
if (embedDocumentContribution != null) {
EmbedBuilder embedBuilder = embedDocumentContribution.buildEmbed();
TextChannel defaultTextChannelForGuild = getDefaultTextChannelForGuild(guild, guildContext);
if (defaultTextChannelForGuild != null) {
messageService.sendWithLogo(embedBuilder, defaultTextChannelForGuild);
}
}
} catch (Exception e) {
logger.error("Error sending getting started message", e);
}
SessionFactory sessionFactory = hibernateComponent.getSessionFactory();
SpotifyApi.Builder spotifyApiBuilder = aiode.getSpotifyApiBuilder();
if (defaultPlaylistContext != null) {
try (Session session = sessionFactory.withOptions().interceptor(InterceptorChain.of(PlaylistItemTimestampInterceptor.class, VerifyPlaylistInterceptor.class)).openSession()) {
HibernatePlaylistMigrator hibernatePlaylistMigrator = new HibernatePlaylistMigrator(defaultPlaylistContext, guild, spotifyApiBuilder.build(), session);
Map<Playlist, List<PlaylistItem>> playlistMap = hibernatePlaylistMigrator.perform();
Mode mode = getMode();
HibernateInvoker.create(session).invokeConsumer(currentSession -> {
for (Playlist playlist : playlistMap.keySet()) {
Playlist existingList = SearchEngine.searchLocalList(currentSession, playlist.getName(), mode == GuildManager.Mode.PARTITIONED, guild.getId());
if (existingList == null) {
playlistMap.get(playlist).forEach(item -> {
item.add();
currentSession.persist(item);
});
currentSession.persist(playlist);
}
}
});
} catch (Exception e) {
logger.error("Exception while setting up default playlists", e);
}
}
}
Aggregations