Added build IDs and moved program name / version information to a .properties file.
This commit is contained in:
parent
f2eec77df0
commit
713c0f068a
137
pom.xml
137
pom.xml
@ -3,61 +3,96 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.tinyplantnews.priestess</groupId>
|
<groupId>com.tinyplantnews.priestess</groupId>
|
||||||
<artifactId>Priestess</artifactId>
|
<artifactId>Priestess</artifactId>
|
||||||
<version>0.0</version>
|
<name>Priestesss of the Bean Goose Cult</name>
|
||||||
|
<version>0.1</version>
|
||||||
<packaging>jar</packaging>
|
<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>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>1.4</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<id>buildnumber</id>
|
||||||
<goals>
|
<phase>validate</phase>
|
||||||
<goal>shade</goal>
|
<goals>
|
||||||
</goals>
|
<goal>create</goal>
|
||||||
<configuration>
|
</goals>
|
||||||
<transformers>
|
</execution>
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
</executions>
|
||||||
<mainClass>com.tinyplantnews.priestess.Priestess</mainClass>
|
<configuration>
|
||||||
</transformer>
|
<format>{0,number}</format>
|
||||||
</transformers>
|
<items>
|
||||||
</configuration>
|
<item>buildNumber</item>
|
||||||
</execution>
|
</items>
|
||||||
</executions>
|
<doCheck>false</doCheck>
|
||||||
</plugin>
|
<doUpdate>false</doUpdate>
|
||||||
</plugins>
|
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.tinyplantnews.priestess.Priestess</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</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>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.discord4j</groupId>
|
<groupId>com.discord4j</groupId>
|
||||||
<artifactId>discord4j-core</artifactId>
|
<artifactId>discord4j-core</artifactId>
|
||||||
<version>3.2.3</version>
|
<version>3.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>5.6.0</version>
|
<version>5.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-params</artifactId>
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
<version>5.6.0</version>
|
<version>5.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.6.0</version>
|
<version>5.6.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>18</maven.compiler.source>
|
<maven.compiler.source>18</maven.compiler.source>
|
||||||
<maven.compiler.target>18</maven.compiler.target>
|
<maven.compiler.target>18</maven.compiler.target>
|
||||||
<exec.mainClass>com.tinyplantnews.priestess.Priestess</exec.mainClass>
|
<exec.mainClass>com.tinyplantnews.priestess.Priestess</exec.mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -47,6 +47,11 @@ public class Command {
|
|||||||
case FAILURE:
|
case FAILURE:
|
||||||
replyTo(m, String.format("Command %s failed for some reason idfk", s));
|
replyTo(m, String.format("Command %s failed for some reason idfk", s));
|
||||||
return;
|
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 name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a help string
|
||||||
|
*/
|
||||||
|
public String getHelp() {
|
||||||
|
return callback.getHelp(this.name);
|
||||||
|
}
|
||||||
|
|
||||||
public static Command commandThatJustRepliesWith(String name, String reply) {
|
public static Command commandThatJustRepliesWith(String name, String reply) {
|
||||||
Command c = new Command(name, 1);
|
Command c = new Command(name, 1);
|
||||||
c.setCallback(new Callback() {
|
c.setCallback(new Callback() {
|
||||||
|
@ -205,4 +205,30 @@ public class Configuration {
|
|||||||
});
|
});
|
||||||
return sb.toString();
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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/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
|
* 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 java.util.logging.Logger;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import reactor.core.publisher.Mono;
|
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 int invocationsThisSession = 0;
|
||||||
|
|
||||||
|
private static boolean offlineMode = false;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
@ -113,7 +115,9 @@ public class Priestess {
|
|||||||
|
|
||||||
if (args[i].startsWith("--")) {
|
if (args[i].startsWith("--")) {
|
||||||
System.out.println("Command-line switch (" + args[i] + ") detected.");
|
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) {
|
switch (yarg) {
|
||||||
case "config-file":
|
case "config-file":
|
||||||
Configuration.setCONFIG_FILE_LOCATION(yarg, false);
|
Configuration.setCONFIG_FILE_LOCATION(yarg, false);
|
||||||
@ -124,7 +128,7 @@ public class Priestess {
|
|||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
case "debug-level":
|
case "debug-level":
|
||||||
String newlevel = args[i].substring(args[i].indexOf('=')+1);
|
String newlevel = args[i].substring(args[i].indexOf('=') + 1);
|
||||||
Configuration.setConfigurationParameter(DEBUG_LEVEL, newlevel);
|
Configuration.setConfigurationParameter(DEBUG_LEVEL, newlevel);
|
||||||
trySetDebugLevel(newlevel);
|
trySetDebugLevel(newlevel);
|
||||||
i++;
|
i++;
|
||||||
@ -142,6 +146,12 @@ public class Priestess {
|
|||||||
allChannelsCultable = true;
|
allChannelsCultable = true;
|
||||||
log.log(Level.INFO, "Listening to all channels in joined guilds.");
|
log.log(Level.INFO, "Listening to all channels in joined guilds.");
|
||||||
break;
|
break;
|
||||||
|
case "version":
|
||||||
|
log.log(Level.INFO, PROGNAME + " " + VERSION);
|
||||||
|
break;
|
||||||
|
case "offline":
|
||||||
|
offlineMode = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log.log(Level.INFO, "Unknown command-line argument: {0}", yarg);
|
log.log(Level.INFO, "Unknown command-line argument: {0}", yarg);
|
||||||
}
|
}
|
||||||
@ -256,65 +266,73 @@ public class Priestess {
|
|||||||
log.log(Level.SEVERE, "bot token is null. aborting.");
|
log.log(Level.SEVERE, "bot token is null. aborting.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dc = DiscordClientBuilder.create(botToken).build().login().block();
|
|
||||||
if (dc == null) {
|
|
||||||
log.log(Level.SEVERE, "gatewaydiscordclient was null. aborting.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String boot_time = "";
|
|
||||||
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.getGuilds().flatMap((g) -> {
|
|
||||||
if (!guildemojimaps.containsKey(g)) {
|
|
||||||
guildemojimaps.put(g, new GuildProfile(g));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!guildnames.containsKey(g.getName())) {
|
|
||||||
guildnames.put(g.getName(), g);
|
|
||||||
}
|
|
||||||
return Mono.empty();
|
|
||||||
}).subscribe();
|
|
||||||
|
|
||||||
dc.getGuilds().flatMap((g) -> g.getChannels().flatMap((channel) -> {
|
|
||||||
|
|
||||||
log.log(Level.INFO, "Checking cultability of channel {0}", channel.getName());
|
|
||||||
if (channel.getName().equals(cultChannelName)) {
|
|
||||||
log.log(Level.INFO, "Channel " + channel.getName() + " in " + g.getName() + " is cultable");
|
|
||||||
cultableChannelIDs.add(channel.getId());
|
|
||||||
}
|
|
||||||
return Mono.empty();
|
|
||||||
})).subscribe();
|
|
||||||
|
|
||||||
dc.getGuilds().flatMap(g -> g.getEmojis()).flatMap(g2 -> {
|
|
||||||
// system.out.println("emoji");
|
|
||||||
registerEmoji(g2.getGuild().block(), g2.getId(), g2.getName());
|
|
||||||
return Mono.empty();
|
|
||||||
}).subscribe();
|
|
||||||
|
|
||||||
dc.on(ConnectEvent.class, event -> {
|
|
||||||
|
|
||||||
log.log(Level.INFO, "connected");
|
|
||||||
|
|
||||||
return Mono.empty();
|
|
||||||
}).subscribe();
|
|
||||||
|
|
||||||
dc.on(ChatInputInteractionEvent.class).flatMap(event -> {
|
|
||||||
return event.reply().withContent("agreed");
|
|
||||||
}).subscribe();
|
|
||||||
|
|
||||||
SysInListener sil = new SysInListener();
|
SysInListener sil = new SysInListener();
|
||||||
Thread t = new Thread(sil);
|
Thread t = new Thread(sil);
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
flywheel.put("System.in listener", t);
|
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.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String boot_time = "";
|
||||||
|
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.getGuilds().flatMap((g) -> {
|
||||||
|
if (!guildemojimaps.containsKey(g)) {
|
||||||
|
guildemojimaps.put(g, new GuildProfile(g));
|
||||||
|
}
|
||||||
|
|
||||||
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
|
if (!guildnames.containsKey(g.getName())) {
|
||||||
.filter(g -> !g.getGuild().blockOptional().isEmpty()).flatMap(guildedmessagehandler).subscribe();
|
guildnames.put(g.getName(), g);
|
||||||
|
}
|
||||||
|
return Mono.empty();
|
||||||
|
}).subscribe();
|
||||||
|
|
||||||
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
|
dc.getGuilds().flatMap((g) -> g.getChannels().flatMap((channel) -> {
|
||||||
.filter(g -> g.getGuild().blockOptional().isEmpty()).flatMap(directmessagehandler).blockLast();
|
|
||||||
|
log.log(Level.INFO, "Checking cultability of channel {0}", channel.getName());
|
||||||
|
if (channel.getName().equals(cultChannelName)) {
|
||||||
|
log.log(Level.INFO, "Channel " + channel.getName() + " in " + g.getName() + " is cultable");
|
||||||
|
cultableChannelIDs.add(channel.getId());
|
||||||
|
}
|
||||||
|
return Mono.empty();
|
||||||
|
})).subscribe();
|
||||||
|
|
||||||
|
dc.getGuilds().flatMap(g -> g.getEmojis()).flatMap(g2 -> {
|
||||||
|
// system.out.println("emoji");
|
||||||
|
registerEmoji(g2.getGuild().block(), g2.getId(), g2.getName());
|
||||||
|
return Mono.empty();
|
||||||
|
}).subscribe();
|
||||||
|
|
||||||
|
dc.on(ConnectEvent.class, event -> {
|
||||||
|
|
||||||
|
log.log(Level.INFO, "connected");
|
||||||
|
|
||||||
|
return Mono.empty();
|
||||||
|
}).subscribe();
|
||||||
|
|
||||||
|
dc.on(ChatInputInteractionEvent.class).flatMap(event -> {
|
||||||
|
return event.reply().withContent("agreed");
|
||||||
|
}).subscribe();
|
||||||
|
|
||||||
|
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;
|
private int invocationsBeforeThisSession = 0;
|
||||||
@ -512,7 +530,7 @@ public class Priestess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Guild resolveGuildByNameOrId(String token) {
|
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)) {
|
if (guildnames.containsKey(token)) {
|
||||||
return guildnames.get(token);
|
return guildnames.get(token);
|
||||||
}
|
}
|
||||||
@ -541,7 +559,7 @@ public class Priestess {
|
|||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "System.in Listener interrupted.");
|
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
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs t) {
|
public Publisher<Mono> apply(CommandArgs t) {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
// nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHelp(String commandName) {
|
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() {
|
private void registerDefaultCommands() {
|
||||||
|
Command.registerCommand(new Command("help", 0).setCallback(listCommandsCommand));
|
||||||
Command.registerCommand(new Command("status", 1).setCallback(showCommand));
|
Command.registerCommand(new Command("status", 1).setCallback(showCommand));
|
||||||
Command.registerCommand(new Command("reload messages", 1).setCallback(reloadMessageStoreCommand));
|
Command.registerCommand(new Command("reload messages", 1).setCallback(reloadMessageStoreCommand));
|
||||||
Command.registerCommand(new Command("use emoji", 1).setCallback(registerEmojiCommand));
|
Command.registerCommand(new Command("use emoji", 1).setCallback(registerEmojiCommand));
|
||||||
|
Loading…
Reference in New Issue
Block a user