Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xdnw/locutus
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Sep 3, 2024
2 parents 2a60763 + 8300f22 commit 5d03391
Show file tree
Hide file tree
Showing 203 changed files with 2,839 additions and 2,303 deletions.
644 changes: 204 additions & 440 deletions src/main/java/link/locutus/discord/Locutus.java

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/main/java/link/locutus/discord/Logg.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public static void text(String msg, Object... obj) {
LOGGER.error(msg, obj);
}

private static volatile boolean setInfoLogging = false;

public static void setInfoLogging() {
if (setInfoLogging) {
return;
}
setInfoLogging = true;
// org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
// Configurator.setRootLevel(org.apache.logging.log4j.Level.INFO);
System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package link.locutus.discord;
package link.locutus.discord._main;

import link.locutus.discord.Logg;
import link.locutus.discord.config.Settings;
import link.locutus.discord.util.TimeUtil;

Expand All @@ -11,16 +12,14 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class Backup {

public static void backup() {
int turnsCheck = Settings.INSTANCE.BACKUP.TURNS;
String script = Settings.INSTANCE.BACKUP.SCRIPT;
if (script.isEmpty()) {
System.out.println("""
Logg.text("""
No backup script is mentioned in the config.yaml
It is recommended to set a backup script to prevent data loss
e.g. <https://restic.net/>
Expand All @@ -44,7 +43,7 @@ public static void backup(String script, int turnDiffRequired) throws IOExceptio
if (!lastBackup.exists()) {
// lastBackup.createNewFile();
if (!lastBackup.createNewFile()) {
System.out.println("Failed to create lastBackup.txt");
Logg.text("Failed to create lastBackup.txt");
return;
}
shouldBackup = true;
Expand Down Expand Up @@ -77,7 +76,7 @@ private static void printProcessOutput(Process process) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
Logg.text(line);
}
} catch (IOException e) {
// handle exception
Expand Down
135 changes: 135 additions & 0 deletions src/main/java/link/locutus/discord/_main/FinalizedLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package link.locutus.discord._main;

import link.locutus.discord.apiv2.PoliticsAndWarV2;
import link.locutus.discord.apiv3.PoliticsAndWarV3;
import link.locutus.discord.commands.manager.CommandManager;
import link.locutus.discord.commands.manager.v2.impl.SlashCommandManager;
import link.locutus.discord.commands.stock.StockDB;
import link.locutus.discord.config.Settings;
import link.locutus.discord.db.*;
import link.locutus.discord.util.trade.TradeManager;
import net.dv8tion.jda.api.JDA;

import java.sql.SQLException;
import java.util.concurrent.Future;
import java.util.function.Supplier;

public class FinalizedLoader implements ILoader {
private volatile BaseballDB baseBallDB;

private final SlashCommandManager slashCommandManager;
private final JDA jda;
private final ForumDB forumDb;
private final DiscordDB discordDB;
private final NationDB nationDB;
private final WarDB warDb;
private final StockDB stockDB;
private final BankDB bankDb;
private final TradeManager tradeManager;
private final CommandManager commandManager;
private final PoliticsAndWarV2 apiV2;
private final PoliticsAndWarV3 apiV3;

public FinalizedLoader(PreLoader loader) {
this.slashCommandManager = loader.getSlashCommandManager();
this.jda = loader.getJda();
this.forumDb = loader.getForumDB();
this.discordDB = loader.getDiscordDB();
this.nationDB = loader.getNationDB();
this.warDb = loader.getWarDB();
this.stockDB = loader.getStockDB();
this.bankDb = loader.getBankDB();
this.tradeManager = loader.getTradeManager();
this.commandManager = loader.getCommandManager();
this.apiV2 = loader.getApiV2();
this.apiV3 = loader.getApiV3();
}

@Override
public BaseballDB getBaseballDB() {
if (this.baseBallDB == null) {
synchronized (this) {
if (this.baseBallDB == null) {
try {
baseBallDB = new BaseballDB(Settings.INSTANCE.DATABASE);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
return this.baseBallDB;
}

@Override
public SlashCommandManager getSlashCommandManager() {
return slashCommandManager;
}

@Override
public ILoader resolveFully(long timeout) {
return this;
}

@Override
public void initialize() {
// Do nothing
}

@Override
public JDA getJda() {
return jda;
}

@Override
public ForumDB getForumDB() {
return forumDb;
}

@Override
public DiscordDB getDiscordDB() {
return discordDB;
}

@Override
public NationDB getNationDB() {
return nationDB;
}

@Override
public WarDB getWarDB() {
return warDb;
}

@Override
public StockDB getStockDB() {
return stockDB;
}

@Override
public BankDB getBankDB() {
return bankDb;
}

@Override
public TradeManager getTradeManager() {
return tradeManager;
}

@Override
public CommandManager getCommandManager() {
return commandManager;
}

@Override
public PoliticsAndWarV2 getApiV2() {
return apiV2;
}

@Override
public PoliticsAndWarV3 getApiV3() {
return apiV3;
}


}
47 changes: 47 additions & 0 deletions src/main/java/link/locutus/discord/_main/ILoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package link.locutus.discord._main;

import link.locutus.discord.apiv2.PoliticsAndWarV2;
import link.locutus.discord.apiv3.PoliticsAndWarV3;
import link.locutus.discord.commands.manager.CommandManager;
import link.locutus.discord.commands.manager.v2.impl.SlashCommandManager;
import link.locutus.discord.commands.stock.StockDB;
import link.locutus.discord.config.Settings;
import link.locutus.discord.db.*;
import link.locutus.discord.util.trade.TradeManager;
import net.dv8tion.jda.api.JDA;

public interface ILoader {
ILoader resolveFully(long timeout);
void initialize();

default String getApiKey() {
return Settings.INSTANCE.API_KEY_PRIMARY;
}

default int getNationId() {
return Settings.INSTANCE.NATION_ID;
}

default long getAdminUserId() {
return Settings.INSTANCE.ADMIN_USER_ID;
}
JDA getJda();
SlashCommandManager getSlashCommandManager();
CommandManager getCommandManager();

NationDB getNationDB();
DiscordDB getDiscordDB();
WarDB getWarDB();
BaseballDB getBaseballDB();
TradeManager getTradeManager();
StockDB getStockDB();
ForumDB getForumDB();
BankDB getBankDB();

PoliticsAndWarV3 getApiV3();
PoliticsAndWarV2 getApiV2();

default String printStacktrace() {
return "";
}
}
Loading

0 comments on commit 5d03391

Please sign in to comment.