Make debug logging configurable

This commit is contained in:
anthorob committed 2022-03-15 19:41:12 -04:00
1 parent f71cdb324b
commit d13e11eac5
3 files changed
+69 -16

No files matched your search

@@ -41,7 +41,7 @@ public class ConfigureCommand extends AbstractCommand {
@Override
public CommandUsage getUsage() {
return CommandUsage.create(this,
new CommandUsage.Argument(CommandUsage.Argument.Type.REQUIRED, new String[] {"musicrole", "musicvolume"}, "")
new CommandUsage.Argument(CommandUsage.Argument.Type.REQUIRED, new String[] {"musicrole", "musicvolume", "debug"}, "")
);
}
@@ -62,8 +62,8 @@ public class ConfigureCommand extends AbstractCommand {
if (args.length > 0) {
// Role for music commands
if (context.getArg(0).equals("musicrole")) {
if (args.length == 1) {
String roleDb = guildManager.getSetting(GuildManager.Settings.MUSIC_ROLE);
Role role = null;
@@ -72,11 +72,19 @@ public class ConfigureCommand extends AbstractCommand {
}
context.reply("Current role needed to use music commands (default is everyone): %s", (role == null ? "Everyone" : role.getAsMention()));
context.reply("Reset role using 'conf musicrole reset' or set it using 'conf musicrole @'");
}
if (args.length == 2) {
List<Role> roles = context.getMessage().getMentionedRoles();
if (context.getArg(1).equals("reset")) {
if (!guildManager.getSetting(GuildManager.Settings.MUSIC_ROLE).isEmpty()) {
guildManager.setSettingValue(GuildManager.Settings.MUSIC_ROLE, null);
}
context.reply("Successful reset of the role");
}
List<Role> roles = context.getMessage().getMentionedRoles();
if (roles.size() == 1) {
Role role = roles.get(0);
if (role.getGuild().getId().equals(context.getGuild().getId())) {
@@ -84,32 +92,58 @@ public class ConfigureCommand extends AbstractCommand {
context.reply("Successfully set %s as the role needed for music command", role.getAsMention());
}
}
if (context.getArg(1).equals("reset")) {
guildManager.setSettingValue(GuildManager.Settings.MUSIC_ROLE, null);
context.reply("Successful reset of the role");
}
}
}
// Default volume for music player
if (context.getArg(0).equals("musicvolume")) {
if (args.length == 1) {
int volume = Integer.parseInt(guildManager.getSetting(GuildManager.Settings.MUSIC_VOLUME));
context.reply("Default volume for music player: " + volume);
context.reply("Set using 'conf musicvolume <value between 0 and 100>'");
}
if (args.length == 2) {
try {
int volume = Integer.parseInt(args[1]);
guildManager.setSettingValue(GuildManager.Settings.MUSIC_VOLUME, String.valueOf(volume));
MusicManager.get(context.getGuild()).setVolume(volume);
context.reply("Default volume for music player is now %d", volume);
if (volume > 0 && volume <= 100) {
guildManager.setSettingValue(GuildManager.Settings.MUSIC_VOLUME, String.valueOf(volume));
MusicManager.get(context.getGuild()).setVolume(volume);
context.reply("Default volume for music player is now %d", volume);
} else
throw new NumberFormatException();
} catch (NumberFormatException e) {
throw new CommandErrorException("Not a value between 0 and 100", context, e);
context.reply("Not a value between 0 and 100");
}
}
}
// Debug
if (context.getArg(0).equals("debug")) {
if (args.length == 1) {
boolean debug = guildManager.isDebugEnabled();
context.reply("Error logging is currently %s for this guild.", (debug ? "enabled" : "disabled"));
context.reply("Use 'conf debug 0/1' to toggle between states.");
}
if (args.length == 2) {
String str = args[1];
boolean debug = guildManager.isDebugEnabled();
if (str.equals("0") || str.equalsIgnoreCase("false")) {
debug = false;
}
if (str.equals("1") || str.equalsIgnoreCase("true")) {
debug = true;
}
guildManager.setDebug(debug);
context.reply("Error logging is now %s for this guild", (debug ? "enabled" : "disabled"));
}
}
@@ -51,11 +51,16 @@ public class VolumeCommand extends AbstractMusicCommand {
return;
try {
int volume = Integer.parseInt(context.getArgumentsAsArray()[0]);
player.setVolume(volume);
context.reply("Volume set to %s", volume);
int volume = Integer.parseInt(context.getArg(0));
if (volume > 0 && volume <= 100) {
player.setVolume(volume);
context.reply("Volume set to %s", volume);
} else
throw new NumberFormatException();
} catch (NumberFormatException e) {
throw new CommandErrorException("Please enter a value from 0 to 100", context, e);
context.reply("Please enter a value from 0 to 100");
}
}
@@ -174,6 +174,20 @@ public class GuildManager {
session.close();
}
public void setDebug(boolean toggle) {
if (toggle == isDebugEnabled())
return;
Session session = sessionFactory.openSession();
session.beginTransaction();
guildEntity.setDebug(toggle);
session.update(guildEntity);
session.getTransaction().commit();
session.close();
}
public static boolean reloadSettingsForGuild(String guildId) {
GuildManager manager = GuildManager.getManager(guildId);
manager.reloadSettingsCache(true);