forked from ChomeNS/chomens-bot-java
BRUH i can just do this what the fuck
yeah its like this for months best chomens moment in 2023 real?
This commit is contained in:
parent
8adef0a3ea
commit
ae8d661117
2 changed files with 209 additions and 210 deletions
|
@ -116,6 +116,8 @@ public class Bot {
|
|||
this.commandSuggestion = new CommandSuggestionPlugin(this);
|
||||
this.mail = new MailPlugin(this);
|
||||
|
||||
for (Listener listener : listeners) listener.loadedPlugins();
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
@ -216,5 +218,6 @@ public class Bot {
|
|||
|
||||
public static class Listener extends SessionAdapter {
|
||||
public void connecting () {}
|
||||
public void loadedPlugins () {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ public class DiscordPlugin {
|
|||
|
||||
public final String prefix;
|
||||
|
||||
private final Map<String, Boolean> alreadyAddedListeners = new HashMap<>();
|
||||
|
||||
public DiscordPlugin (Configuration config, JDA jda) {
|
||||
final Configuration.Discord options = config.discord();
|
||||
this.prefix = options.prefix();
|
||||
|
@ -47,36 +45,11 @@ public class DiscordPlugin {
|
|||
if (jda == null) return;
|
||||
|
||||
for (Bot bot : Main.bots) {
|
||||
String channelId = servers.get(bot.host() + ":" + bot.port());
|
||||
final String channelId = servers.get(bot.host() + ":" + bot.port());
|
||||
|
||||
bot.addListener(new Bot.Listener() {
|
||||
@Override
|
||||
public void connecting() {
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Connecting to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected (ConnectedEvent event) {
|
||||
boolean channelAlreadyAddedListeners = alreadyAddedListeners.getOrDefault(channelId, false);
|
||||
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Successfully connected to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
|
||||
if (channelAlreadyAddedListeners) return;
|
||||
|
||||
public void loadedPlugins() {
|
||||
bot.tick().addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void onTick() {
|
||||
|
@ -91,6 +64,44 @@ public class DiscordPlugin {
|
|||
sendMessage(CodeBlockUtilities.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connecting() {
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Connecting to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected (ConnectedEvent event) {
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Successfully connected to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(DisconnectedEvent event) {
|
||||
final String reason = ComponentUtilities.stringifyAnsi(event.getReason());
|
||||
sendMessageInstantly(
|
||||
"Disconnected: \n" +
|
||||
"```ansi\n" +
|
||||
reason.replace("`", "\\`") +
|
||||
"\n```"
|
||||
, channelId
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
jda.addEventListener(new ListenerAdapter() {
|
||||
@Override
|
||||
|
@ -98,7 +109,8 @@ public class DiscordPlugin {
|
|||
// TODO: IMPROVE this code because why make 172 lines just for a single discord message
|
||||
if (
|
||||
!event.getChannel().getId().equals(channelId) ||
|
||||
event.getAuthor().getId().equals(jda.getSelfUser().getId())
|
||||
event.getAuthor().getId().equals(jda.getSelfUser().getId()) ||
|
||||
!bot.loggedIn()
|
||||
) return;
|
||||
|
||||
final Message _message = event.getMessage();
|
||||
|
@ -272,22 +284,6 @@ public class DiscordPlugin {
|
|||
}
|
||||
});
|
||||
|
||||
alreadyAddedListeners.put(channelId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(DisconnectedEvent event) {
|
||||
final String reason = ComponentUtilities.stringifyAnsi(event.getReason());
|
||||
sendMessageInstantly(
|
||||
"Disconnected: \n" +
|
||||
"```ansi\n" +
|
||||
reason.replace("`", "\\`") +
|
||||
"\n```"
|
||||
, channelId
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
bot.discord(this);
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +327,7 @@ public class DiscordPlugin {
|
|||
long currentTime = System.currentTimeMillis();
|
||||
if (!nextLogTimes.containsKey(channelId) || (currentTime >= nextLogTimes.get(channelId) && doneSendingInLogs.get(channelId))
|
||||
|| currentTime - nextLogTimes.get(channelId) > 5000) {
|
||||
long logDelay = 2000; // mabe don't hardcode this
|
||||
long logDelay = 2000;
|
||||
|
||||
nextLogTimes.put(channelId, currentTime + logDelay);
|
||||
String message;
|
||||
|
|
Loading…
Reference in a new issue