Skip to content

Commit

Permalink
release update v1.6.1.2 and enable silent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
robinfriedli committed Jul 27, 2019
1 parent b74ed09 commit d7cd269
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 42 deletions.
2 changes: 1 addition & 1 deletion resources/current-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.1.1
1.6.1.2
1 change: 1 addition & 0 deletions resources/schemas/versionSchema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</xs:sequence>
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="launched" type="xs:boolean"/>
<xs:attribute name="silent" type="xs:boolean" default="false"/>
</xs:complexType>

</xs:schema>
8 changes: 7 additions & 1 deletion resources/versions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<versions xmlns="versionSpace">
<version launched="false" version="1.6.1.1">
<version launched="false" silent="true" version="1.6.1.2">
<feature>enable silent updates</feature>
<feature>fix export command</feature>
<feature>fix Playable#matches</feature>
<feature>improve upload command</feature>
</version>
<version launched="true" version="1.6.1.1">
<feature>improve and add new admin tools</feature>
<feature>fix wrong behavior of the play / pause action when the bot left the channel</feature>
<feature>minor improvements</feature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
Expand Down Expand Up @@ -38,29 +39,8 @@ public void perform() throws Exception {
XmlElement versionElem = context.query(Conditions.attribute("version").is(currentVersion)).getOnlyResult();
if (versionElem != null) {
if (!versionElem.getAttribute("launched").getBool()) {
List<XmlElement> lowerLaunchedVersions = context.query(xmlElement -> xmlElement.getTagName().equals("version")
&& versionCompare(currentVersion, xmlElement.getAttribute("version").getValue()) == 1
&& xmlElement.getAttribute("launched").getBool()).collect();
if (!lowerLaunchedVersions.isEmpty()) {
MessageService messageService = new MessageService();
String message = "Botify has been updated to " + currentVersion + ". [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()) {
StringBuilder featuresBuilder = new StringBuilder();
for (XmlElement feature : features) {
featuresBuilder.append("-\t").append(feature.getTextContent()).append(System.lineSeparator());
}
embedBuilder.addField("Features", featuresBuilder.toString(), false);
}

for (Guild guild : jda.getGuilds()) {
messageService.sendWithLogo(embedBuilder, guild);
}
if (!(versionElem.hasAttribute("silent") && versionElem.getAttribute("silent").getBool())) {
sendUpdateAlert(context, currentVersion, versionElem);
}

context.invoke(() -> versionElem.setAttribute("launched", true));
Expand All @@ -71,6 +51,33 @@ && versionCompare(currentVersion, xmlElement.getAttribute("version").getValue())
}
}

private void sendUpdateAlert(Context context, String currentVersion, XmlElement versionElem) throws IOException {
List<XmlElement> lowerLaunchedVersions = context.query(xmlElement -> xmlElement.getTagName().equals("version")
&& versionCompare(currentVersion, xmlElement.getAttribute("version").getValue()) == 1
&& xmlElement.getAttribute("launched").getBool()).collect();
if (!lowerLaunchedVersions.isEmpty()) {
MessageService messageService = new MessageService();
String message = "Botify has been updated to " + currentVersion + ". [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()) {
StringBuilder featuresBuilder = new StringBuilder();
for (XmlElement feature : features) {
featuresBuilder.append("-\t").append(feature.getTextContent()).append(System.lineSeparator());
}
embedBuilder.addField("Features", featuresBuilder.toString(), false);
}

for (Guild guild : jda.getGuilds()) {
messageService.sendWithLogo(embedBuilder, guild);
}
}
}

