General fixes. Works.
Formatted source files. Fixed command-line arguments processing. Added ability to specify logging levels by name (ALL, FINE, FINER...) Generally fixed unnoticed problems in Configuration and Priestess classes. Stopped spuriously committing configuration file path to preferences store, changed some Priestess methods to use her own tokenizer, and fixed a null check in setCultableChannels method.
This commit is contained in:
parent
7d97078e43
commit
f2eec77df0
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/priestessconfig.txt
|
/priestessconfig.txt
|
||||||
/priestessconfig.txtbkup
|
/priestessconfig.txtbkup
|
||||||
/target/
|
/target/
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
@ -26,8 +26,8 @@ public class Command {
|
|||||||
|
|
||||||
private static final Logger log = Logger.getLogger(Priestess.class.getName());
|
private static final Logger log = Logger.getLogger(Priestess.class.getName());
|
||||||
|
|
||||||
public static void replyTo(Message m, String s){
|
public static void replyTo(Message m, String s) {
|
||||||
if(m != null){
|
if (m != null) {
|
||||||
m.getChannel().block().createMessage(s).withMessageReference(m.getId()).block();
|
m.getChannel().block().createMessage(s).withMessageReference(m.getId()).block();
|
||||||
} else {
|
} else {
|
||||||
log.log(Level.INFO, s);
|
log.log(Level.INFO, s);
|
||||||
@ -35,10 +35,10 @@ 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.INFO, "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;
|
||||||
case BADPERM:
|
case BADPERM:
|
||||||
@ -65,11 +65,11 @@ public class Command {
|
|||||||
* @param a
|
* @param a
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public CommandStatus tryExecuteCommand(String commandline, int permissionLevel, Message m){
|
public CommandStatus tryExecuteCommand(String commandline, int permissionLevel, Message m) {
|
||||||
if(!commandline.startsWith(this.name)){
|
if (!commandline.startsWith(this.name)) {
|
||||||
return NOMATCH;
|
return NOMATCH;
|
||||||
}
|
}
|
||||||
if(permissionLevel < this.permissionLevel){
|
if (permissionLevel < this.permissionLevel) {
|
||||||
return BADPERM;
|
return BADPERM;
|
||||||
}
|
}
|
||||||
String payload = commandline.substring(this.namelen).trim();
|
String payload = commandline.substring(this.namelen).trim();
|
||||||
@ -77,16 +77,16 @@ public class Command {
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command setCallback(Callback c){
|
public Command setCallback(Callback c) {
|
||||||
this.callback = c;
|
this.callback = c;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command(String name, int permissionLevel){
|
Command(String name, int permissionLevel) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.namelen = name.length();
|
this.namelen = name.length();
|
||||||
this.permissionLevel = permissionLevel;
|
this.permissionLevel = permissionLevel;
|
||||||
this.callback = new Callback(){
|
this.callback = new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs t) {
|
public Publisher<Mono> apply(CommandArgs t) {
|
||||||
t.replyWith(String.format("Callback for function %s not registered", name));
|
t.replyWith(String.format("Callback for function %s not registered", name));
|
||||||
@ -96,13 +96,14 @@ public class Command {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerCommand(Command c){
|
public static void registerCommand(Command c) {
|
||||||
commands.put(c.name, c);
|
commands.put(c.name, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*= "use emoji";
|
/*
|
||||||
public static final String REPLYTO_COMMAND = "reply to";
|
* = "use emoji"; public static final String REPLYTO_COMMAND = "reply to";
|
||||||
public static final String SENDTO_COMMAND = "send to";*/
|
* public static final String SENDTO_COMMAND = "send to";
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name
|
* @return the name
|
||||||
@ -111,9 +112,9 @@ public class Command {
|
|||||||
return name;
|
return 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() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs t) {
|
public Publisher<Mono> apply(CommandArgs t) {
|
||||||
|
@ -37,7 +37,7 @@ public class CommandArgs {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replyWith(String s){
|
public void replyWith(String s) {
|
||||||
Command.replyTo(m, s);
|
Command.replyTo(m, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,5 @@ package com.tinyplantnews.priestess;
|
|||||||
* @author atomb
|
* @author atomb
|
||||||
*/
|
*/
|
||||||
public enum CommandStatus {
|
public enum CommandStatus {
|
||||||
NOMATCH,
|
NOMATCH, SUCCESS, FAILURE, BADPERM;
|
||||||
SUCCESS,
|
|
||||||
FAILURE,
|
|
||||||
BADPERM;
|
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,10 @@ import java.util.prefs.BackingStoreException;
|
|||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* "Ms Merry," you may say, "You literally import the Preferences class, and yet
|
||||||
|
* you insist on writing your own configuration store. Why?" "Iunno," I reply.
|
||||||
*
|
*
|
||||||
* @author twi
|
* @author sandy
|
||||||
*/
|
*/
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
@ -67,9 +69,9 @@ public class Configuration {
|
|||||||
if (Files.exists(Paths.get(DEFAULT_CONFIG_FILE_NAME), LinkOption.NOFOLLOW_LINKS)) {
|
if (Files.exists(Paths.get(DEFAULT_CONFIG_FILE_NAME), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
return DEFAULT_CONFIG_FILE_NAME;
|
return DEFAULT_CONFIG_FILE_NAME;
|
||||||
}
|
}
|
||||||
//JDialog jd = new JDialog();
|
// JDialog jd = new JDialog();
|
||||||
//jd.add(new JLabel("Choose where to put Priestess Working Directory"));
|
// jd.add(new JLabel("Choose where to put Priestess Working Directory"));
|
||||||
//jd.setVisible(true);
|
// 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);
|
||||||
@ -80,15 +82,9 @@ 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, "Backing store exception while committing configuration file path to persistent storage {0}", e.getMessage());
|
|
||||||
}
|
|
||||||
return f.getAbsolutePath();
|
return f.getAbsolutePath();
|
||||||
}
|
}
|
||||||
} else if(rv == JFileChooser.CANCEL_OPTION) {
|
} else if (rv == JFileChooser.CANCEL_OPTION) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +100,14 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (Files.isDirectory(Paths.get(CONFIG_FILE_LOCATION), LinkOption.NOFOLLOW_LINKS)) {
|
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;
|
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()));
|
BufferedReader br = new BufferedReader(new FileReader(Paths.get(CONFIG_FILE_LOCATION).toFile()));
|
||||||
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()) {
|
||||||
System.out.println("read empty value for key (" + key + ") from configuration file");
|
log.log(Level.FINE, "read empty value for key (" + key + ") from configuration file");
|
||||||
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());
|
||||||
@ -119,7 +116,8 @@ public class Configuration {
|
|||||||
});
|
});
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
|
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, "Error loading configuration file from (" + CONFIG_FILE_LOCATION + ") {0}", ex);
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE,
|
||||||
|
"Error loading configuration file from (" + CONFIG_FILE_LOCATION + ") {0}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +135,14 @@ public class Configuration {
|
|||||||
CONFIG_FILE_LOCATION = aCONFIG_FILE_LOCATION;
|
CONFIG_FILE_LOCATION = aCONFIG_FILE_LOCATION;
|
||||||
if (persistent) {
|
if (persistent) {
|
||||||
props.setProperty(CONFIG_FILE_KEY, CONFIG_FILE_LOCATION);
|
props.setProperty(CONFIG_FILE_KEY, CONFIG_FILE_LOCATION);
|
||||||
|
prefs.put(CONFIG_FILE_KEY, CONFIG_FILE_LOCATION);
|
||||||
|
try {
|
||||||
|
prefs.flush();
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
log.log(Level.WARNING,
|
||||||
|
"Backing store exception while committing configuration file path to persistent storage {0}",
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -161,18 +167,20 @@ public class Configuration {
|
|||||||
try {
|
try {
|
||||||
Files.copy(Paths.get(CONFIG_FILE_LOCATION), Paths.get(CONFIG_FILE_LOCATION + "bkup"));
|
Files.copy(Paths.get(CONFIG_FILE_LOCATION), Paths.get(CONFIG_FILE_LOCATION + "bkup"));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
if(ioe instanceof NoSuchFileException) {
|
if (ioe instanceof NoSuchFileException) {
|
||||||
log.log(Level.FINE, "No existing configuration file--not creating backup");
|
log.log(Level.FINE, "No existing configuration file--not creating backup");
|
||||||
} else {
|
} else {
|
||||||
log.log(Level.WARNING, "Exception encountered while trying to create configuration file backup: {0}", ioe);
|
log.log(Level.WARNING,
|
||||||
|
"Exception encountered while trying to create configuration file backup: {0}", ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
System.err.println("Making backup configuration file failed. Exiting without committing configuration to file");
|
System.err.println(
|
||||||
|
"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))) {
|
try (BufferedWriter br = new BufferedWriter(new FileWriter(Paths.get(CONFIG_FILE_LOCATION).toFile(), false))) {
|
||||||
configuration.forEach((key, value) -> {
|
configuration.forEach((key, value) -> {
|
||||||
try {
|
try {
|
||||||
br.append(key + delimiter + value + "\n");
|
br.append(key + delimiter + value + "\n");
|
||||||
|
@ -23,12 +23,11 @@ class GuildProfile {
|
|||||||
g = g1;
|
g = g1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HashMap<String, Snowflake> customemojis = new HashMap<>();
|
private HashMap<String, Snowflake> customemojis = new HashMap<>();
|
||||||
|
|
||||||
private HashMap<String, Snowflake> approvingcustomemojis = new HashMap<>();
|
private HashMap<String, Snowflake> approvingcustomemojis = new HashMap<>();
|
||||||
|
|
||||||
//Just so it's seekable, for the random approving emoji methods.
|
// Just so it's seekable, for the random approving emoji methods.
|
||||||
private ArrayList<String> approvingcustomemojinames = new ArrayList<>();
|
private ArrayList<String> approvingcustomemojinames = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,11 +70,7 @@ class GuildProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GuildEmoji getEmojiByNumber(int i) {
|
public GuildEmoji getEmojiByNumber(int i) {
|
||||||
return g.getGuildEmojiById(
|
return g.getGuildEmojiById(approvingcustomemojis.get(approvingcustomemojinames.get(i))).block();
|
||||||
approvingcustomemojis.get(approvingcustomemojinames
|
|
||||||
.get(i)
|
|
||||||
)
|
|
||||||
).block();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,9 @@ public class InstantiableConfiguration {
|
|||||||
if (Files.exists(Paths.get(DEFAULT_CONFIG_FILE_NAME), LinkOption.NOFOLLOW_LINKS)) {
|
if (Files.exists(Paths.get(DEFAULT_CONFIG_FILE_NAME), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
return DEFAULT_CONFIG_FILE_NAME;
|
return DEFAULT_CONFIG_FILE_NAME;
|
||||||
}
|
}
|
||||||
//JDialog jd = new JDialog();
|
// JDialog jd = new JDialog();
|
||||||
//jd.add(new JLabel("Choose where to put Priestess Working Directory"));
|
// jd.add(new JLabel("Choose where to put Priestess Working Directory"));
|
||||||
//jd.setVisible(true);
|
// 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);
|
||||||
@ -89,7 +89,8 @@ public class InstantiableConfiguration {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (Files.isDirectory(Paths.get(CONFIG_FILE_LOCATION), LinkOption.NOFOLLOW_LINKS)) {
|
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;
|
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()));
|
BufferedReader br = new BufferedReader(new FileReader(Paths.get(CONFIG_FILE_LOCATION).toFile()));
|
||||||
br.lines().forEach((s) -> {
|
br.lines().forEach((s) -> {
|
||||||
@ -104,7 +105,8 @@ public class InstantiableConfiguration {
|
|||||||
});
|
});
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
|
|
||||||
Logger.getLogger(InstantiableConfiguration.class.getName()).log(Level.SEVERE, "Error loading configuration file from (" + CONFIG_FILE_LOCATION + ") {0}", ex);
|
Logger.getLogger(InstantiableConfiguration.class.getName()).log(Level.SEVERE,
|
||||||
|
"Error loading configuration file from (" + CONFIG_FILE_LOCATION + ") {0}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,14 +148,16 @@ public class InstantiableConfiguration {
|
|||||||
try {
|
try {
|
||||||
Files.copy(Paths.get(CONFIG_FILE_LOCATION), Paths.get(CONFIG_FILE_LOCATION + "bkup"));
|
Files.copy(Paths.get(CONFIG_FILE_LOCATION), Paths.get(CONFIG_FILE_LOCATION + "bkup"));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
log.log(Level.WARNING, "Exception encountered while trying to create confirguation file backup: {0}", ioe);
|
log.log(Level.WARNING, "Exception encountered while trying to create confirguation file backup: {0}",
|
||||||
|
ioe);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(InstantiableConfiguration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(InstantiableConfiguration.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
System.err.println("Making backup configuration file failed. Exiting without committing configuration to file");
|
System.err.println(
|
||||||
|
"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))) {
|
try (BufferedWriter br = new BufferedWriter(new FileWriter(Paths.get(CONFIG_FILE_LOCATION).toFile(), false))) {
|
||||||
configuration.forEach((key, value) -> {
|
configuration.forEach((key, value) -> {
|
||||||
try {
|
try {
|
||||||
br.append(key + delimiter + value + "\n");
|
br.append(key + delimiter + value + "\n");
|
||||||
|
@ -45,6 +45,7 @@ public class JKRSONTag {
|
|||||||
public void setVal(String val) {
|
public void setVal(String val) {
|
||||||
this.val = val;
|
this.val = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String val;
|
private String val;
|
||||||
|
|
||||||
|
@ -17,6 +17,14 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* OH IT STORES THE PROPHECIES
|
||||||
|
*
|
||||||
|
* The configuration file (priestessconfig.txt) contains a key, 'messages', for which the value is a path to the messages store.
|
||||||
|
* The messages store contains prophecies that are given every few bean goose invocations.
|
||||||
|
* This class first loads the file, scans it and generates a list of indices for the messages it contains.
|
||||||
|
*
|
||||||
|
* This class could definitely use a cache of the message starts--a special block at the beginning/end of the file with a list of message starts/ends,
|
||||||
|
* but I'm not up to writing that today - 7 May 2023
|
||||||
*
|
*
|
||||||
* @author atomb
|
* @author atomb
|
||||||
*/
|
*/
|
||||||
@ -32,8 +40,10 @@ public class MessageStore {
|
|||||||
Thread t;
|
Thread t;
|
||||||
|
|
||||||
private boolean messagesCached = false;
|
private boolean messagesCached = false;
|
||||||
|
private long loadStart = Long.MAX_VALUE;
|
||||||
|
|
||||||
public MessageStore(File f1) throws FileNotFoundException, IOException {
|
public MessageStore(File f1) throws FileNotFoundException, IOException {
|
||||||
|
loadStart = System.nanoTime();
|
||||||
f = new RandomAccessFile(f1.getPath(), "r");
|
f = new RandomAccessFile(f1.getPath(), "r");
|
||||||
System.out.println("Message store is " + f.length() + " bytes long");
|
System.out.println("Message store is " + f.length() + " bytes long");
|
||||||
fr = f.getChannel();
|
fr = f.getChannel();
|
||||||
@ -102,7 +112,7 @@ public class MessageStore {
|
|||||||
log.setLevel(Level.FINE);
|
log.setLevel(Level.FINE);
|
||||||
log.log(Level.INFO, "Attempting to characterize message store");
|
log.log(Level.INFO, "Attempting to characterize message store");
|
||||||
try {
|
try {
|
||||||
ArrayList<Integer> messagestartsal = new ArrayList<>(); //contains index of every '{'
|
ArrayList<Integer> messagestartsal = new ArrayList<>(); // contains index of every '{'
|
||||||
char c;
|
char c;
|
||||||
int a = 0;
|
int a = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -131,7 +141,10 @@ public class MessageStore {
|
|||||||
System.out.println("Found invocation message at position " + i);
|
System.out.println("Found invocation message at position " + i);
|
||||||
}
|
}
|
||||||
messagesCached = true;
|
messagesCached = true;
|
||||||
}
|
|
||||||
|
|
||||||
|
long loadEnd = System.nanoTime();
|
||||||
|
long tdiff = loadEnd - loadStart;
|
||||||
|
log.log(Level.FINE, "Prophecies loaded in {0} ms", tdiff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
: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
|
||||||
*/
|
*/
|
||||||
@ -52,8 +54,9 @@ public class Priestess {
|
|||||||
|
|
||||||
private static void trySetDebugLevel(String level) {
|
private static void trySetDebugLevel(String level) {
|
||||||
try {
|
try {
|
||||||
debug_level = Integer.parseInt(level);
|
Level new_debug_level = Level.parse(level);
|
||||||
log.setLevel(new CustomLoggingLevel(debug_level));
|
log.setLevel(new_debug_level);
|
||||||
|
debug_level = new_debug_level.intValue();
|
||||||
log.log(Level.INFO, "Logging level set to {0}", level);
|
log.log(Level.INFO, "Logging level set to {0}", level);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
log.log(Level.WARNING, "Invalid custom logging level ({0})", level);
|
log.log(Level.WARNING, "Invalid custom logging level ({0})", level);
|
||||||
@ -96,14 +99,7 @@ public class Priestess {
|
|||||||
|
|
||||||
private static boolean allChannelsCultable = false;
|
private static boolean allChannelsCultable = false;
|
||||||
|
|
||||||
private String[] approvingEmojis = {
|
private String[] approvingEmojis = { "U+1F44D", "U+270C", "U+1F525", "U+2764", "U+1F496", "U+1F63B" };
|
||||||
"U+1F44D",
|
|
||||||
"U+270C",
|
|
||||||
"U+1F525",
|
|
||||||
"U+2764",
|
|
||||||
"U+1F496",
|
|
||||||
"U+1F63B"
|
|
||||||
};
|
|
||||||
|
|
||||||
private int invocationsThisSession = 0;
|
private int invocationsThisSession = 0;
|
||||||
|
|
||||||
@ -117,21 +113,28 @@ 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.");
|
||||||
switch (args[i].substring(2)) {
|
String yarg = args[i].substring(2, args[i].indexOf('='));
|
||||||
|
switch (yarg) {
|
||||||
case "config-file":
|
case "config-file":
|
||||||
|
Configuration.setCONFIG_FILE_LOCATION(yarg, false);
|
||||||
i++;
|
i++;
|
||||||
Configuration.setCONFIG_FILE_LOCATION(args[i], false);
|
|
||||||
break;
|
break;
|
||||||
case "config-file-persistent":
|
case "config-file-persistent":
|
||||||
|
Configuration.setCONFIG_FILE_LOCATION(yarg, true);
|
||||||
i++;
|
i++;
|
||||||
Configuration.setCONFIG_FILE_LOCATION(args[i], true);
|
|
||||||
break;
|
break;
|
||||||
case "debug-level":
|
case "debug-level":
|
||||||
|
String newlevel = args[i].substring(args[i].indexOf('=')+1);
|
||||||
|
Configuration.setConfigurationParameter(DEBUG_LEVEL, newlevel);
|
||||||
|
trySetDebugLevel(newlevel);
|
||||||
i++;
|
i++;
|
||||||
Configuration.setConfigurationParameter(DEBUG_LEVEL, args[i]);
|
|
||||||
trySetDebugLevel(args[i]);
|
|
||||||
break;
|
break;
|
||||||
//There is precisely no reason for me to include this.
|
case "debug":
|
||||||
|
Configuration.setConfigurationParameter(DEBUG_LEVEL, Level.ALL.toString());
|
||||||
|
trySetDebugLevel(yarg);
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
// There is precisely no reason for me to include this.
|
||||||
case "windows-lineendings":
|
case "windows-lineendings":
|
||||||
NEWLINE = "\r\n";
|
NEWLINE = "\r\n";
|
||||||
break;
|
break;
|
||||||
@ -140,7 +143,7 @@ public class Priestess {
|
|||||||
log.log(Level.INFO, "Listening to all channels in joined guilds.");
|
log.log(Level.INFO, "Listening to all channels in joined guilds.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
log.log(Level.INFO, "Unknown command-line argument: {0}", yarg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +156,8 @@ public class Priestess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerEmoji(Guild g, Snowflake emojiFlake, String emojiName) {
|
private void registerEmoji(Guild g, Snowflake emojiFlake, String emojiName) {
|
||||||
System.out.println(String.format("\nCustom Emoji Detected: \nServer:\t%s\nFlake:\t%s\nName:\t%s", g, emojiFlake, emojiName));
|
System.out.println(String.format("\nCustom Emoji Detected: \nServer:\t%s\nFlake:\t%s\nName:\t%s", g, emojiFlake,
|
||||||
|
emojiName));
|
||||||
if (!guildemojimaps.containsKey(g)) {
|
if (!guildemojimaps.containsKey(g)) {
|
||||||
guildemojimaps.put(g, new GuildProfile(g));
|
guildemojimaps.put(g, new GuildProfile(g));
|
||||||
}
|
}
|
||||||
@ -187,7 +191,7 @@ public class Priestess {
|
|||||||
String commandline = cdr(magicPhrase, c);
|
String commandline = cdr(magicPhrase, c);
|
||||||
System.out.println("Attempting to run command (" + commandline + ") with permission level " + permissionLevel);
|
System.out.println("Attempting to run command (" + commandline + ") with permission level " + permissionLevel);
|
||||||
|
|
||||||
Command.tryAll(commandline, m, permissionLevel); //System.out.println("payload " + payload);
|
Command.tryAll(commandline, m, permissionLevel); // System.out.println("payload " + payload);
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,10 +205,8 @@ public class Priestess {
|
|||||||
Guild g = m.getGuild().block();
|
Guild g = m.getGuild().block();
|
||||||
GuildProfile gp = guildemojimaps.get(g);
|
GuildProfile gp = guildemojimaps.get(g);
|
||||||
if (gp == null) {
|
if (gp == null) {
|
||||||
log.log(Level.INFO,
|
log.log(Level.INFO, "Message from unregistered guild, " + "not registering now.");
|
||||||
"Message from unregistered guild, "
|
// register guild?
|
||||||
+ "not registering now.");
|
|
||||||
//register guild?
|
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,15 +220,16 @@ public class Priestess {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Function<MessageCreateEvent, Publisher<Mono>> directmessagehandler = (var t) -> {
|
Function<MessageCreateEvent, Publisher<Mono>> directmessagehandler = (var t) -> {
|
||||||
//System.out.println("ya boi");
|
// System.out.println("ya boi");
|
||||||
Message m = t.getMessage();
|
Message m = t.getMessage();
|
||||||
String c = m.getContent();
|
String c = m.getContent();
|
||||||
log.log(Level.FINE, "processing direct message {0}", c);
|
log.log(Level.FINE, "processing direct message {0}", c);
|
||||||
|
|
||||||
log.log(Level.FINE, "User snowflake for message {0} is {1}", new Object[]{c, m.getAuthor().get().getId().asString()});
|
log.log(Level.FINE, "User snowflake for message {0} is {1}",
|
||||||
|
new Object[] { c, m.getAuthor().get().getId().asString() });
|
||||||
|
|
||||||
if (c.equalsIgnoreCase(magicPhrase)) {
|
if (c.equalsIgnoreCase(magicPhrase)) {
|
||||||
//System.out.println("approved");
|
// System.out.println("approved");
|
||||||
m.addReaction(ReactionEmoji.codepoints(randomApprovingEmoji())).subscribe();
|
m.addReaction(ReactionEmoji.codepoints(randomApprovingEmoji())).subscribe();
|
||||||
} else if (c.startsWith(magicPhrase)) {
|
} else if (c.startsWith(magicPhrase)) {
|
||||||
return dispatchCommand(t, m, c);
|
return dispatchCommand(t, m, c);
|
||||||
@ -249,7 +252,7 @@ public class Priestess {
|
|||||||
log.log(Level.INFO, String.format("Starting Priestess normally"));
|
log.log(Level.INFO, String.format("Starting Priestess normally"));
|
||||||
}
|
}
|
||||||
setup();
|
setup();
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -272,27 +275,23 @@ public class Priestess {
|
|||||||
guildnames.put(g.getName(), g);
|
guildnames.put(g.getName(), g);
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}).subscribe();
|
||||||
).subscribe();
|
|
||||||
|
|
||||||
dc.getGuilds().flatMap((g)
|
dc.getGuilds().flatMap((g) -> g.getChannels().flatMap((channel) -> {
|
||||||
-> g.getChannels().flatMap((channel) -> {
|
|
||||||
|
|
||||||
log.log(Level.INFO, "Checking cultability of channel {0}", channel.getName());
|
log.log(Level.INFO, "Checking cultability of channel {0}", channel.getName());
|
||||||
if (channel.getName().equals(cultChannelName)) {
|
if (channel.getName().equals(cultChannelName)) {
|
||||||
System.out.println("Channel " + channel.getName() + " in " + g.getName() + " is cultable");
|
log.log(Level.INFO, "Channel " + channel.getName() + " in " + g.getName() + " is cultable");
|
||||||
cultableChannelIDs.add(channel.getId());
|
cultableChannelIDs.add(channel.getId());
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
})
|
})).subscribe();
|
||||||
).subscribe();
|
|
||||||
|
|
||||||
dc.getGuilds().flatMap(g -> g.getEmojis()).flatMap(g2 -> {
|
dc.getGuilds().flatMap(g -> g.getEmojis()).flatMap(g2 -> {
|
||||||
//system.out.println("emoji");
|
// system.out.println("emoji");
|
||||||
registerEmoji(g2.getGuild().block(), g2.getId(), g2.getName());
|
registerEmoji(g2.getGuild().block(), g2.getId(), g2.getName());
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}).subscribe();
|
||||||
).subscribe();
|
|
||||||
|
|
||||||
dc.on(ConnectEvent.class, event -> {
|
dc.on(ConnectEvent.class, event -> {
|
||||||
|
|
||||||
@ -312,12 +311,10 @@ public class Priestess {
|
|||||||
flywheel.put("System.in listener", t);
|
flywheel.put("System.in listener", t);
|
||||||
|
|
||||||
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)
|
.filter(g -> !g.getGuild().blockOptional().isEmpty()).flatMap(guildedmessagehandler).subscribe();
|
||||||
.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(directmessagehandler)
|
.filter(g -> g.getGuild().blockOptional().isEmpty()).flatMap(directmessagehandler).blockLast();
|
||||||
.blockLast();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int invocationsBeforeThisSession = 0;
|
private int invocationsBeforeThisSession = 0;
|
||||||
@ -348,7 +345,8 @@ public class Priestess {
|
|||||||
ms = setupMessageStore();
|
ms = setupMessageStore();
|
||||||
|
|
||||||
long free0 = Runtime.getRuntime().freeMemory();
|
long free0 = Runtime.getRuntime().freeMemory();
|
||||||
log.log(Level.FINE, "Initialization complete. approx. {0} bytes free in memory.\n Attempting garbage collection.", free0);
|
log.log(Level.FINE,
|
||||||
|
"Initialization complete. approx. {0} bytes free in memory.\n Attempting garbage collection.", free0);
|
||||||
Runtime.getRuntime().gc();
|
Runtime.getRuntime().gc();
|
||||||
long free1 = Runtime.getRuntime().freeMemory();
|
long free1 = Runtime.getRuntime().freeMemory();
|
||||||
long freediff = free1 - free0;
|
long freediff = free1 - free0;
|
||||||
@ -384,7 +382,8 @@ public class Priestess {
|
|||||||
private void invokeDeity(Guild g, Message m) {
|
private void invokeDeity(Guild g, Message m) {
|
||||||
int ae_custom = guildemojimaps.get(g).approvingEmojiCount();
|
int ae_custom = guildemojimaps.get(g).approvingEmojiCount();
|
||||||
int emojicount = approvingEmojis.length + ae_custom;
|
int emojicount = approvingEmojis.length + ae_custom;
|
||||||
//System.out.println(approvingEmojis.length + " default, " + ae_custom + " custom approving emojis.");
|
// System.out.println(approvingEmojis.length + " default, " + ae_custom + "
|
||||||
|
// custom approving emojis.");
|
||||||
int which = (int) (Math.random() * emojicount);
|
int which = (int) (Math.random() * emojicount);
|
||||||
if (which < approvingEmojis.length) {
|
if (which < approvingEmojis.length) {
|
||||||
m.addReaction(ReactionEmoji.codepoints(randomApprovingEmoji())).subscribe();
|
m.addReaction(ReactionEmoji.codepoints(randomApprovingEmoji())).subscribe();
|
||||||
@ -446,8 +445,7 @@ public class Priestess {
|
|||||||
|
|
||||||
private void dispatchMilestone(int i, Guild g, Message m) {
|
private void dispatchMilestone(int i, Guild g, Message m) {
|
||||||
if ((i % 5) == 0) {
|
if ((i % 5) == 0) {
|
||||||
MessageCreateSpec mcs = MessageCreateSpec.create()
|
MessageCreateSpec mcs = MessageCreateSpec.create().withMessageReference(m.getId())
|
||||||
.withMessageReference(m.getId())
|
|
||||||
.withContent(randomMessage());
|
.withContent(randomMessage());
|
||||||
m.getChannel().block().createMessage(mcs).subscribe();
|
m.getChannel().block().createMessage(mcs).subscribe();
|
||||||
}
|
}
|
||||||
@ -475,9 +473,11 @@ public class Priestess {
|
|||||||
for (String token : tokens) {
|
for (String token : tokens) {
|
||||||
|
|
||||||
String sflake = token.substring(0, token.indexOf(subtokenDelimiter));
|
String sflake = token.substring(0, token.indexOf(subtokenDelimiter));
|
||||||
String perm = token.substring(token.indexOf(subtokenDelimiter) + subtokenDelimiter.length(), token.length());
|
String perm = token.substring(token.indexOf(subtokenDelimiter) + subtokenDelimiter.length(),
|
||||||
|
token.length());
|
||||||
|
|
||||||
System.out.println("Adding snowflake (" + sflake + ") to whitelist with permission level (" + perm + ").");
|
System.out.println(
|
||||||
|
"Adding snowflake (" + sflake + ") to whitelist with permission level (" + perm + ").");
|
||||||
|
|
||||||
Snowflake a = Snowflake.of(sflake);
|
Snowflake a = Snowflake.of(sflake);
|
||||||
|
|
||||||
@ -486,6 +486,9 @@ public class Priestess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
private MessageStore setupMessageStore() {
|
private MessageStore setupMessageStore() {
|
||||||
String mesglist = Configuration.getConfigurationParameter(MESSAGES);
|
String mesglist = Configuration.getConfigurationParameter(MESSAGES);
|
||||||
File f = Paths.get(mesglist).toFile();
|
File f = Paths.get(mesglist).toFile();
|
||||||
@ -494,7 +497,7 @@ public class Priestess {
|
|||||||
return ms1;
|
return ms1;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
|
log.log(Level.WARNING, "Message store file does not exist.");
|
||||||
} else {
|
} else {
|
||||||
log.log(Level.SEVERE, e.getMessage());
|
log.log(Level.SEVERE, e.getMessage());
|
||||||
}
|
}
|
||||||
@ -554,7 +557,8 @@ public class Priestess {
|
|||||||
StringBuilder s = new StringBuilder();
|
StringBuilder s = new StringBuilder();
|
||||||
boolean inQuote = false;
|
boolean inQuote = false;
|
||||||
for (char c : payload.toCharArray()) {
|
for (char c : payload.toCharArray()) {
|
||||||
//log.log(Level.FINE, String.format("c: %c, inQuote: %s", c, (inQuote ? "yes" : "no")));
|
// log.log(Level.FINE, String.format("c: %c, inQuote: %s", c, (inQuote ? "yes" :
|
||||||
|
// "no")));
|
||||||
if (!inQuote && c == '\"') {
|
if (!inQuote && c == '\"') {
|
||||||
inQuote = true;
|
inQuote = true;
|
||||||
tryPush(a, s);
|
tryPush(a, s);
|
||||||
@ -581,24 +585,25 @@ public class Priestess {
|
|||||||
/**
|
/**
|
||||||
* I wanted the replacement string to be {xxxx} without the dollar sign, but
|
* I wanted the replacement string to be {xxxx} without the dollar sign, but
|
||||||
* unit tests failed when the help/usage was nothing but {xxxx}. Instead of
|
* unit tests failed when the help/usage was nothing but {xxxx}. Instead of
|
||||||
* investigating, I gave up and added a dollar sign to make it something
|
* investigating, I gave up and added a dollar sign to make it something like
|
||||||
* like Python's f-strings. Or JS' backtick-strings, I can never remember
|
* Python's f-strings. Or JS' backtick-strings, I can never remember which is
|
||||||
* which is which.
|
* which.
|
||||||
*/
|
*/
|
||||||
public static class Callback implements Function<CommandArgs, Publisher<Mono>> {
|
public static class Callback implements Function<CommandArgs, Publisher<Mono>> {
|
||||||
|
|
||||||
final Logger log = Logger.getLogger(Callback.class.getName());
|
final Logger log = Logger.getLogger(Callback.class.getName());
|
||||||
String[] usages = {"Undefined command usage"};
|
String[] usages = { "Undefined command usage" };
|
||||||
String help = "${usage}";
|
String help = "${usage}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs t) {
|
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."); // Generated from
|
||||||
|
// nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHelp(String commandName) {
|
public String getHelp(String commandName) {
|
||||||
String s = getUsage(commandName);
|
String s = getUsage(commandName);
|
||||||
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) {
|
||||||
@ -619,12 +624,7 @@ public class Priestess {
|
|||||||
public final Callback registerEmojiCommand = new Callback() {
|
public final Callback registerEmojiCommand = new Callback() {
|
||||||
|
|
||||||
String usage = "{commandname} EMOJI";
|
String usage = "{commandname} EMOJI";
|
||||||
String help
|
String help = "register emoji for use in basic invocations." + "" + "" + "" + "";
|
||||||
= "register emoji for use in basic invocations."
|
|
||||||
+ ""
|
|
||||||
+ ""
|
|
||||||
+ ""
|
|
||||||
+ "";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs o) {
|
public Publisher<Mono> apply(CommandArgs o) {
|
||||||
@ -688,7 +688,7 @@ public class Priestess {
|
|||||||
@Override
|
@Override
|
||||||
public Publisher<Mono> apply(CommandArgs o) {
|
public Publisher<Mono> apply(CommandArgs o) {
|
||||||
String pay2 = cdr("set", o.getPayload());
|
String pay2 = cdr("set", o.getPayload());
|
||||||
String[] paytokens = pay2.split(" ");
|
String[] paytokens = tokenize(pay2);
|
||||||
if (paytokens.length == 2) {
|
if (paytokens.length == 2) {
|
||||||
log.log(Level.INFO, "setting configuration parameter " + paytokens[0] + " to " + paytokens[1]);
|
log.log(Level.INFO, "setting configuration parameter " + paytokens[0] + " to " + paytokens[1]);
|
||||||
Configuration.setConfigurationParameter(paytokens[0], paytokens[1]);
|
Configuration.setConfigurationParameter(paytokens[0], paytokens[1]);
|
||||||
@ -740,7 +740,7 @@ public class Priestess {
|
|||||||
return t.getName().equals(tokens[1]);
|
return t.getName().equals(tokens[1]);
|
||||||
}
|
}
|
||||||
}).blockFirst();
|
}).blockFirst();
|
||||||
if (g != null) {
|
if (c != null) {
|
||||||
if (tokens.length == 3) {
|
if (tokens.length == 3) {
|
||||||
if (isAffirmative(tokens[2])) {
|
if (isAffirmative(tokens[2])) {
|
||||||
cultableChannelIDs.add(c.getId());
|
cultableChannelIDs.add(c.getId());
|
||||||
@ -805,15 +805,12 @@ public class Priestess {
|
|||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
Guild a = resolveGuildByNameOrId(arglist[0]);
|
Guild a = resolveGuildByNameOrId(arglist[0]);
|
||||||
//guildnames.get(arglist[0]);
|
// guildnames.get(arglist[0]);
|
||||||
/*
|
/*
|
||||||
for (Object a0 : guildnames.entrySet().toArray()) {
|
* for (Object a0 : guildnames.entrySet().toArray()) { Map.Entry<String, Guild>
|
||||||
Map.Entry<String, Guild> a3 = (Map.Entry<String, Guild>) a0;
|
* a3 = (Map.Entry<String, Guild>) a0; Guild a1 = (Guild) a3.getValue(); if
|
||||||
Guild a1 = (Guild) a3.getValue();
|
* (a1.getId().asString().equals(arglist[0])) { a = a1; } }
|
||||||
if (a1.getId().asString().equals(arglist[0])) {
|
*/
|
||||||
a = a1;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (a == null) {
|
if (a == null) {
|
||||||
o.replyWith("Could not find guild");
|
o.replyWith("Could not find guild");
|
||||||
@ -856,7 +853,8 @@ public class Priestess {
|
|||||||
Command.registerCommand(new Command("send to", 1).setCallback(sendToCommand));
|
Command.registerCommand(new Command("send to", 1).setCallback(sendToCommand));
|
||||||
Command.registerCommand(new Command("cult", 9000).setCallback(setCultableChannelsCommand));
|
Command.registerCommand(new Command("cult", 9000).setCallback(setCultableChannelsCommand));
|
||||||
Command.registerCommand(new Command("perm", 0).setCallback(permissionLevelCommand));
|
Command.registerCommand(new Command("perm", 0).setCallback(permissionLevelCommand));
|
||||||
Command.registerCommand(Command.commandThatJustRepliesWith("is minecraft online", "i dunno log on and find out smfh"));
|
Command.registerCommand(
|
||||||
|
Command.commandThatJustRepliesWith("is minecraft online", "i dunno log on and find out smfh"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,34 +34,26 @@ public class PriestessTest {
|
|||||||
@org.junit.jupiter.api.Test
|
@org.junit.jupiter.api.Test
|
||||||
public void testMain() {
|
public void testMain() {
|
||||||
System.out.println("main");
|
System.out.println("main");
|
||||||
String[] args = {"testsuite"};
|
String[] args = { "testsuite" };
|
||||||
Priestess.main(args);
|
Priestess.main(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@org.junit.jupiter.api.Test
|
@org.junit.jupiter.api.Test
|
||||||
public void testCallbackHelpTexts(){
|
public void testCallbackHelpTexts() {
|
||||||
assertEquals("boi", "son".replaceAll("son", "boi"));
|
assertEquals("boi", "son".replaceAll("son", "boi"));
|
||||||
|
|
||||||
|
|
||||||
Priestess p = new Priestess();
|
Priestess p = new Priestess();
|
||||||
p.shutdownCommand.help = "ha boi";
|
p.shutdownCommand.help = "ha boi";
|
||||||
testCallbackHelpText(p.shutdownCommand,
|
testCallbackHelpText(p.shutdownCommand, "shut down", "ha boi");
|
||||||
"shut down",
|
|
||||||
"ha boi");
|
|
||||||
|
|
||||||
p.shutdownCommand.help = "${commandname}";
|
p.shutdownCommand.help = "${commandname}";
|
||||||
testCallbackHelpText(p.shutdownCommand,
|
testCallbackHelpText(p.shutdownCommand, "shut down", "shut down");
|
||||||
"shut down",
|
|
||||||
"shut down");
|
|
||||||
|
|
||||||
p.shutdownCommand.help = "${commandname} turns off the entire internet";
|
p.shutdownCommand.help = "${commandname} turns off the entire internet";
|
||||||
testCallbackHelpText(p.shutdownCommand,
|
testCallbackHelpText(p.shutdownCommand, "shut down", "shut down turns off the entire internet");
|
||||||
"shut down",
|
|
||||||
"shut down turns off the entire internet");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testCallbackHelpText(Priestess.Callback c, String name, String expHelp){
|
private void testCallbackHelpText(Priestess.Callback c, String name, String expHelp) {
|
||||||
String help = c.getHelp(name);
|
String help = c.getHelp(name);
|
||||||
Assertions.assertEquals(expHelp, help);
|
Assertions.assertEquals(expHelp, help);
|
||||||
}
|
}
|
||||||
@ -71,25 +63,19 @@ public class PriestessTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTokenize() {
|
public void testTokenize() {
|
||||||
testTokenize1("a",
|
testTokenize1("a", new String[] { "a" });
|
||||||
new String[]{"a"});
|
testTokenize1("a, b", new String[] { "a,", "b" });
|
||||||
testTokenize1("a, b",
|
testTokenize1("ya boi", new String[] { "ya", "boi" });
|
||||||
new String[]{"a,", "b"});
|
// Should handle these trivially. Single quotes not special.
|
||||||
testTokenize1("ya boi",
|
testTokenize1("'''' ''' ' '''", new String[] { "''''", "'''", "'", "'''" });
|
||||||
new String[]{"ya", "boi"});
|
testTokenize1("*^@^$/><::;''", new String[] { "*^@^$/><::;''" });
|
||||||
//Should handle these trivially. Single quotes not special.
|
testTokenize1("*^@^$/> <::;''", new String[] { "*^@^$/>", "<::;''" });
|
||||||
testTokenize1("'''' ''' ' '''",
|
testTokenize1("this is not quoted, \"this is\"", new String[] { "this", "is", "not", "quoted,", "this is" });
|
||||||
new String[]{"''''", "'''", "'", "'''"});
|
testTokenize1("this is not quoted, \"this is", null);
|
||||||
testTokenize1("*^@^$/><::;''",
|
/*
|
||||||
new String[]{"*^@^$/><::;''"});
|
* testTokenize1("this is not quoted, \\\"this is", new String[]{"this", "is",
|
||||||
testTokenize1("*^@^$/> <::;''",
|
* "not", "quoted,", "\"this is"});
|
||||||
new String[]{"*^@^$/>", "<::;''"});
|
*/
|
||||||
testTokenize1("this is not quoted, \"this is\"",
|
|
||||||
new String[]{"this", "is", "not", "quoted,", "this is"});
|
|
||||||
testTokenize1("this is not quoted, \"this is",
|
|
||||||
null);
|
|
||||||
/*testTokenize1("this is not quoted, \\\"this is",
|
|
||||||
new String[]{"this", "is", "not", "quoted,", "\"this is"});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testTokenize1(String payload, String[] expResult) {
|
private void testTokenize1(String payload, String[] expResult) {
|
||||||
|
Loading…
Reference in New Issue
Block a user