use of net.robinfriedli.aiode.entities.xml.Version 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.entities.xml.Version 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");
}
}
Aggregations