Added new config lines

This commit is contained in:
Matthew Cech
2021-01-03 20:43:45 -08:00
parent 36445d618c
commit 2b53b01178
3 changed files with 77 additions and 14 deletions
+3
View File
@@ -1,5 +1,6 @@
"Type","Key","Value" "Type","Key","Value"
"Globals","mode (dev or release)","dev" "Globals","mode (dev or release)","dev"
"Globals","activity","with a laser pointer"
"Localized Commands","beans","" "Localized Commands","beans",""
"Localized Commands","benchmark, bench","" "Localized Commands","benchmark, bench",""
"Localized Commands","bet","" "Localized Commands","bet",""
@@ -57,6 +58,8 @@
"Localized Commands","work","" "Localized Commands","work",""
"Localized Commands","yeet","" "Localized Commands","yeet",""
"Localized Strings","AddGuildRoleFailure","Failed to add %s to %s" "Localized Strings","AddGuildRoleFailure","Failed to add %s to %s"
"Localized Strings","BeansImageBottomText","BEANS"
"Localized Strings","BeansImageTopText","YOU HAVE"
"Localized Strings","BeansShowDisplay","You have %s beans!" "Localized Strings","BeansShowDisplay","You have %s beans!"
"Localized Strings","BeansShowInfo","Displays how many beans you have" "Localized Strings","BeansShowInfo","Displays how many beans you have"
"Localized Strings","BeansShowMentioned","I took a look and %sbeans!" "Localized Strings","BeansShowMentioned","I took a look and %sbeans!"
1 Type Key Value
2 Globals mode (dev or release) dev
3 Globals activity with a laser pointer
4 Localized Commands beans
5 Localized Commands benchmark, bench
6 Localized Commands bet
58 Localized Commands work
59 Localized Commands yeet
60 Localized Strings AddGuildRoleFailure Failed to add %s to %s
61 Localized Strings BeansImageBottomText BEANS
62 Localized Strings BeansImageTopText YOU HAVE
63 Localized Strings BeansShowDisplay You have %s beans!
64 Localized Strings BeansShowInfo Displays how many beans you have
65 Localized Strings BeansShowMentioned I took a look and %sbeans!
+35 -1
View File
@@ -18,13 +18,20 @@ public class ConfigGlobals implements IConfigSection
private static final String startupStyleKey = "mode (dev or release)"; private static final String startupStyleKey = "mode (dev or release)";
private KittyStartupMode startupStyleValue = KittyStartupMode.Dev; private KittyStartupMode startupStyleValue = KittyStartupMode.Dev;
// Constructor private static final String activityKey = "activity";
private String activityValue = "with a laser pointer"; // Appears as "Playing with a laser pointer"
// Singleton Constructor - explode if there's a problem.
public ConfigGlobals() public ConfigGlobals()
{ {
if(instance == null) if(instance == null)
{
instance = this; instance = this;
}
else else
{
GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!"); GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!");
}
} }
@Override @Override
@@ -38,6 +45,11 @@ public class ConfigGlobals implements IConfigSection
return instance.startupStyleValue; return instance.startupStyleValue;
} }
public static String getActivity()
{
return instance.activityValue;
}
@Override @Override
public void consume(List<ConfigItem> pairs) public void consume(List<ConfigItem> pairs)
{ {
@@ -52,8 +64,29 @@ public class ConfigGlobals implements IConfigSection
startupStyleValue = KittyStartupMode.Dev; startupStyleValue = KittyStartupMode.Dev;
if(value.equalsIgnoreCase(KittyStartupMode.Release.name())) if(value.equalsIgnoreCase(KittyStartupMode.Release.name()))
{
startupStyleValue = KittyStartupMode.Release; startupStyleValue = KittyStartupMode.Release;
}
if(value.equalsIgnoreCase(KittyStartupMode.PoguRelease.name()))
{
startupStyleValue = KittyStartupMode.PoguRelease;
}
continue;
} }
// Parse text for 'playing'
if(key.equalsIgnoreCase(activityKey))
{
activityValue = value;
}
}
// If we change any globals, update anything we need to.
if(ObjectBuilder.getHasInitialized())
{
ObjectBuilder.updateActivity();
} }
} }
@@ -62,6 +95,7 @@ public class ConfigGlobals implements IConfigSection
{ {
List<ConfigItem> items = new ArrayList<ConfigItem>(); List<ConfigItem> items = new ArrayList<ConfigItem>();
items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase())); items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.name().toLowerCase()));
items.add(new ConfigItem(getSectionTitle(), activityKey, activityValue));
return items; return items;
} }
+38 -12
View File
@@ -39,7 +39,7 @@ import utils.GlobalLog;
import utils.LogFilter; import utils.LogFilter;
import utils.audio.AudioUtils; import utils.audio.AudioUtils;
// NOTE(wisp): Isolated factory to assist with storage and caching if needed. // NOTE: Isolated factory to assist with storage and caching if needed.
// This also minimizes the number of places JDA interacts with our codebase. // This also minimizes the number of places JDA interacts with our codebase.
// As it stands, if the object name begins with Kitty, it's constructed here. // As it stands, if the object name begins with Kitty, it's constructed here.
// TODO: Make all methods ID based instead of event based // TODO: Make all methods ID based instead of event based
@@ -82,15 +82,20 @@ public class ObjectBuilder
// Lazy initialization multithreaded mutex stuff to prevent explosions. // Lazy initialization multithreaded mutex stuff to prevent explosions.
// TODO: Investigate using 'synchronized' instead potentially // TODO: Investigate using 'synchronized' instead potentially
private static boolean hasInitialized; private static Boolean hasInitialized = false;
private static Semaphore initMutex = new Semaphore(1); private static Semaphore initMutex = new Semaphore(1);
private static JDA kitty; private static JDA kitty;
// This is it, this is how the lazy init starts! // This is it, this is how the lazy init starts!
private static void lazyInit() private static void lazyInit()
{ {
if(hasInitialized) synchronized(hasInitialized)
return; {
if(hasInitialized)
{
return;
}
}
try try
{ {
@@ -109,14 +114,17 @@ public class ObjectBuilder
AudioSourceManagers.registerLocalSource(playerManager); AudioSourceManagers.registerLocalSource(playerManager);
// Start by reading from things that are external. Because // Start by reading from things that are external. Because
// we require these things to be resolved before the rest of the application, // we require these things to be resolved before the rest of
// we place them here. // the application, we place them here.
config = new Config(); config = new Config();
} }
finally finally
{ {
initMutex.release(); initMutex.release();
hasInitialized = true; synchronized(hasInitialized)
{
hasInitialized = true;
}
} }
} }
catch(InterruptedException ie) catch(InterruptedException ie)
@@ -126,6 +134,14 @@ public class ObjectBuilder
} }
} }
public static boolean getHasInitialized()
{
synchronized(hasInitialized)
{
return hasInitialized;
}
}
//////////////////////// ////////////////////////
// Extraction Methods // // Extraction Methods //
//////////////////////// ////////////////////////
@@ -389,22 +405,32 @@ public class ObjectBuilder
// Determine token based on config. Default to test token. // Determine token based on config. Default to test token.
String tokenToUse = Ref.TestToken; String tokenToUse = Ref.TestToken;
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release) switch(ConfigGlobals.getStartupMode())
tokenToUse = Ref.Token; {
if(ConfigGlobals.getStartupMode() == KittyStartupMode.PoguRelease) case Release: tokenToUse = Ref.Token; break;
tokenToUse = Ref.PoguToken; case PoguRelease: tokenToUse = Ref.PoguToken; break;
default: tokenToUse = Ref.TestToken; break;
}
// Construct bot based on token using the JDA Builder // Construct bot based on token using the JDA Builder
JDABuilder builder = JDABuilder.createDefault(tokenToUse); JDABuilder builder = JDABuilder.createDefault(tokenToUse);
kitty = builder.build(); kitty = builder.build();
// Set activity, and add primariy event listener. // Set activity, and add primariy event listener.
kitty.getPresence().setActivity(Activity.playing("with a laser pointer")); updateActivity();
kitty.addEventListener(new Main()); kitty.addEventListener(new Main());
return new KittyCore(kitty); return new KittyCore(kitty);
} }
// Updates the bots current activity based on the globals value.
public static void updateActivity()
{
String activity = ConfigGlobals.getActivity();
GlobalLog.log(LogFilter.Core, "Updating activity to " + activity);
kitty.getPresence().setActivity(Activity.playing(activity));
}
// Default construction of the command manager. In order to remotely resolve command enabling // Default construction of the command manager. In order to remotely resolve command enabling
// and disabling, what we do is construct the commands with a localized pair that is checked against // and disabling, what we do is construct the commands with a localized pair that is checked against
// the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can // the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can