|
2 | 2 |
|
3 | 3 | import de.btobastian.sdcf4j.CommandHandler;
|
4 | 4 | import de.btobastian.sdcf4j.handler.JavacordHandler;
|
5 |
| -import org.apache.logging.log4j.LogManager; |
6 |
| -import org.apache.logging.log4j.Logger; |
7 | 5 | import org.javacord.api.DiscordApi;
|
8 | 6 | import org.javacord.api.DiscordApiBuilder;
|
| 7 | +import org.javacord.api.util.logging.ExceptionLogger; |
9 | 8 | import org.javacord.bot.commands.DocsCommand;
|
10 | 9 | import org.javacord.bot.commands.ExampleCommand;
|
11 | 10 | import org.javacord.bot.commands.GitHubCommand;
|
|
17 | 16 | import org.javacord.bot.commands.SetupCommand;
|
18 | 17 | import org.javacord.bot.commands.WikiCommand;
|
19 | 18 |
|
20 |
| -public class Main { |
| 19 | +import java.io.IOException; |
| 20 | +import java.nio.file.Files; |
| 21 | +import java.nio.file.Path; |
| 22 | +import java.nio.file.Paths; |
21 | 23 |
|
22 |
| - private static Logger logger = LogManager.getLogger(Main.class); |
| 24 | +public class Main { |
23 | 25 |
|
24 | 26 | /**
|
25 |
| - * The entrance point of the bot. |
| 27 | + * The entry point of the bot. |
26 | 28 | *
|
27 |
| - * @param args The first argument should be the bot's token. Every other argument gets ignored. |
| 29 | + * @param args The bot requires exactly one argument, either a file with the token as content or the token directly. |
| 30 | + * If the argument is a relative file path, it is relative to the working directory. |
| 31 | + * @throws IOException If there is an error when reading the token file. |
28 | 32 | */
|
29 |
| - public static void main(String[] args) { |
| 33 | + public static void main(String[] args) throws IOException { |
| 34 | + Thread.setDefaultUncaughtExceptionHandler(ExceptionLogger.getUncaughtExceptionHandler()); |
| 35 | + |
| 36 | + if (args.length != 1) { |
| 37 | + System.err.println("This bot requires exactly one argument, " |
| 38 | + + "either a file with the token as content or the token directly.\n" |
| 39 | + + "If the argument is a relative file path, it is relative to the working directory"); |
| 40 | + System.exit(1); |
| 41 | + } |
| 42 | + |
| 43 | + DiscordApiBuilder apiBuilder = new DiscordApiBuilder(); |
| 44 | + |
| 45 | + // Token |
| 46 | + Path tokenFile = Paths.get(args[0]); |
| 47 | + if (Files.isRegularFile(tokenFile)) { |
| 48 | + apiBuilder.setToken(Files.newBufferedReader(tokenFile).readLine()); |
| 49 | + } else { |
| 50 | + apiBuilder.setToken(args[0]); |
| 51 | + } |
| 52 | + |
30 | 53 | // Login
|
31 |
| - DiscordApi api = new DiscordApiBuilder() |
32 |
| - .setToken(args[0]) |
| 54 | + DiscordApi api = apiBuilder |
| 55 | + .setWaitForServersOnStartup(false) |
33 | 56 | .login().join();
|
34 | 57 |
|
35 | 58 | // Register commands
|
|
0 commit comments