Make bot version consistent with Maven
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
A new internal properties file has been added. Maven will scan this file and replace any value it finds.
This commit is contained in:
parent
70578d2ffc
commit
40aac28e34
10
pom.xml
10
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>wtf.beatrice.hidekobot</groupId>
|
<groupId>wtf.beatrice.hidekobot</groupId>
|
||||||
<artifactId>HidekoBot</artifactId>
|
<artifactId>HidekoBot</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.4.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>16</maven.compiler.source>
|
<maven.compiler.source>16</maven.compiler.source>
|
||||||
@ -42,7 +42,15 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import wtf.beatrice.hidekobot.datasource.ConfigurationSource;
|
import wtf.beatrice.hidekobot.datasource.ConfigurationSource;
|
||||||
import wtf.beatrice.hidekobot.datasource.DatabaseSource;
|
import wtf.beatrice.hidekobot.datasource.DatabaseSource;
|
||||||
|
import wtf.beatrice.hidekobot.datasource.PropertiesSource;
|
||||||
import wtf.beatrice.hidekobot.listeners.MessageCommandListener;
|
import wtf.beatrice.hidekobot.listeners.MessageCommandListener;
|
||||||
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
import wtf.beatrice.hidekobot.listeners.MessageLogger;
|
||||||
import wtf.beatrice.hidekobot.listeners.SlashCommandListener;
|
import wtf.beatrice.hidekobot.listeners.SlashCommandListener;
|
||||||
@ -19,6 +20,8 @@ public class Cache
|
|||||||
// todo: make this compatible with the message listener's regex
|
// todo: make this compatible with the message listener's regex
|
||||||
private static final String botPrefix = "hideko";
|
private static final String botPrefix = "hideko";
|
||||||
private static final Logger logger = new Logger(Cache.class);
|
private static final Logger logger = new Logger(Cache.class);
|
||||||
|
|
||||||
|
private static PropertiesSource propertiesSource = null;
|
||||||
private static ConfigurationSource configurationSource = null;
|
private static ConfigurationSource configurationSource = null;
|
||||||
private static DatabaseSource databaseSource = null;
|
private static DatabaseSource databaseSource = null;
|
||||||
private static boolean verbose = false;
|
private static boolean verbose = false;
|
||||||
@ -33,8 +36,6 @@ public class Cache
|
|||||||
private static LocalDateTime startupTime = null;
|
private static LocalDateTime startupTime = null;
|
||||||
|
|
||||||
private final static String execPath = System.getProperty("user.dir");
|
private final static String execPath = System.getProperty("user.dir");
|
||||||
|
|
||||||
private static final String botVersion = "0.4.0"; // todo: we should probably find a way to make this consistent with Maven
|
|
||||||
private static final String botName = "Hideko";
|
private static final String botName = "Hideko";
|
||||||
|
|
||||||
private static SlashCommandListener slashCommandListener = null;
|
private static SlashCommandListener slashCommandListener = null;
|
||||||
@ -160,6 +161,16 @@ public class Cache
|
|||||||
*/
|
*/
|
||||||
public static @Nullable DatabaseSource getDatabaseSource() { return databaseSource; }
|
public static @Nullable DatabaseSource getDatabaseSource() { return databaseSource; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the properties source instance loaded from the JAR archive.
|
||||||
|
*
|
||||||
|
* @param propertiesSourceInstance the properties source instance.
|
||||||
|
*/
|
||||||
|
public static void setPropertiesSourceInstance(PropertiesSource propertiesSourceInstance)
|
||||||
|
{
|
||||||
|
propertiesSource = propertiesSourceInstance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the DateTimeFormatter string for parsing the expired messages timestamp.
|
* Get the DateTimeFormatter string for parsing the expired messages timestamp.
|
||||||
*
|
*
|
||||||
@ -182,7 +193,9 @@ public class Cache
|
|||||||
*
|
*
|
||||||
* @return a String of the bot version.
|
* @return a String of the bot version.
|
||||||
*/
|
*/
|
||||||
public static String getBotVersion() { return botVersion; }
|
public static String getBotVersion() {
|
||||||
|
return propertiesSource.getProperty("bot.version");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the bot's global color.
|
* Get the bot's global color.
|
||||||
|
@ -10,6 +10,7 @@ import wtf.beatrice.hidekobot.commands.message.HelloCommand;
|
|||||||
import wtf.beatrice.hidekobot.commands.slash.*;
|
import wtf.beatrice.hidekobot.commands.slash.*;
|
||||||
import wtf.beatrice.hidekobot.datasource.ConfigurationSource;
|
import wtf.beatrice.hidekobot.datasource.ConfigurationSource;
|
||||||
import wtf.beatrice.hidekobot.datasource.DatabaseSource;
|
import wtf.beatrice.hidekobot.datasource.DatabaseSource;
|
||||||
|
import wtf.beatrice.hidekobot.datasource.PropertiesSource;
|
||||||
import wtf.beatrice.hidekobot.listeners.ButtonInteractionListener;
|
import wtf.beatrice.hidekobot.listeners.ButtonInteractionListener;
|
||||||
import wtf.beatrice.hidekobot.listeners.MessageCommandListener;
|
import wtf.beatrice.hidekobot.listeners.MessageCommandListener;
|
||||||
import wtf.beatrice.hidekobot.listeners.SlashCommandCompleter;
|
import wtf.beatrice.hidekobot.listeners.SlashCommandCompleter;
|
||||||
@ -45,6 +46,14 @@ public class HidekoBot
|
|||||||
Cache.setConfigurationSource(configurationSource);
|
Cache.setConfigurationSource(configurationSource);
|
||||||
logger.log("Configuration loaded!");
|
logger.log("Configuration loaded!");
|
||||||
|
|
||||||
|
// load properties
|
||||||
|
logger.log("Loading properties...");
|
||||||
|
PropertiesSource propertiesSource = new PropertiesSource();
|
||||||
|
propertiesSource.load();
|
||||||
|
Cache.setPropertiesSourceInstance(propertiesSource);
|
||||||
|
logger.log("Properties loaded!");
|
||||||
|
|
||||||
|
// check loaded bot token
|
||||||
String botToken = Cache.getBotToken();
|
String botToken = Cache.getBotToken();
|
||||||
if(botToken == null || botToken.isEmpty())
|
if(botToken == null || botToken.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,11 @@ public class ConfigurationSource
|
|||||||
.getClassLoader()
|
.getClassLoader()
|
||||||
.getResourceAsStream("config.yml"))
|
.getResourceAsStream("config.yml"))
|
||||||
{ internalConfigContents = internalConfigYaml.load(internalConfigStream); }
|
{ internalConfigContents = internalConfigYaml.load(internalConfigStream); }
|
||||||
catch (IOException e) { logger.log(e.getMessage()); }
|
catch (IOException e) {
|
||||||
|
logger.log(e.getMessage());
|
||||||
|
HidekoBot.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(internalConfigContents == null)
|
if(internalConfigContents == null)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package wtf.beatrice.hidekobot.datasource;
|
||||||
|
|
||||||
|
import wtf.beatrice.hidekobot.HidekoBot;
|
||||||
|
import wtf.beatrice.hidekobot.util.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class PropertiesSource
|
||||||
|
{
|
||||||
|
|
||||||
|
private Properties properties = null;
|
||||||
|
private final String fileName = "default.properties";
|
||||||
|
private final Logger logger = new Logger(getClass());
|
||||||
|
|
||||||
|
public void load()
|
||||||
|
{
|
||||||
|
properties = new Properties();
|
||||||
|
|
||||||
|
try (InputStream internalPropertiesStream = getClass()
|
||||||
|
.getClassLoader()
|
||||||
|
.getResourceAsStream(fileName))
|
||||||
|
{
|
||||||
|
properties.load(internalPropertiesStream);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
logger.log(e.getMessage());
|
||||||
|
HidekoBot.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String property)
|
||||||
|
{ return properties == null ? "" : properties.getProperty(property); }
|
||||||
|
}
|
1
src/main/resources/default.properties
Normal file
1
src/main/resources/default.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
bot.version=${project.version}
|
Loading…
Reference in New Issue
Block a user