little config update + among us

This commit is contained in:
ChomeNS 2023-03-21 12:21:12 +07:00
parent 7246f0a36f
commit f769cd92b0
4 changed files with 20 additions and 19 deletions

View file

@ -13,7 +13,6 @@ import org.apache.commons.lang3.RandomStringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -25,14 +24,12 @@ public class Bot {
@Getter private final int port;
private final String _username;
@Getter private final List<Bot> allBots;
@Getter private final Map<String, String> keys;
@Getter private final Configuration config;
@Getter private String username;
@Getter private Session session;
@Getter private final int reconnectDelay;
@Getter private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
@Getter private final ChatPlugin chat = new ChatPlugin(this);
@ -46,13 +43,12 @@ public class Bot {
@Getter private final HashingPlugin hashing = new HashingPlugin(this);
@Getter private final MusicPlayerPlugin music = new MusicPlayerPlugin(this);
public Bot (String host, int port, int reconnectDelay, String _username, List<Bot> allBots, Map<String, String> keys) {
public Bot (String host, int port, String _username, List<Bot> allBots, Configuration config) {
this.host = host;
this.port = port;
this.reconnectDelay = reconnectDelay;
this._username = _username;
this.allBots = allBots;
this.keys = keys;
this.config = config;
reconnect();
}
@ -112,11 +108,13 @@ public class Bot {
listener.disconnected(disconnectedEvent);
}
final int reconnectDelay = config.reconnectDelay();
if (reconnectDelay < 0) return; // to disable reconnecting
Runnable task = () -> reconnect();
executor.schedule(task, reconnectDelay(), TimeUnit.MILLISECONDS);
executor.schedule(task, reconnectDelay, TimeUnit.MILLISECONDS);
}
});

View file

@ -15,7 +15,7 @@ public class Main {
final File file = new File("config.yml");
final Constructor constructor = new Constructor(Configuration.class);
final Yaml yaml = new Yaml(constructor);
Configuration config;
Configuration _config;
if (!file.exists()) {
// creates config file from default-config.yml
@ -35,16 +35,16 @@ public class Main {
System.out.println("config.yml file not found, so the default one was created");
config = yaml.load(is);
_config = yaml.load(is);
}
InputStream opt = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(opt));
config = yaml.load(reader);
_config = yaml.load(reader);
final Configuration config = _config;
final int reconnectDelay = config.reconnectDelay();
final Map<String, String> keys = config.keys();
Configuration.Bots[] botsOptions = config.bots();
final List<Bot> allBots = new ArrayList<>();
@ -57,7 +57,7 @@ public class Main {
final String username = botOption.username();
new Thread(() -> {
final Bot bot = new Bot(host, port, reconnectDelay, username, allBots, keys);
final Bot bot = new Bot(host, port, username, allBots, config);
allBots.add(bot);
latch.countDown();

View file

@ -9,7 +9,9 @@ import net.kyori.adventure.text.format.NamedTextColor;
import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.terminal.TerminalBuilder;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@ -32,6 +34,10 @@ public class ConsolePlugin {
bot.logger(new LoggerPlugin(bot));
}
try {
TerminalBuilder.builder().build();
} catch (IOException ignored) {}
String prompt = "> ";
new Thread(() -> {

View file

@ -20,11 +20,8 @@ public class HashingPlugin {
}
public void update () {
// final String ownerHashKey = "b)R<><52>nF<6E>CW<43><57><EFBFBD>#<23>\\[<5B>S*8\"t^eia<69>Z<EFBFBD><5A>k<EFBFBD><6B><EFBFBD><EFBFBD>K1<4B>8zȢ<7A>";
// final String normalHashKey = "<EFBFBD>iB_D<EFBFBD><EFBFBD><EFBFBD>k<EFBFBD><EFBFBD>j8H<EFBFBD>{?[/ڭ<>f<EFBFBD><>^-=<3D>Ț<EFBFBD><C89A>v]<5D><>g><3E><>=c";
final String normalHashKey = bot.keys().get("normalKey");
final String ownerHashKey = bot.keys().get("ownerKey");
final String normalHashKey = bot.config().keys().get("normalKey");
final String ownerHashKey = bot.config().keys().get("ownerKey");
final String hashValue = System.currentTimeMillis() / 10_000 + normalHashKey;
hash = Hashing.sha256()