Added an example chat input interaction (/bean).
Streamlined the messagehandler functions Changed the callback help/usage paradigm to use something that may actually work (I don't know whether it does) Rationalized the way that configuration files are located and loaded, guarded against TOCTOU
This commit is contained in:
parent
4bbcbcf290
commit
dc9ac7eddd
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,4 +6,5 @@ dependency-reduced-pom.xml
|
|||||||
buildNumber.properties
|
buildNumber.properties
|
||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
.bin/
|
||||||
.settings/
|
.settings/
|
||||||
|
207
pom.xml
207
pom.xml
@ -1,98 +1,113 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<groupId>com.tinyplantnews.priestess</groupId>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>Priestess</artifactId>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<name>Priestesss of the Bean Goose Cult</name>
|
<groupId>com.tinyplantnews.priestess</groupId>
|
||||||
<version>0.2</version>
|
<artifactId>Priestess</artifactId>
|
||||||
<packaging>jar</packaging>
|
<name>Priestesss of the Bean Goose Cult</name>
|
||||||
<scm>
|
<version>0.2</version>
|
||||||
<connection>scm:git:https://tinyplantnews.com/git/Priestess.git</connection>
|
<packaging>jar</packaging>
|
||||||
<developerConnection>scm:git:https://twi@10.0.0.1:/srv/git/Priestess.git</developerConnection>
|
<scm>
|
||||||
</scm>
|
<connection>scm:git:https://tinyplantnews.com/git/Priestess.git</connection>
|
||||||
<build>
|
<developerConnection>scm:git:https://twi@10.0.0.1:/srv/git/Priestess.git</developerConnection>
|
||||||
<plugins>
|
</scm>
|
||||||
<plugin>
|
<build>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<plugins>
|
||||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
<plugin>
|
||||||
<version>1.4</version>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<executions>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
<execution>
|
<version>3.4.1</version>
|
||||||
<id>buildnumber</id>
|
<goals>
|
||||||
<phase>validate</phase>
|
<goal>java</goal>
|
||||||
<goals>
|
</goals>
|
||||||
<goal>create</goal>
|
<configuration>
|
||||||
</goals>
|
<mainClass>com.tinyplantnews.priestess.Priestess</mainClass>
|
||||||
</execution>
|
</configuration>
|
||||||
</executions>
|
</plugin>
|
||||||
<configuration>
|
<plugin>
|
||||||
<format>{0,number}</format>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<items>
|
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||||
<item>buildNumber</item>
|
<version>1.4</version>
|
||||||
</items>
|
<executions>
|
||||||
<doCheck>false</doCheck>
|
<execution>
|
||||||
<doUpdate>false</doUpdate>
|
<id>buildnumber</id>
|
||||||
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
|
<phase>validate</phase>
|
||||||
</configuration>
|
<goals>
|
||||||
</plugin>
|
<goal>create</goal>
|
||||||
<plugin>
|
</goals>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</execution>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
</executions>
|
||||||
<version>3.4.1</version>
|
<configuration>
|
||||||
<executions>
|
<format>{0,number}</format>
|
||||||
<execution>
|
<items>
|
||||||
<phase>package</phase>
|
<item>buildNumber</item>
|
||||||
<goals>
|
</items>
|
||||||
<goal>shade</goal>
|
<doCheck>false</doCheck>
|
||||||
</goals>
|
<doUpdate>false</doUpdate>
|
||||||
<configuration>
|
<revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
|
||||||
<transformers>
|
</configuration>
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
</plugin>
|
||||||
<mainClass>com.tinyplantnews.priestess.Priestess</mainClass>
|
<plugin>
|
||||||
</transformer>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</transformers>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
</configuration>
|
<version>3.4.1</version>
|
||||||
</execution>
|
<executions>
|
||||||
</executions>
|
<execution>
|
||||||
</plugin>
|
<phase>package</phase>
|
||||||
</plugins>
|
<goals>
|
||||||
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
|
<goal>shade</goal>
|
||||||
<resources>
|
</goals>
|
||||||
<resource>
|
<configuration>
|
||||||
<directory>src/main/java/com/tinyplantnews/priestess/version</directory>
|
<transformers>
|
||||||
<filtering>true</filtering>
|
<transformer
|
||||||
</resource>
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
</resources>
|
<mainClass>
|
||||||
</build>
|
com.tinyplantnews.priestess.Priestess</mainClass>
|
||||||
<dependencies>
|
</transformer>
|
||||||
<dependency>
|
</transformers>
|
||||||
<groupId>com.discord4j</groupId>
|
</configuration>
|
||||||
<artifactId>discord4j-core</artifactId>
|
</execution>
|
||||||
<version>3.2.3</version>
|
</executions>
|
||||||
</dependency>
|
</plugin>
|
||||||
<dependency>
|
</plugins>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<finalName>${project.artifactId}-${project.version}.${buildNumber}</finalName>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<resources>
|
||||||
<version>5.6.0</version>
|
<resource>
|
||||||
<scope>test</scope>
|
<directory>src/main/java/com/tinyplantnews/priestess/version</directory>
|
||||||
</dependency>
|
<filtering>true</filtering>
|
||||||
<dependency>
|
</resource>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
</resources>
|
||||||
<artifactId>junit-jupiter-params</artifactId>
|
</build>
|
||||||
<version>5.6.0</version>
|
<dependencies>
|
||||||
<scope>test</scope>
|
<dependency>
|
||||||
</dependency>
|
<groupId>com.discord4j</groupId>
|
||||||
<dependency>
|
<artifactId>discord4j-core</artifactId>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<version>3.2.3</version>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
</dependency>
|
||||||
<version>5.6.0</version>
|
<dependency>
|
||||||
<scope>test</scope>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
</dependency>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
</dependencies>
|
<version>5.6.0</version>
|
||||||
<properties>
|
<scope>test</scope>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
</dependency>
|
||||||
<maven.compiler.source>18</maven.compiler.source>
|
<dependency>
|
||||||
<maven.compiler.target>18</maven.compiler.target>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<exec.mainClass>com.tinyplantnews.priestess.Priestess</exec.mainClass>
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
</properties>
|
<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>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -37,7 +37,7 @@ public class Command {
|
|||||||
static void tryAll(String commandline, Message m, int permissionLevel) {
|
static void tryAll(String commandline, Message m, int permissionLevel) {
|
||||||
for (String s : commands.keySet()) {
|
for (String s : commands.keySet()) {
|
||||||
if (commandline.startsWith(s)) {
|
if (commandline.startsWith(s)) {
|
||||||
log.log(Level.INFO, "Matched command " + s);
|
log.log(Level.FINE, "Matched command " + s);
|
||||||
switch (commands.get(s).tryExecuteCommand(commandline, permissionLevel, m)) {
|
switch (commands.get(s).tryExecuteCommand(commandline, permissionLevel, m)) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
return;
|
return;
|
||||||
@ -123,7 +123,7 @@ public class Command {
|
|||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return callback.getHelp(this.name);
|
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() {
|
||||||
|
@ -51,27 +51,14 @@ public class Configuration {
|
|||||||
if (getCONFIG_FILE_LOCATION() != null) {
|
if (getCONFIG_FILE_LOCATION() != null) {
|
||||||
return getCONFIG_FILE_LOCATION();
|
return getCONFIG_FILE_LOCATION();
|
||||||
}
|
}
|
||||||
setCONFIG_FILE_LOCATION(setConfigurationFilePath(), false);
|
setCONFIG_FILE_LOCATION(findOrCreateConfigurationFile(), false);
|
||||||
return getCONFIG_FILE_LOCATION();
|
return getCONFIG_FILE_LOCATION();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String setConfigurationFilePath() {
|
private static String findOrCreateConfigurationFile() {
|
||||||
String s = System.getenv(CONFIG_FILE_KEY);
|
/*
|
||||||
if (s != null && !s.isBlank()) {
|
* Try the environment variable
|
||||||
return s;
|
*/
|
||||||
} else if (props.containsKey(CONFIG_FILE_KEY)) {
|
|
||||||
return props.getProperty(CONFIG_FILE_KEY);
|
|
||||||
}
|
|
||||||
s = prefs.get(CONFIG_FILE_KEY, "");
|
|
||||||
if (s != null && !s.isBlank()) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
if (Files.exists(Paths.get(DEFAULT_CONFIG_FILE_NAME), LinkOption.NOFOLLOW_LINKS)) {
|
|
||||||
return DEFAULT_CONFIG_FILE_NAME;
|
|
||||||
}
|
|
||||||
// JDialog jd = new JDialog();
|
|
||||||
// jd.add(new JLabel("Choose where to put Priestess Working Directory"));
|
|
||||||
// jd.setVisible(true);
|
|
||||||
JOptionPane.showConfirmDialog(null, "Select where cult files will be stored.");
|
JOptionPane.showConfirmDialog(null, "Select where cult files will be stored.");
|
||||||
JFileChooser jfc = new JFileChooser("Config File for Discord Cult Priestess");
|
JFileChooser jfc = new JFileChooser("Config File for Discord Cult Priestess");
|
||||||
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
@ -82,6 +69,12 @@ public class Configuration {
|
|||||||
if (rv == JFileChooser.APPROVE_OPTION) {
|
if (rv == JFileChooser.APPROVE_OPTION) {
|
||||||
File f = jfc.getSelectedFile();
|
File f = jfc.getSelectedFile();
|
||||||
if (f.isDirectory() && f.canRead() && f.canWrite()) {
|
if (f.isDirectory() && f.canRead() && f.canWrite()) {
|
||||||
|
prefs.put(CONFIG_FILE_KEY, f.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
prefs.flush();
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
log.log(Level.WARNING, "Failed to flush preferences to backing store");
|
||||||
|
}
|
||||||
return f.getAbsolutePath();
|
return f.getAbsolutePath();
|
||||||
}
|
}
|
||||||
} else if (rv == JFileChooser.CANCEL_OPTION) {
|
} else if (rv == JFileChooser.CANCEL_OPTION) {
|
||||||
@ -92,18 +85,66 @@ public class Configuration {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String FILE_MARKER = "(file)";
|
||||||
|
|
||||||
|
public static String resolveIndirectConfigurationValue(String v) {
|
||||||
|
log.log(Level.INFO, "Index of <" + FILE_MARKER + "> in <" + v + "> is " + v.indexOf(FILE_MARKER));
|
||||||
|
if (v.indexOf(FILE_MARKER) == 0) {
|
||||||
|
String relpath = v.substring(FILE_MARKER.length()).trim();
|
||||||
|
|
||||||
|
File configFile = Paths.get(CONFIG_FILE_LOCATION).toFile();
|
||||||
|
String configDir;
|
||||||
|
if (configFile.isDirectory()) {
|
||||||
|
configDir = configFile.getPath();
|
||||||
|
} else {
|
||||||
|
configDir = configFile.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
Path indirectValuePath = Paths.get(configDir, relpath);
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(indirectValuePath.toFile()));) {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
br.lines().forEach((s) -> {
|
||||||
|
sb.append(s);
|
||||||
|
});
|
||||||
|
v = sb.toString();
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
|
||||||
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE,
|
||||||
|
"Error loading indirect configuration value from (" + indirectValuePath.toString() + ") {0}",
|
||||||
|
ex);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE,
|
||||||
|
"Error loading indirect configuration value from (" + indirectValuePath.toString() + ") {0}",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
private static final String delimiter = ": ";
|
private static final String delimiter = ": ";
|
||||||
|
|
||||||
public static void getConfigurationFromFile() {
|
private static File resolveDirectoryToConfigFile(File f) {
|
||||||
if (CONFIG_FILE_LOCATION == null) {
|
|
||||||
setConfigurationFilePath();
|
if (f.isDirectory()) {
|
||||||
|
f = Paths.get(f.getPath(), Configuration.DEFAULT_CONFIG_FILE_NAME).toFile();
|
||||||
}
|
}
|
||||||
try {
|
return f;
|
||||||
if (Files.isDirectory(Paths.get(CONFIG_FILE_LOCATION), LinkOption.NOFOLLOW_LINKS)) {
|
}
|
||||||
CONFIG_FILE_LOCATION = CONFIG_FILE_LOCATION + System.getProperty("file.separator")
|
|
||||||
+ DEFAULT_CONFIG_FILE_NAME;
|
/**
|
||||||
}
|
*
|
||||||
BufferedReader br = new BufferedReader(new FileReader(Paths.get(CONFIG_FILE_LOCATION).toFile()));
|
*/
|
||||||
|
public static boolean readConfigurationFromFile(String path) throws IOException {
|
||||||
|
if (path == null || path.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
File f = Paths.get(path).toFile();
|
||||||
|
if (CONFIG_FILE_LOCATION == null) {
|
||||||
|
findOrCreateConfigurationFile();
|
||||||
|
}
|
||||||
|
f = resolveDirectoryToConfigFile(f);
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
|
||||||
|
|
||||||
br.lines().forEach((s) -> {
|
br.lines().forEach((s) -> {
|
||||||
String key = s.substring(0, s.indexOf(delimiter));
|
String key = s.substring(0, s.indexOf(delimiter));
|
||||||
if (s.length() == s.indexOf(delimiter) + delimiter.length()) {
|
if (s.length() == s.indexOf(delimiter) + delimiter.length()) {
|
||||||
@ -111,16 +152,35 @@ public class Configuration {
|
|||||||
configuration.put(key, "");
|
configuration.put(key, "");
|
||||||
} else {
|
} else {
|
||||||
String value = s.substring(s.indexOf(delimiter) + delimiter.length());
|
String value = s.substring(s.indexOf(delimiter) + delimiter.length());
|
||||||
|
value = resolveIndirectConfigurationValue(value);
|
||||||
configuration.put(key, value);
|
configuration.put(key, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (FileNotFoundException ex) {
|
CONFIG_FILE_LOCATION = f.toString();
|
||||||
|
return true;
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE,
|
} catch (FileNotFoundException fnfe) {
|
||||||
"Error loading configuration file from (" + CONFIG_FILE_LOCATION + ") {0}", ex);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void findAndReadConfigurationFile() {
|
||||||
|
try {
|
||||||
|
if (readConfigurationFromFile(System.getenv(CONFIG_FILE_KEY))) {
|
||||||
|
return;
|
||||||
|
} else if (readConfigurationFromFile(props.getProperty(CONFIG_FILE_KEY, ""))) {
|
||||||
|
return;
|
||||||
|
} else if (readConfigurationFromFile(prefs.get(CONFIG_FILE_KEY, ""))) {
|
||||||
|
return;
|
||||||
|
} else if (readConfigurationFromFile(findOrCreateConfigurationFile())) {
|
||||||
|
} else {
|
||||||
|
log.log(Level.WARNING, "Could not resolve a configuration file path, using defaults.");
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
log.log(Level.SEVERE, "Could not read configuration file {0}", ioe.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the CONFIG_FILE_LOCATION
|
* @return the CONFIG_FILE_LOCATION
|
||||||
*/
|
*/
|
||||||
@ -180,7 +240,9 @@ public class Configuration {
|
|||||||
"Making backup configuration file failed. Exiting without committing configuration to file");
|
"Making backup configuration file failed. Exiting without committing configuration to file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (BufferedWriter br = new BufferedWriter(new FileWriter(Paths.get(CONFIG_FILE_LOCATION).toFile(), false))) {
|
File f = Paths.get(CONFIG_FILE_LOCATION).toFile();
|
||||||
|
f = resolveDirectoryToConfigFile(f);
|
||||||
|
try (BufferedWriter br = new BufferedWriter(new FileWriter(f, false))) {
|
||||||
configuration.forEach((key, value) -> {
|
configuration.forEach((key, value) -> {
|
||||||
try {
|
try {
|
||||||
br.append(key + delimiter + value + "\n");
|
br.append(key + delimiter + value + "\n");
|
||||||
|
@ -22,6 +22,8 @@ import discord4j.core.object.presence.ClientPresence;
|
|||||||
import discord4j.core.object.presence.Status;
|
import discord4j.core.object.presence.Status;
|
||||||
import discord4j.core.object.reaction.ReactionEmoji;
|
import discord4j.core.object.reaction.ReactionEmoji;
|
||||||
import discord4j.core.spec.MessageCreateSpec;
|
import discord4j.core.spec.MessageCreateSpec;
|
||||||
|
import discord4j.discordjson.json.ApplicationCommandRequest;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -248,6 +250,14 @@ public class Priestess {
|
|||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Function<MessageCreateEvent, Publisher<Mono>> messagehandler = (MessageCreateEvent t) -> {
|
||||||
|
if (t.getGuild().blockOptional().isEmpty()) {
|
||||||
|
return directmessagehandler.apply(t);
|
||||||
|
} else {
|
||||||
|
return guildedmessagehandler.apply(t);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
private static final String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
private String randomLetter() {
|
private String randomLetter() {
|
||||||
@ -266,6 +276,8 @@ public class Priestess {
|
|||||||
if (botToken.isBlank()) {
|
if (botToken.isBlank()) {
|
||||||
log.log(Level.SEVERE, "bot token is null. aborting.");
|
log.log(Level.SEVERE, "bot token is null. aborting.");
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
log.log(Level.FINE, "bot token set.");
|
||||||
}
|
}
|
||||||
SysInListener sil = new SysInListener();
|
SysInListener sil = new SysInListener();
|
||||||
Thread t = new Thread(sil);
|
Thread t = new Thread(sil);
|
||||||
@ -327,12 +339,23 @@ public class Priestess {
|
|||||||
dc.on(ChatInputInteractionEvent.class).flatMap(event -> {
|
dc.on(ChatInputInteractionEvent.class).flatMap(event -> {
|
||||||
return event.reply().withContent("agreed");
|
return event.reply().withContent("agreed");
|
||||||
}).subscribe();
|
}).subscribe();
|
||||||
|
long applicationId = dc.getRestClient().getApplicationId().block();
|
||||||
|
|
||||||
|
ApplicationCommandRequest acr = ApplicationCommandRequest.builder().name("bean").description("beans")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
dc.getGuilds().flatMap((g) -> {
|
||||||
|
log.log(Level.INFO, "Registering command with server {0}", g.getName());
|
||||||
|
dc.getRestClient().getApplicationService()
|
||||||
|
.createGuildApplicationCommand(applicationId, g.getId().asLong(), acr).block();
|
||||||
|
return Mono.empty();
|
||||||
|
}).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())
|
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
|
||||||
.filter(g -> !g.getGuild().blockOptional().isEmpty()).flatMap(guildedmessagehandler).subscribe();
|
/*.filter(g -> g.getGuild().blockOptional().isEmpty())*/.flatMap(messagehandler).blockLast();
|
||||||
|
|
||||||
dc.on(MessageCreateEvent.class).filter(event -> !event.getMessage().getAuthor().get().isBot())
|
|
||||||
.filter(g -> g.getGuild().blockOptional().isEmpty()).flatMap(directmessagehandler).blockLast();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,7 +363,7 @@ public class Priestess {
|
|||||||
|
|
||||||
private void setup() {
|
private void setup() {
|
||||||
Configuration.findConfigurationFilePath();
|
Configuration.findConfigurationFilePath();
|
||||||
Configuration.getConfigurationFromFile();
|
Configuration.findAndReadConfigurationFile();
|
||||||
|
|
||||||
botToken = Configuration.getConfigurationParameter(TOKEN_KEY);
|
botToken = Configuration.getConfigurationParameter(TOKEN_KEY);
|
||||||
|
|
||||||
@ -380,7 +403,9 @@ public class Priestess {
|
|||||||
|
|
||||||
private void shutdown() {
|
private void shutdown() {
|
||||||
replcontinue = false;
|
replcontinue = false;
|
||||||
dc.logout().subscribe();
|
if (dc != null) {
|
||||||
|
dc.logout().subscribe();
|
||||||
|
}
|
||||||
System.out.println("Logged out");
|
System.out.println("Logged out");
|
||||||
try {
|
try {
|
||||||
user_reader.close();
|
user_reader.close();
|
||||||
@ -392,10 +417,10 @@ public class Priestess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int invocationsTotal = invocationsBeforeThisSession + invocationsThisSession;
|
int invocationsTotal = invocationsBeforeThisSession + invocationsThisSession;
|
||||||
System.out.println("Bean Goose has been invoked " + invocationsTotal + " times so far.");
|
log.log(Level.INFO, "Bean Goose has been invoked " + invocationsTotal + " times so far.");
|
||||||
Configuration.setConfigurationParameter(INVOCATIONS_KEY, Integer.toString(invocationsTotal));
|
Configuration.setConfigurationParameter(INVOCATIONS_KEY, Integer.toString(invocationsTotal));
|
||||||
Configuration.commitConfigurationToFile();
|
Configuration.commitConfigurationToFile();
|
||||||
System.out.println("Configuration committed to file.");
|
log.log(Level.INFO, "Configuration committed to file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeDeity(Guild g, Message m) {
|
private void invokeDeity(Guild g, Message m) {
|
||||||
@ -420,7 +445,7 @@ public class Priestess {
|
|||||||
|
|
||||||
private int resolveAuthorPermissionLevel(MessageCreateEvent t, Message m) {
|
private int resolveAuthorPermissionLevel(MessageCreateEvent t, Message m) {
|
||||||
int level = 0;
|
int level = 0;
|
||||||
Optional gio = t.getGuildId();
|
Optional<Snowflake> gio = t.getGuildId();
|
||||||
if (gio.isPresent()) {
|
if (gio.isPresent()) {
|
||||||
Member a = m.getAuthorAsMember().block();
|
Member a = m.getAuthorAsMember().block();
|
||||||
for (Snowflake snowflake : (Snowflake[]) a.getRoleIds().toArray(new Snowflake[3])) {
|
for (Snowflake snowflake : (Snowflake[]) a.getRoleIds().toArray(new Snowflake[3])) {
|
||||||
@ -454,7 +479,7 @@ public class Priestess {
|
|||||||
if (ao.isPresent()) {
|
if (ao.isPresent()) {
|
||||||
for (String s1 : s.split(" ")) {
|
for (String s1 : s.split(" ")) {
|
||||||
if (s1.equals(ao.get().getId().asString())) {
|
if (s1.equals(ao.get().getId().asString())) {
|
||||||
System.out.println("Literally catluck detected.");
|
log.log(Level.FINE, "Literally catluck detected.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -614,17 +639,31 @@ public class Priestess {
|
|||||||
String[] usages = { "Undefined command usage" };
|
String[] usages = { "Undefined command usage" };
|
||||||
String help = "${usage}";
|
String help = "${usage}";
|
||||||
|
|
||||||
|
public Callback() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Callback(String[] usages1, String help1) {
|
||||||
|
super();
|
||||||
|
if (usages1 != null) {
|
||||||
|
usages = usages1;
|
||||||
|
}
|
||||||
|
if (help1 != null) {
|
||||||
|
help = help1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs t) {
|
public Publisher<Mono> apply(CommandArgs t) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHelp(String commandName) {
|
public String getHelp(String commandName) {
|
||||||
String s = getUsage(commandName);
|
String s = getUsage(commandName, usages);
|
||||||
return help/* .replaceAll("\\$\\{usage\\}", s) */.replaceAll("\\$\\{commandname\\}", commandName);
|
return help.replaceAll("\\$\\{usage\\}", s).replaceAll("\\$\\{commandname\\}", commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsage(String commandName) {
|
public String getUsage(String commandName, String[] usages) {
|
||||||
StringBuilder u = new StringBuilder();
|
StringBuilder u = new StringBuilder();
|
||||||
for (int i = 0; i < usages.length; i++) {
|
for (int i = 0; i < usages.length; i++) {
|
||||||
String s = usages[i];
|
String s = usages[i];
|
||||||
@ -639,10 +678,8 @@ public class Priestess {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Callback registerEmojiCommand = new Callback() {
|
public final Callback registerEmojiCommand = new Callback(new String[] { "${commandname} EMOJI" },
|
||||||
|
"register emoji for use in basic invocations.") {
|
||||||
String usage = "{commandname} EMOJI";
|
|
||||||
String help = "register emoji for use in basic invocations." + "" + "" + "" + "";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs o) {
|
public Publisher<Mono> apply(CommandArgs o) {
|
||||||
@ -675,7 +712,8 @@ public class Priestess {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public final Callback commitConfigurationCommand = new Callback() {
|
public final Callback commitConfigurationCommand = new Callback(new String[] { "${commandname}" },
|
||||||
|
"commit configuration to the configuration file.") {
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs o) {
|
public Publisher<Mono> apply(CommandArgs o) {
|
||||||
System.out.println("Committing configuration to file.");
|
System.out.println("Committing configuration to file.");
|
||||||
|
Loading…
Reference in New Issue
Block a user