add support for disabling discord

This commit is contained in:
ChomeNS
2023-05-10 15:42:21 +07:00
parent 3d049da565
commit 7dedd82729
5 changed files with 21 additions and 13 deletions

View File

@@ -45,6 +45,7 @@ public class Configuration {
}
public static class Discord {
@Getter public boolean enabled = true;
@Getter public String prefix = "default!";
@Getter public String token;
@Getter public Map<String, String> servers = new HashMap<>();

View File

@@ -56,18 +56,20 @@ public class Main {
// idk if these should be here lol, but it is just the discord stuff
JDA jda = null;
JDABuilder builder = JDABuilder.createDefault(config.discord().token());
try {
jda = builder.build();
jda.awaitReady();
} catch (LoginException e) {
System.err.println("Failed to login to Discord, stacktrace:");
e.printStackTrace();
System.exit(1);
} catch (InterruptedException ignored) {
System.exit(1);
if (config.discord().enabled()) {
JDABuilder builder = JDABuilder.createDefault(config.discord().token());
try {
jda = builder.build();
jda.awaitReady();
} catch (LoginException e) {
System.err.println("Failed to login to Discord, stacktrace:");
e.printStackTrace();
System.exit(1);
} catch (InterruptedException ignored) {
System.exit(1);
}
jda.getPresence().setPresence(Activity.playing(config.discord().statusMessage()), false); // what does `b` do? kinda sus,..,
}
jda.getPresence().setPresence(Activity.playing(config.discord().statusMessage()), false); // what does `b` do? kinda sus,..,
for (Configuration.BotOption botOption : botsOptions) {
final Bot bot = new Bot(botOption, bots, config);

View File

@@ -40,6 +40,8 @@ public class DiscordPlugin {
this.servers = options.servers();
this.jda = jda;
if (jda == null) return;
for (Bot bot : Main.bots) {
String channelId = servers.get(bot.host() + ":" + bot.port());
@@ -214,6 +216,7 @@ public class DiscordPlugin {
}
public void sendMessageInstantly (String message, String channelId) {
if (jda == null) return;
final TextChannel logChannel = jda.getTextChannelById(channelId);
logChannel.sendMessage(message).queue(
(msg) -> doneSendingInLogs.put(channelId, true),

View File

@@ -166,7 +166,7 @@ public class GrepLogPlugin {
.append(Component.newline())
.append(Component.text(results.toString()))
);
} else {
} else if (bot.config().discord().enabled()) {
bot.chat().tellraw(
Component.translatable(
"Log query finished, found %s matches. Results were sent in Discord",