scuffed push
This commit is contained in:
1 parent
1312c5fa53
commit
98d2f5d411
27 files changed
+971
-109
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package netneutrality;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import netneutrality.db.entities.OGuild;
|
||||
import netneutrality.db.entities.OGuildSetting;
|
||||
import netneutrality.handler.ratelimiter.IMessageRateLimiter;
|
||||
import netneutrality.handler.ratelimiter.MessageRateLimiterImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GuildManager {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger(GuildManager.class);
|
||||
private static final Map<String, GuildManager> managers = new ConcurrentHashMap<>();
|
||||
private final Guild guild;
|
||||
private final OGuild guildEntity;
|
||||
private final IMessageRateLimiter rateLimiter;
|
||||
|
||||
private GuildManager(Guild guild) {
|
||||
this.guild = guild;
|
||||
this.guildEntity = new OGuild(guild.getId());
|
||||
|
||||
this.rateLimiter = new MessageRateLimiterImpl();
|
||||
managers.put(guild.getId(), this);
|
||||
}
|
||||
|
||||
public static GuildManager getManager(Guild guild) {
|
||||
if (managers.containsKey(guild.getId())) {
|
||||
return managers.get(guild.getId());
|
||||
} else {
|
||||
return new GuildManager(guild);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSetting(String key) {
|
||||
return guildEntity.getSettings().getSettingByKey(key);
|
||||
}
|
||||
|
||||
public void reloadSettings() {
|
||||
guildEntity.reloadSettings();
|
||||
}
|
||||
|
||||
public IMessageRateLimiter getRateLimiter() {
|
||||
return rateLimiter;
|
||||
}
|
||||
|
||||
public Guild getGuild() {
|
||||
return guild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void load() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ import netneutrality.http.server.WebApi;
|
||||
import netneutrality.music.MusicManager;
|
||||
import netneutrality.utils.Settings;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -29,29 +32,36 @@ public class MusicBot {
|
||||
DBController.init();
|
||||
|
||||
try {
|
||||
jda = JDABuilder.createDefault(Settings.getInstance().get("bot.token"))
|
||||
jda = JDABuilder.createDefault(Settings.getInstance().get("BOT_TOKEN"))
|
||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES)
|
||||
.build();
|
||||
jda.awaitReady();
|
||||
} catch (LoginException | IllegalArgumentException | InterruptedException e) {
|
||||
logger.error(e.getMessage());
|
||||
shutdown();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
jda.getPresence().setActivity(Activity.watching("me load..."));
|
||||
jda.addEventListener(new NewCommandListener(), new EditHandler());
|
||||
|
||||
new WebApi();
|
||||
jda.getPresence().setActivity(Activity.watching("you"));
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
if( LogManager.getContext() instanceof LoggerContext) {
|
||||
logger.debug("Shutting down log4j2");
|
||||
Configurator.shutdown((LoggerContext)LogManager.getContext());
|
||||
}
|
||||
|
||||
MusicBot.shutdown();
|
||||
}));
|
||||
|
||||
ConsoleHandler consoleInput = new ConsoleHandler();
|
||||
|
||||
switch (consoleInput.init()) {
|
||||
|
||||
case "quit":
|
||||
shutdown();
|
||||
System.exit(0);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -59,13 +69,12 @@ public class MusicBot {
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
logger.info("[Net Neutrality] Shutting down...");
|
||||
System.out.println("[Net Neutrality] Shutting down...");
|
||||
MusicManager.disconnectPlayers();
|
||||
ThreadManager.shutdownExecutor();
|
||||
disconnect();
|
||||
DBController.shutdown();
|
||||
logger.info("[Net Neutrality] Shutdown complete");
|
||||
System.exit(0);
|
||||
System.out.println("[Net Neutrality] Shutdown complete");
|
||||
}
|
||||
|
||||
public static JDA getJDA() {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ThreadManager {
|
||||
}
|
||||
|
||||
public static void shutdownExecutor() {
|
||||
logger.debug("[Executor] Shutting down...");
|
||||
System.out.println("[Executor] Shutting down...");
|
||||
|
||||
try {
|
||||
for (ExecutorService ex : executors.values()) {
|
||||
@@ -74,19 +74,19 @@ public class ThreadManager {
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
logger.warn("[Executor] Running tasks interrupted");
|
||||
System.err.println("[Executor] Running tasks interrupted");
|
||||
}
|
||||
finally {
|
||||
executors.forEach((name, ex) -> {
|
||||
if (!ex.isTerminated()) {
|
||||
logger.warn("[Executor: " + name + "] Forcing shutdown of running tasks..");
|
||||
System.err.println("[Executor: " + name + "] Forcing shutdown of running tasks..");
|
||||
ex.shutdownNow();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
logger.debug("[Executor] Shutdown finished!");
|
||||
System.out.println("[Executor] Shutdown finished!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ package netneutrality.command;/*
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.entities.Permission;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package netneutrality.command.bot;/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandType;
|
||||
import netneutrality.command.Visibility;
|
||||
|
||||
public class ConfigureCommand extends AbstractCommand {
|
||||
@Override
|
||||
public boolean needAdmin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommand() {
|
||||
return "configure";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAlias() {
|
||||
return new String[] {
|
||||
"conf"
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Used to configure the bot on this server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return Visibility.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return CommandType.ADMINISTRATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(MessageReceivedEvent event, String args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class DBController {
|
||||
private final static HashMap<String, AbstractController> controllers = new HashMap<>();
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(DBController.class);
|
||||
private static final MysqlDatabase database = new MysqlDatabase(Settings.getInstance().get("mysql.database", "netneutrality"));
|
||||
private static final MysqlDatabase database = new MysqlDatabase(Settings.getInstance().get("MYSQL_DATABASE", "netneutrality"));
|
||||
|
||||
/**
|
||||
* @param controller The name of the controller as defined in the {@link AbstractController#getControllerName()}'s method
|
||||
|
||||
@@ -42,16 +42,16 @@ public class MysqlDatabase {
|
||||
|
||||
protected MysqlDatabase(String dbName) {
|
||||
this.dbName = dbName;
|
||||
String dbUser = Settings.getInstance().get("mysql.user", "root");
|
||||
String dbPass = Settings.getInstance().get("mysql.password", "");
|
||||
String dbHost = Settings.getInstance().get("mysql.host", "localhost");
|
||||
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
||||
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
||||
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
||||
|
||||
try {
|
||||
logger.info(String.format("Connecting to database '%1$s' at %2$s:3306", dbName, dbHost));
|
||||
logger.info(String.format("Connecting to database '%1$s' at %2$s:3306 with user '%3$s'", dbName, dbHost, dbUser));
|
||||
connection = new MysqlConnector(dbName, dbUser, dbHost, dbPass).connect().getConnection();
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error connecting to database. Shutting down..", e);
|
||||
MusicBot.shutdown();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +147,7 @@ public class MysqlDatabase {
|
||||
ResultSet rs = query.executeQuery();
|
||||
return rs;
|
||||
} catch (SQLException e) {
|
||||
logger.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -221,13 +220,15 @@ public class MysqlDatabase {
|
||||
* Recreate and reconnect the MySQL connection.
|
||||
*/
|
||||
public void reconnect() {
|
||||
String dbUser = Settings.getInstance().get("MYSQL_USER", "root");
|
||||
String dbPass = Settings.getInstance().get("MYSQL_PASSWORD", "");
|
||||
String dbHost = Settings.getInstance().get("MYSQL_HOST", "localhost");
|
||||
|
||||
try {
|
||||
logger.info("Reconnecting to database...");
|
||||
connection = new MysqlConnector(dbName, "root", "localhost", "").connect().getConnection();
|
||||
connection = new MysqlConnector(dbName, dbUser, dbHost, dbPass).connect().getConnection();
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error connecting to database. Shutting down..");
|
||||
MusicBot.shutdown();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package netneutrality.db.entities;/*
|
||||
*/
|
||||
|
||||
|
||||
import netneutrality.GuildManager;
|
||||
import netneutrality.db.models.MTableModel;
|
||||
|
||||
public class OGuild extends AbstractEntity {
|
||||
@@ -14,7 +15,7 @@ public class OGuild extends AbstractEntity {
|
||||
public boolean logging;
|
||||
public String logchannel;
|
||||
|
||||
public OGuildSetting settings;
|
||||
private OGuildSetting settings;
|
||||
|
||||
public OGuild(String guildId) {
|
||||
super(guildId);
|
||||
@@ -22,15 +23,24 @@ public class OGuild extends AbstractEntity {
|
||||
this.settings = new OGuildSetting(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return guildID != null;
|
||||
public void reloadSettings() {
|
||||
GuildManager.logger.debug("Reloading settings for guild: " + guildID);
|
||||
this.settings = new OGuildSetting(this);
|
||||
}
|
||||
|
||||
public String getGuildID() {
|
||||
return guildID;
|
||||
}
|
||||
|
||||
public OGuildSetting getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return guildID != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "guilds";
|
||||
@@ -49,5 +59,4 @@ public class OGuild extends AbstractEntity {
|
||||
this.logchannel = (String) table.getRow(0).get(2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package netneutrality.handler;
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.PrivateChannel;
|
||||
import netneutrality.ThreadManager;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class MessageRateLimit {
|
||||
|
||||
private static Member lastSender;
|
||||
private static OffsetDateTime timestamp;
|
||||
private static final long cooldown = 500000000L; // 1 seconds = 1000000000 nanoseconds
|
||||
|
||||
public synchronized static boolean check(Member member, Message message, MessageChannel channel) {
|
||||
|
||||
if (channel instanceof PrivateChannel)
|
||||
return false;
|
||||
|
||||
if (lastSender == null || timestamp == null) {
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (member.getUser().getId().equals(lastSender.getUser().getId())) {
|
||||
if (message.getTimeCreated().minusNanos(cooldown).isBefore(timestamp)) {
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
message.delete().queue();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,18 +4,18 @@ package netneutrality.handler;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import netneutrality.GuildManager;
|
||||
import netneutrality.command.AbstractCommand;
|
||||
import netneutrality.command.CommandManager;
|
||||
import netneutrality.command.Visibility;
|
||||
import netneutrality.command.basic.HelpCommand;
|
||||
import netneutrality.db.DBController;
|
||||
import netneutrality.db.controllers.DBMessage;
|
||||
import netneutrality.utils.MessageFunction;
|
||||
import netneutrality.utils.Settings;
|
||||
import netneutrality.utils.UserFunction;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NewCommandListener extends ListenerAdapter {
|
||||
|
||||
@@ -24,11 +24,21 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
||||
if (event.getAuthor().isBot()) return;
|
||||
if (event.isWebhookMessage()) return;
|
||||
GuildManager.getManager(event.getGuild()).getRateLimiter().check(event.getMember(), event.getMessage(), event.getChannel());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
|
||||
|
||||
if (event.getAuthor().isBot()) return;
|
||||
if (event.isWebhookMessage()) return;
|
||||
if (MessageRateLimit.check(event.getMember(), event.getMessage(), event.getChannel())) return;
|
||||
|
||||
if (event.getMessage().isEdited())
|
||||
|
||||
if (event.isFromType(ChannelType.TEXT)) {
|
||||
((DBMessage) DBController.get("message")).log(event.getGuild(), event.getTextChannel(), event.getAuthor(), event.getMessage());
|
||||
@@ -37,8 +47,8 @@ public class NewCommandListener extends ListenerAdapter {
|
||||
Message message = event.getMessage();
|
||||
String msg = message.getContentDisplay().trim();
|
||||
|
||||
if (msg.startsWith(Settings.getInstance().get("bot.prefix"))) {
|
||||
msg = msg.substring(1);
|
||||
if (msg.startsWith(Settings.getInstance().get("BOT_PREFIX", "$"))) {
|
||||
msg = msg.substring(Settings.getInstance().get("BOT_PREFIX", "$").length());
|
||||
String cmd = msg.split(" ", 2)[0];
|
||||
|
||||
if (CommandManager.commands.containsKey(cmd) || CommandManager.commandsAlias.containsKey(cmd)) {
|
||||
|
||||
@@ -9,11 +9,12 @@ package netneutrality.handler;
|
||||
|
||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ServerJoinHandler extends ListenerAdapter {
|
||||
|
||||
@Override
|
||||
public void onGuildJoin(GuildJoinEvent event){
|
||||
public void onGuildJoin(@NotNull GuildJoinEvent event){
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package netneutrality.handler.ratelimiter;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
public interface IMessageRateLimiter {
|
||||
|
||||
void check(Member member, Message message, TextChannel channel);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package netneutrality.handler.ratelimiter;/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://xtremcommunity.com/
|
||||
* https://discord.gg/CdFcyQ
|
||||
*/
|
||||
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import netneutrality.handler.ratelimiter.IMessageRateLimiter;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class MessageRateLimiterImpl implements IMessageRateLimiter {
|
||||
private int messagePerSecond = 5;
|
||||
private static Member lastSender;
|
||||
private static OffsetDateTime timestamp;
|
||||
private static final long cooldown = 500000000L; // 1 seconds = 1000000000 nanoseconds
|
||||
|
||||
@Override
|
||||
public void check(Member member, Message message, TextChannel channel) {
|
||||
|
||||
if (lastSender == null || timestamp == null) {
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
return;
|
||||
}
|
||||
|
||||
if (member.getUser().getId().equals(lastSender.getUser().getId())) {
|
||||
if (message.getTimeCreated().minusNanos(cooldown).isBefore(timestamp)) {
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
message.delete().queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lastSender = member;
|
||||
timestamp = message.getTimeCreated();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class ActionHandler implements HttpHandler {
|
||||
if (path.equals("/actions/shutdown")) {
|
||||
LogManager.getLogger(MusicBot.class).info("Request to shutdown received");
|
||||
WebApi.sendStringResponse(exchange, "Shutting down..");
|
||||
MusicBot.shutdown();
|
||||
System.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,11 @@ public class TrackScheduler extends AudioEventAdapter {
|
||||
// something is playing, it returns false and does nothing. In that case the player was already playing so this
|
||||
// track goes to the queue instead.
|
||||
boolean start = player.startTrack(track, true);
|
||||
channel.getManager().setTopic(":speaker: Now playing : " + track.getInfo().title).queue();
|
||||
|
||||
if (!start) {
|
||||
queue.offer(track);
|
||||
} else
|
||||
channel.getManager().setTopic(":speaker: Now playing : " + track.getInfo().title).queue();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextChannel(TextChannel channel) {
|
||||
|
||||
@@ -108,7 +108,7 @@ public class MessageFunction {
|
||||
|
||||
}
|
||||
|
||||
message.addField(Settings.getInstance().get("bot.prefix") + command.getCommand() + " - Arguments: " + usage, description, false);
|
||||
message.addField(Settings.getInstance().get("BOT_PREFIX") + command.getCommand() + " - Arguments: " + usage, description, false);
|
||||
}
|
||||
|
||||
return message.build();
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.dv8tion.jda.api.entities.User;
|
||||
import netneutrality.MusicBot;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Settings {
|
||||
@@ -15,21 +16,37 @@ public class Settings {
|
||||
|
||||
public Settings() {
|
||||
File file = new File("bot.config");
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
fis = new FileInputStream(file);
|
||||
prop.load(fis);
|
||||
fis.close();
|
||||
|
||||
loadEnvironmentVariables();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null)
|
||||
fis.close();
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadEnvironmentVariables() {
|
||||
Map<String, String> envs = System.getenv();
|
||||
|
||||
for (Map.Entry<String, String> env : envs.entrySet()) {
|
||||
if (prop.containsKey(env.getKey())) {
|
||||
prop.setProperty(env.getKey(), env.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Settings getInstance() {
|
||||
if(INSTANCE == null) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new Settings();
|
||||
}
|
||||
|
||||
@@ -43,7 +60,7 @@ public class Settings {
|
||||
public String get(String key, String def) {
|
||||
String property = prop.getProperty(key);
|
||||
|
||||
if (property == null)
|
||||
if (property == null || property.isEmpty())
|
||||
return def;
|
||||
|
||||
return property;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" xmlns="http://logging.apache.org/log4j/2.0/config">
|
||||
<Configuration status="WARN" shutdownHook="disable">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight{%-5level}{STYLE=Logback} %logger - %msg%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="netneutrality" level="info" additivity="false">
|
||||
<Logger name="netneutrality" level="trace" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Logger>
|
||||
<Root level="error">
|
||||
<AppenderRef ref="Console" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
</Configuration>
|
||||
Reference in new issue
Block a user