use of net.robinfriedli.aiode.function.CheckedConsumer in project aiode by robinfriedli.
the class VersionUpdateAlertTask method sendUpdateAlert.
private void sendUpdateAlert(Context context, Version versionElem, JDA shard) {
List<XmlElement> lowerLaunchedVersions = context.query(and(tagName("version"), attribute("launched").is(true), lowerVersionThan(versionElem.getVersion()))).collect();
if (!lowerLaunchedVersions.isEmpty()) {
String message = "Aiode has been updated to " + versionElem.getVersion() + ". [Check the releases here](" + "https://github.com/robinfriedli/botify/releases)";
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Update");
embedBuilder.setDescription(message);
List<XmlElement> features = versionElem.query(tagName("feature")).collect();
if (!features.isEmpty()) {
embedBuilder.addField("**Features**", "Changes in this update", false);
for (XmlElement feature : features) {
embedBuilder.addField(feature.getAttribute("title").getValue(), feature.getTextContent(), false);
}
}
List<Guild> guilds = shard.getGuilds();
long delaySecs = OFFSET++ * (guilds.size() / MESSAGES_PER_SECOND);
if (delaySecs > 0) {
delaySecs += 10;
}
MESSAGE_DISPATCH.schedule(() -> {
// with the other shards
synchronized (DISPATCH_LOCK) {
// setup current thread session and handle all guilds within one session instead of opening a new session for each
StaticSessionProvider.consumeSession((CheckedConsumer<Session>) session -> {
int counter = 0;
long currentTimeMillis = System.currentTimeMillis();
for (Guild guild : guilds) {
messageService.sendWithLogo(embedBuilder, guild);
if (++counter % MESSAGES_PER_SECOND == 0) {
long delta = System.currentTimeMillis() - currentTimeMillis;
if (delta < 1000) {
Thread.sleep(1000 - delta);
}
currentTimeMillis = System.currentTimeMillis();
}
}
});
}
}, delaySecs, TimeUnit.SECONDS);
}
}
use of net.robinfriedli.aiode.function.CheckedConsumer in project aiode by robinfriedli.
the class HollowYouTubeVideo method fetch.
@Override
public Playable fetch() {
// only supported for Spotify redirect as YouTube does not allow loading specific playlist items
if (isHollow() && redirectedSpotifyTrack != null) {
markLoading();
EagerFetchQueue.submitFetch(() -> StaticSessionProvider.consumeSession((CheckedConsumer<Session>) session -> {
SpotifyRedirectService spotifyRedirectService = new SpotifyRedirectService(session, youTubeService);
spotifyRedirectService.redirectTrack(this);
}));
}
return this;
}
Aggregations