change to land.chipmunk.chayapak because yes

This commit is contained in:
ChomeNS
2023-03-27 12:53:05 +07:00
parent cb34dfff90
commit fbf9f3e2f1
70 changed files with 221 additions and 220 deletions

View File

@@ -1,75 +0,0 @@
package me.chayapak1.chomens_bot;
import me.chayapak1.chomens_bot.plugins.ConsolePlugin;
import me.chayapak1.chomens_bot.plugins.DiscordPlugin;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class Main {
public static final List<Bot> allBots = new ArrayList<>();
public static CountDownLatch latch = null;
public static void main(String[] args) throws IOException, InterruptedException {
final File file = new File("config.yml");
final Constructor constructor = new Constructor(Configuration.class);
final Yaml yaml = new Yaml(constructor);
Configuration _config;
if (!file.exists()) {
// creates config file from default-config.yml
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default-config.yml");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
while (reader.ready()) {
char character = (char) reader.read();
stringBuilder.append(character);
}
String defaultConfig = stringBuilder.toString();
// writes it
BufferedWriter configWriter = new BufferedWriter(new FileWriter(file));
configWriter.write(defaultConfig);
configWriter.close();
System.out.println("config.yml file not found, so the default one was created");
_config = yaml.load(is);
}
InputStream opt = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(opt));
_config = yaml.load(reader);
final Configuration config = _config;
Configuration.Bots[] botsOptions = config.bots();
latch = new CountDownLatch(botsOptions.length);
for (Configuration.Bots botOption : botsOptions) {
final String host = botOption.host();
final int port = botOption.port();
final String username = botOption.username();
final boolean kaboom = botOption.kaboom();
new Thread(() -> {
final Bot bot = new Bot(host, port, username, kaboom, allBots, config);
allBots.add(bot);
latch.countDown();
}).start();
}
new DiscordPlugin(config);
latch.await();
new ConsolePlugin(allBots);
}
}