This commit is contained in:
@@ -22,7 +22,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
public class Cache
|
||||
{
|
||||
|
||||
private Cache() {
|
||||
private Cache()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ public class Cache
|
||||
private static String botApplicationId = "";
|
||||
|
||||
// discord api returns a broken image if you don't use specific sizes (powers of 2), so we limit it to these
|
||||
private static final int[] supportedAvatarResolutions = { 16, 32, 64, 128, 256, 512, 1024 };
|
||||
private static final int[] supportedAvatarResolutions = {16, 32, 64, 128, 256, 512, 1024};
|
||||
|
||||
/**
|
||||
* Get an array of all the Discord-supported avatar resolutions.
|
||||
@@ -78,7 +79,10 @@ public class Cache
|
||||
*
|
||||
* @return array of supported resolutions.
|
||||
*/
|
||||
public static int[] getSupportedAvatarResolutions() { return supportedAvatarResolutions; }
|
||||
public static int[] getSupportedAvatarResolutions()
|
||||
{
|
||||
return supportedAvatarResolutions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -86,7 +90,10 @@ public class Cache
|
||||
*
|
||||
* @return a boolean which is true if the bot is in verbose-mode
|
||||
*/
|
||||
public static synchronized boolean isVerbose() { return verbose; }
|
||||
public static synchronized boolean isVerbose()
|
||||
{
|
||||
return verbose;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's verbosity status at runtime.
|
||||
@@ -98,13 +105,13 @@ public class Cache
|
||||
{
|
||||
verbose = v;
|
||||
|
||||
if(verbosityLogger != null)
|
||||
if (verbosityLogger != null)
|
||||
{
|
||||
HidekoBot.getAPI().removeEventListener(verbosityLogger);
|
||||
verbosityLogger = null;
|
||||
}
|
||||
|
||||
if(v)
|
||||
if (v)
|
||||
{
|
||||
verbosityLogger = new MessageLogger();
|
||||
HidekoBot.getAPI().addEventListener(verbosityLogger);
|
||||
@@ -116,7 +123,8 @@ public class Cache
|
||||
*
|
||||
* @return a long of the account's id
|
||||
*/
|
||||
public static long getBotOwnerId() {
|
||||
public static long getBotOwnerId()
|
||||
{
|
||||
return configurationSource == null ? 0L : (Long) configurationSource.getConfigValue(ConfigurationEntry.BOT_OWNER_ID);
|
||||
}
|
||||
|
||||
@@ -126,7 +134,8 @@ public class Cache
|
||||
*
|
||||
* @return a String of the bot's token.
|
||||
*/
|
||||
public static String getBotToken() {
|
||||
public static String getBotToken()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_TOKEN);
|
||||
}
|
||||
|
||||
@@ -136,8 +145,11 @@ public class Cache
|
||||
*
|
||||
* @return a long of the account's id
|
||||
*/
|
||||
|
||||
public static long getBotMaintainerId() { return BOT_MAINTAINER_ID; }
|
||||
|
||||
public static long getBotMaintainerId()
|
||||
{
|
||||
return BOT_MAINTAINER_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's application id.
|
||||
@@ -154,14 +166,18 @@ public class Cache
|
||||
*
|
||||
* @return a string of the bot's application id
|
||||
*/
|
||||
public static String getBotApplicationId() { return botApplicationId; }
|
||||
public static String getBotApplicationId()
|
||||
{
|
||||
return botApplicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate an invite link for the bot
|
||||
*
|
||||
* @return a string containing the invite link
|
||||
*/
|
||||
public static String getInviteUrl() {
|
||||
public static String getInviteUrl()
|
||||
{
|
||||
return DEFAULT_INVITE_LINK.replace("%userid%", botApplicationId);
|
||||
}
|
||||
|
||||
@@ -180,7 +196,10 @@ public class Cache
|
||||
*
|
||||
* @return the DatabaseSource instance.
|
||||
*/
|
||||
public static @Nullable DatabaseSource getDatabaseSource() { return databaseSource; }
|
||||
public static @Nullable DatabaseSource getDatabaseSource()
|
||||
{
|
||||
return databaseSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the properties source instance loaded from the JAR archive.
|
||||
@@ -197,24 +216,34 @@ public class Cache
|
||||
*
|
||||
* @return the String of the DateTimeFormatter format.
|
||||
*/
|
||||
public static String getExpiryTimestampFormat(){ return EXPIRY_TIMESTAMP_FORMAT; }
|
||||
public static String getExpiryTimestampFormat()
|
||||
{
|
||||
return EXPIRY_TIMESTAMP_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of seconds after which a message expires.
|
||||
*
|
||||
* @return long value of the expiry seconds.
|
||||
*/
|
||||
public static long getExpiryTimeSeconds() { return EXPIRY_TIME_SECONDS; }
|
||||
public static long getExpiryTimeSeconds()
|
||||
{
|
||||
return EXPIRY_TIME_SECONDS;
|
||||
}
|
||||
|
||||
|
||||
public static String getBotName() { return BOT_NAME; }
|
||||
public static String getBotName()
|
||||
{
|
||||
return BOT_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bot's version.
|
||||
*
|
||||
* @return a String of the bot version.
|
||||
*/
|
||||
public static String getBotVersion() {
|
||||
public static String getBotVersion()
|
||||
{
|
||||
return propertiesSource.getProperty("bot.version");
|
||||
}
|
||||
|
||||
@@ -223,7 +252,8 @@ public class Cache
|
||||
*
|
||||
* @return a String containing the base URL of the repository, including a <b>trailing slash</b>.
|
||||
*/
|
||||
public static String getRepositoryUrl() {
|
||||
public static String getRepositoryUrl()
|
||||
{
|
||||
String url = propertiesSource.getProperty("repo.base_url");
|
||||
return url.endsWith("/") ? url : url + "/";
|
||||
}
|
||||
@@ -233,16 +263,19 @@ public class Cache
|
||||
*
|
||||
* @return the Color object.
|
||||
*/
|
||||
public static Color getBotColor() {
|
||||
public static Color getBotColor()
|
||||
{
|
||||
Color defaultColor = Color.PINK;
|
||||
if(configurationSource == null) return defaultColor;
|
||||
if (configurationSource == null) return defaultColor;
|
||||
String colorName = (String) configurationSource.getConfigValue(ConfigurationEntry.BOT_COLOR);
|
||||
|
||||
Color color = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
Field field = Color.class.getField(colorName);
|
||||
color = (Color)field.get(null);
|
||||
} catch (RuntimeException | NoSuchFieldException | IllegalAccessException e) {
|
||||
color = (Color) field.get(null);
|
||||
} catch (RuntimeException | NoSuchFieldException | IllegalAccessException e)
|
||||
{
|
||||
LOGGER.error("Unknown color: {}", colorName);
|
||||
}
|
||||
return color == null ? defaultColor : color;
|
||||
@@ -251,21 +284,36 @@ public class Cache
|
||||
|
||||
//todo javadocs
|
||||
public static void setSlashCommandListener(SlashCommandListener commandListener)
|
||||
{ slashCommandListener = commandListener; }
|
||||
{
|
||||
slashCommandListener = commandListener;
|
||||
}
|
||||
|
||||
public static SlashCommandListener getSlashCommandListener() { return slashCommandListener; }
|
||||
public static SlashCommandListener getSlashCommandListener()
|
||||
{
|
||||
return slashCommandListener;
|
||||
}
|
||||
|
||||
|
||||
public static void setSlashCommandCompletionListener(SlashCommandCompletionListener commandCompletionListener)
|
||||
{ slashCommandCompletionListener = commandCompletionListener; }
|
||||
{
|
||||
slashCommandCompletionListener = commandCompletionListener;
|
||||
}
|
||||
|
||||
public static SlashCommandCompletionListener getSlashCommandCompletionListener() { return slashCommandCompletionListener; }
|
||||
public static SlashCommandCompletionListener getSlashCommandCompletionListener()
|
||||
{
|
||||
return slashCommandCompletionListener;
|
||||
}
|
||||
|
||||
|
||||
public static void setMessageCommandListener(MessageCommandListener commandListener)
|
||||
{ messageCommandListener = commandListener; }
|
||||
{
|
||||
messageCommandListener = commandListener;
|
||||
}
|
||||
|
||||
public static MessageCommandListener getMessageCommandListener() { return messageCommandListener; }
|
||||
public static MessageCommandListener getMessageCommandListener()
|
||||
{
|
||||
return messageCommandListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bot's startup time. Generally only used at boot time.
|
||||
@@ -273,7 +321,9 @@ public class Cache
|
||||
* @param time a LocalDateTime of the startup moment.
|
||||
*/
|
||||
public static void setStartupTime(LocalDateTime time)
|
||||
{ startupTime = time; }
|
||||
{
|
||||
startupTime = time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -281,37 +331,54 @@ public class Cache
|
||||
*
|
||||
* @return a LocalDateTime object of the startup instant.
|
||||
*/
|
||||
public static LocalDateTime getStartupTime() { return startupTime; }
|
||||
public static LocalDateTime getStartupTime()
|
||||
{
|
||||
return startupTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of when the bot was created.
|
||||
*
|
||||
* @return a LocalDateTime object of the first commit's instant.
|
||||
*/
|
||||
public static LocalDateTime getBotBirthDate() { return botBirthDate; }
|
||||
public static LocalDateTime getBotBirthDate()
|
||||
{
|
||||
return botBirthDate;
|
||||
}
|
||||
|
||||
public static String getFullHeartBeatLink() {
|
||||
public static String getFullHeartBeatLink()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.HEARTBEAT_LINK);
|
||||
}
|
||||
|
||||
//todo javadocs
|
||||
public static String getExecPath() { return EXEC_PATH; }
|
||||
public static String getExecPath()
|
||||
{
|
||||
return EXEC_PATH;
|
||||
}
|
||||
|
||||
/*private static ConfigurationSource getConfigurationSource()
|
||||
{ return configurationSource; }*/
|
||||
|
||||
public static String getRandomOrgApiKey() {
|
||||
public static String getRandomOrgApiKey()
|
||||
{
|
||||
return configurationSource == null ? null : (String) configurationSource.getConfigValue(ConfigurationEntry.RANDOM_ORG_API_KEY);
|
||||
}
|
||||
|
||||
public static void setConfigurationSource(ConfigurationSource configurationSource)
|
||||
{ Cache.configurationSource = configurationSource; }
|
||||
{
|
||||
Cache.configurationSource = configurationSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bot's prefix
|
||||
*
|
||||
* @return a String of the bot's prefix.
|
||||
*/
|
||||
public static String getBotPrefix() { return BOT_PREFIX; }
|
||||
public static String getBotPrefix()
|
||||
{
|
||||
return BOT_PREFIX;
|
||||
}
|
||||
|
||||
public static void cacheLoveCalculatorValue(String userId1, String userId2, int value)
|
||||
{
|
||||
@@ -326,7 +393,7 @@ public class Cache
|
||||
String merged2 = userId2 + "|" + userId1;
|
||||
Integer value = null;
|
||||
value = loveCalculatorValues.get(merged1);
|
||||
if(value == null) value = loveCalculatorValues.get(merged2);
|
||||
if (value == null) value = loveCalculatorValues.get(merged2);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -336,7 +403,8 @@ public class Cache
|
||||
loveCalculatorValues.remove(userId2 + "|" + userId1);
|
||||
}
|
||||
|
||||
public static ScheduledExecutorService getTaskScheduler() {
|
||||
public static ScheduledExecutorService getTaskScheduler()
|
||||
{
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user