Added build IDs and moved program name / version information to a .properties file.

This commit is contained in:
Sandy Mossgrave 2023-05-07 23:54:46 +00:00
parent f2eec77df0
commit 713c0f068a
4 changed files with 213 additions and 111 deletions

37
pom.xml
View File

@ -3,10 +3,38 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tinyplantnews.priestess</groupId>
<artifactId>Priestess</artifactId>
<version>0.0</version>
<name>Priestesss of the Bean Goose Cult</name>
<version>0.1</version>
<packaging>jar</packaging>
<scm>
<connection>scm:git:https://tinyplantnews.com/git/Priestess.git</connection>
<developerConnection>scm:git:https://twi@10.0.0.1:/srv/git/Priestess.git</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>buildnumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
@ -28,6 +56,13 @@
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
<resources>
<resource>
<directory>src/main/java/com/tinyplantnews/priestess/version</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>

View File

@ -47,6 +47,11 @@ public class Command {
case FAILURE:
replyTo(m, String.format("Command %s failed for some reason idfk", s));
return;
case NOMATCH:
replyTo(m, String.format("Command %s says it doesn't match command name", s));
break;
default:
break;
}
}
}
@ -112,6 +117,13 @@ public class Command {
return name;
}
/**
* @return a help string
*/
public String getHelp() {
return callback.getHelp(this.name);
}
public static Command commandThatJustRepliesWith(String name, String reply) {
Command c = new Command(name, 1);
c.setCallback(new Callback() {

View File

@ -205,4 +205,30 @@ public class Configuration {
});
return sb.toString();
}
private static Properties getJarProperties() {
Properties props = new Properties();
try {
props.load(Configuration.class.getClassLoader().getResourceAsStream("version/version.properties"));
} catch (IOException e) {
log.log(Level.SEVERE, "Problem encountered while loading basic jar properties: {0}", e);
return null;
}
return props;
}
public static final String PROGNAME;
public static final String VERSION;
static {
Properties props = getJarProperties();
if (props == null) {
PROGNAME = "Priestess, probably";
VERSION = "(version unknown)";
} else {
PROGNAME = props.getProperty("progname");
VERSION = props.getProperty("version");
}
}
}

View File

@ -1,6 +1,4 @@
/*
:q:q
qqqqqqqq:qdf
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
*/
@ -41,6 +39,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import static com.tinyplantnews.priestess.Configuration.PROGNAME;
import static com.tinyplantnews.priestess.Configuration.VERSION;
/**
*
@ -103,6 +103,8 @@ public class Priestess {
private int invocationsThisSession = 0;
private static boolean offlineMode = false;
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
@ -113,7 +115,9 @@ public class Priestess {
if (args[i].startsWith("--")) {
System.out.println("Command-line switch (" + args[i] + ") detected.");
String yarg = args[i].substring(2, args[i].indexOf('='));
int endi = args[i].indexOf('=');
endi = endi > 0 ? endi : args[i].length();
String yarg = args[i].substring(2, endi);
switch (yarg) {
case "config-file":
Configuration.setCONFIG_FILE_LOCATION(yarg, false);
@ -142,6 +146,12 @@ public class Priestess {
allChannelsCultable = true;
log.log(Level.INFO, "Listening to all channels in joined guilds.");
break;
case "version":
log.log(Level.INFO, PROGNAME + " " + VERSION);
break;
case "offline":
offlineMode = true;
break;
default:
log.log(Level.INFO, "Unknown command-line argument: {0}", yarg);
}
@ -256,6 +266,18 @@ public class Priestess {
log.log(Level.SEVERE, "bot token is null. aborting.");
return;
}
SysInListener sil = new SysInListener();
Thread t = new Thread(sil);
t.start();
flywheel.put("System.in listener", t);
if (offlineMode) {
try {
t.join();
} catch (InterruptedException e) {
t.interrupt();
}
} else {
dc = DiscordClientBuilder.create(botToken).build().login().block();
if (dc == null) {
log.log(Level.SEVERE, "gatewaydiscordclient was null. aborting.");
@ -265,7 +287,8 @@ public class Priestess {
Date d = new Date();
SimpleDateFormat df = new SimpleDateFormat("dd MMM YYYY kk:mm");
boot_time = df.format(d);
dc.updatePresence(ClientPresence.of(Status.ONLINE, ClientActivity.playing("since " + boot_time))).subscribe();
dc.updatePresence(ClientPresence.of(Status.ONLINE, ClientActivity.playing("since " + boot_time)))
.subscribe();
dc.getGuilds().flatMap((g) -> {
if (!guildemojimaps.containsKey(g)) {
guildemojimaps.put(g, new GuildProfile(g));
@ -304,18 +327,13 @@ public class Priestess {
return event.reply().withContent("agreed");
}).subscribe();
SysInListener sil = new SysInListener();
Thread t = new Thread(sil);
t.start();
flywheel.put("System.in listener", t);
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
.filter(g -> !g.getGuild().blockOptional().isEmpty()).flatMap(guildedmessagehandler).subscribe();
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
.filter(g -> g.getGuild().blockOptional().isEmpty()).flatMap(directmessagehandler).blockLast();
}
}
private int invocationsBeforeThisSession = 0;
@ -512,7 +530,7 @@ public class Priestess {
}
private Guild resolveGuildByNameOrId(String token) {
log.log(Level.INFO, "Finding guild by name or ID " + token);
log.log(Level.FINE, "Finding guild by name or ID " + token);
if (guildnames.containsKey(token)) {
return guildnames.get(token);
}
@ -541,7 +559,7 @@ public class Priestess {
} catch (InterruptedException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "System.in Listener interrupted.");
}
System.out.println("break repl");
System.out.println("Breaking repl");
}
}
@ -597,8 +615,7 @@ public class Priestess {
@Override
public Publisher<Mono> apply(CommandArgs t) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from
// nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
throw new UnsupportedOperationException("Not supported yet.");
}
public String getHelp(String commandName) {
@ -843,7 +860,19 @@ public class Priestess {
}
};
public final Callback listCommandsCommand = new Callback() {
@Override
public Publisher<Mono> apply(CommandArgs o) {
o.replyWith(PROGNAME + " " + VERSION);
for (String name : Command.commands.keySet()) {
o.replyWith(" Help for command " + name + ": " + Command.commands.get(name).getHelp());
}
return Mono.empty();
}
};
private void registerDefaultCommands() {
Command.registerCommand(new Command("help", 0).setCallback(listCommandsCommand));
Command.registerCommand(new Command("status", 1).setCallback(showCommand));
Command.registerCommand(new Command("reload messages", 1).setCallback(reloadMessageStoreCommand));
Command.registerCommand(new Command("use emoji", 1).setCallback(registerEmojiCommand));