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>
|
||||
<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.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>
|
||||
<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>
|
||||
<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>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<exec.mainClass>com.tinyplantnews.priestess.Priestess</exec.mainClass>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<exec.mainClass>com.tinyplantnews.priestess.Priestess</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
||||
</project>
|
||||
|
@ -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() {
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
@ -124,7 +128,7 @@ public class Priestess {
|
||||
i++;
|
||||
break;
|
||||
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);
|
||||
trySetDebugLevel(newlevel);
|
||||
i++;
|
||||
@ -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,65 +266,73 @@ public class Priestess {
|
||||
log.log(Level.SEVERE, "bot token is null. aborting.");
|
||||
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();
|
||||
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.");
|
||||
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())
|
||||
.filter(g -> !g.getGuild().blockOptional().isEmpty()).flatMap(guildedmessagehandler).subscribe();
|
||||
if (!guildnames.containsKey(g.getName())) {
|
||||
guildnames.put(g.getName(), g);
|
||||
}
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
|
||||
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
|
||||
.filter(g -> g.getGuild().blockOptional().isEmpty()).flatMap(directmessagehandler).blockLast();
|
||||
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();
|
||||
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user