private int versionCompare(String s1, String s2) {
String[] split1 = s1.split("\\.");
String[] split2 = s2.split("\\.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.dv8tion.jda.core.entities.ISnowflake;
import net.robinfriedli.botify.Botify;
import net.robinfriedli.botify.command.AbstractAdminCommand;
import net.robinfriedli.botify.command.ArgumentContribution;
import net.robinfriedli.botify.command.CommandContext;
import net.robinfriedli.botify.command.CommandManager;
import net.robinfriedli.botify.discord.CommandExecutionQueueManager;
Expand All @@ -38,12 +39,14 @@ public CleanDbCommand(CommandContribution commandContribution, CommandContext co
public void runAdmin() {
Botify.shutdownListeners();
try {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled cleanup");
embedBuilder.setDescription("Botify is suspending for a few seconds to clean the database.");
sendToActiveGuilds(embedBuilder.build());
CommandExecutionQueueManager executionQueueManager = Botify.get().getExecutionQueueManager();
if (!argumentSet("silent")) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled cleanup");
embedBuilder.setDescription("Botify is suspending for a few seconds to clean the database.");
sendToActiveGuilds(embedBuilder.build());
}

CommandExecutionQueueManager executionQueueManager = Botify.get().getExecutionQueueManager();
CommandContext context = getContext();
Thread cleanupThread = new Thread(() -> {
CommandContext.Current.set(context);
Expand Down Expand Up @@ -196,4 +199,13 @@ private int deleteStalePresets(CriteriaBuilder cb, Set<String> activeGuildIds, S
@Override
public void onSuccess() {
}

@Override
public ArgumentContribution setupArguments() {
ArgumentContribution argumentContribution = new ArgumentContribution(this);
argumentContribution.map("silent")
.setDescription("Disables alerting active guilds about the restart.");
return argumentContribution;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dv8tion.jda.core.EmbedBuilder;
import net.robinfriedli.botify.Botify;
import net.robinfriedli.botify.command.AbstractAdminCommand;
import net.robinfriedli.botify.command.ArgumentContribution;
import net.robinfriedli.botify.command.CommandContext;
import net.robinfriedli.botify.command.CommandManager;
import net.robinfriedli.botify.entities.xml.CommandContribution;
Expand Down Expand Up @@ -37,13 +38,15 @@ private void doQuit() {
Botify.shutdownListeners();

try {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled shutdown");
embedBuilder.setDescription("The bot is scheduled to shut down after completing queued actions. No commands will be accepted until then.");
if (!getCommandBody().isBlank()) {
embedBuilder.addField("Reason", getCommandBody(), false);
if (!argumentSet("silent")) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled shutdown");
embedBuilder.setDescription("The bot is scheduled to shut down after completing queued actions. No commands will be accepted until then.");
if (!getCommandBody().isBlank()) {
embedBuilder.addField("Reason", getCommandBody(), false);
}
sendToActiveGuilds(embedBuilder.build());
}
sendToActiveGuilds(embedBuilder.build());

// runs in separate thread to avoid deadlock when waiting for commands to finish
Thread shutdownThread = new Thread(() -> Botify.shutdown(60000));
Expand All @@ -55,4 +58,12 @@ private void doQuit() {
}
}

@Override
public ArgumentContribution setupArguments() {
ArgumentContribution argumentContribution = new ArgumentContribution(this);
argumentContribution.map("silent")
.setDescription("Disables alerting active guilds about the shutdown.");
return argumentContribution;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.dv8tion.jda.core.EmbedBuilder;
import net.robinfriedli.botify.Botify;
import net.robinfriedli.botify.command.AbstractAdminCommand;
import net.robinfriedli.botify.command.ArgumentContribution;
import net.robinfriedli.botify.command.CommandContext;
import net.robinfriedli.botify.command.CommandManager;
import net.robinfriedli.botify.entities.xml.CommandContribution;
Expand Down Expand Up @@ -43,13 +44,15 @@ private void doRestart() {
Botify.shutdownListeners();

try {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled restart");
embedBuilder.setDescription("The bot is scheduled to restart after completing pending actions. No commands will be accepted until then.");
if (!getCommandBody().isBlank()) {
embedBuilder.addField("Reason", getCommandBody(), false);
if (!argumentSet("silent")) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled restart");
embedBuilder.setDescription("The bot is scheduled to restart after completing pending actions. No commands will be accepted until then.");
if (!getCommandBody().isBlank()) {
embedBuilder.addField("Reason", getCommandBody(), false);
}
sendToActiveGuilds(embedBuilder.build());
}
sendToActiveGuilds(embedBuilder.build());

Runtime runtime = Runtime.getRuntime();
runtime.addShutdownHook(new Thread(() -> {
Expand All @@ -74,4 +77,11 @@ private void doRestart() {
}
}

@Override
public ArgumentContribution setupArguments() {
ArgumentContribution argumentContribution = new ArgumentContribution(this);
argumentContribution.map("silent")
.setDescription("Disables alerting active guilds about the restart.");
return argumentContribution;
}
}

0 comments on commit d7cd269

Please sign in to comment.