Implement verbosity-changer command at runtime
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d085a671c5
commit
ff4ffba45d
@ -1,19 +1,64 @@
|
|||||||
package wtf.beatrice.hidekobot;
|
package wtf.beatrice.hidekobot;
|
||||||
|
|
||||||
|
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
||||||
|
|
||||||
public class Configuration
|
public class Configuration
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static boolean verbose = false;
|
private static boolean verbose = false;
|
||||||
|
private static MessageLogger verbosityLogger;
|
||||||
private static boolean paused = false;
|
private static boolean paused = false;
|
||||||
|
private static String prefix = ".";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the bot has been started with the verbose argument.
|
||||||
|
*
|
||||||
|
* @return a boolean which is true if the bot is in verbose-mode
|
||||||
|
*/
|
||||||
public static boolean isVerbose() { return verbose; }
|
public static boolean isVerbose() { return verbose; }
|
||||||
|
|
||||||
// WARNING: verbosity spams the logs a LOT!
|
/**
|
||||||
public static void setVerbose(boolean v) { verbose = v; }
|
* Set the bot's verbosity status at runtime.
|
||||||
|
* This also registers or unregisters the message-logger listener.
|
||||||
|
*
|
||||||
|
* @param v the verbosity boolean value
|
||||||
|
*/
|
||||||
|
public static void setVerbose(boolean v)
|
||||||
|
{
|
||||||
|
verbose = v;
|
||||||
|
|
||||||
|
if(v)
|
||||||
|
{
|
||||||
|
if(verbosityLogger == null)
|
||||||
|
{
|
||||||
|
verbosityLogger = new MessageLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
HidekoBot.getAPI().addEventListener(verbosityLogger);
|
||||||
|
} else {
|
||||||
|
if(verbosityLogger != null)
|
||||||
|
{
|
||||||
|
HidekoBot.getAPI().removeEventListener(verbosityLogger);
|
||||||
|
verbosityLogger = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the bot has paused all operation.
|
||||||
|
*
|
||||||
|
* @return a boolean which is true if the bot is currently paused
|
||||||
|
*/
|
||||||
public static boolean isPaused() { return paused; }
|
public static boolean isPaused() { return paused; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the bot in paused or unpaused state.
|
||||||
|
* Paused means that it will not reply to anything expect the unpause command.
|
||||||
|
*
|
||||||
|
* @param p a boolean specifying if the bot should be paused
|
||||||
|
*/
|
||||||
public static void setPaused(boolean p) { paused = p; }
|
public static void setPaused(boolean p) { paused = p; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,15 +40,6 @@ public class HidekoBot
|
|||||||
// load token from args
|
// load token from args
|
||||||
botToken = args[0];
|
botToken = args[0];
|
||||||
|
|
||||||
// if there are more than 1 args, then iterate through them because we have additional things to do
|
|
||||||
if(args.length > 1) {
|
|
||||||
List<String> argsList = new ArrayList<>();
|
|
||||||
for(int i = 1; i < args.length; i++)
|
|
||||||
{ argsList.add(args[i]); }
|
|
||||||
|
|
||||||
if(argsList.contains("verbose")) Configuration.setVerbose(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// try to create the bot object and authenticate it with discord.
|
// try to create the bot object and authenticate it with discord.
|
||||||
@ -74,12 +65,21 @@ public class HidekoBot
|
|||||||
|
|
||||||
// register listeners
|
// register listeners
|
||||||
jda.addEventListener(new MessageListener());
|
jda.addEventListener(new MessageListener());
|
||||||
if(Configuration.isVerbose()) jda.addEventListener(new MessageLogger());
|
|
||||||
|
|
||||||
// set the bot's status
|
// set the bot's status
|
||||||
jda.getPresence().setStatus(OnlineStatus.ONLINE);
|
jda.getPresence().setStatus(OnlineStatus.ONLINE);
|
||||||
jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA"));
|
jda.getPresence().setActivity(Activity.playing("Hatsune Miku: Project DIVA"));
|
||||||
|
|
||||||
|
// if there are more than 1 args, then iterate through them because we have additional things to do.
|
||||||
|
// we are doing this at the end because we might need the API to be already initialized for some things.
|
||||||
|
if(args.length > 1) {
|
||||||
|
List<String> argsList = new ArrayList<>();
|
||||||
|
for(int i = 1; i < args.length; i++)
|
||||||
|
{ argsList.add(args[i]); }
|
||||||
|
|
||||||
|
if(argsList.contains("verbose")) Configuration.setVerbose(true);
|
||||||
|
}
|
||||||
|
|
||||||
// print the bot logo.
|
// print the bot logo.
|
||||||
logger.log("Ready!\n\n" + logger.getLogo() + "\nv" + version + " - bot is ready!\n", 2);
|
logger.log("Ready!\n\n" + logger.getLogo() + "\nv" + version + " - bot is ready!\n", 2);
|
||||||
|
|
||||||
|
@ -120,5 +120,22 @@ public class MessageListener extends ListenerAdapter
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(eventMessage.equalsIgnoreCase("hideko verbose"))
|
||||||
|
{
|
||||||
|
MessageChannel channel = event.getChannel();
|
||||||
|
|
||||||
|
boolean verbose = Configuration.isVerbose();
|
||||||
|
|
||||||
|
String msg = verbose ? "off" : "on";
|
||||||
|
msg = "Turning verbosity " + msg + "!";
|
||||||
|
|
||||||
|
Configuration.setVerbose(!verbose);
|
||||||
|
|
||||||
|
channel.sendMessage(msg).queue();
|
||||||
|
logger.log(msg);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user