refactor: bot.getServerString() to reduce mess
This commit is contained in:
@@ -311,6 +311,10 @@ public class Bot {
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
public String getServerString () {
|
||||
return host + ":" + port;
|
||||
}
|
||||
|
||||
public void stop () {
|
||||
session.disconnect("Received stop signal");
|
||||
Main.bots.remove(this);
|
||||
|
||||
@@ -197,7 +197,7 @@ public class Main {
|
||||
for (Bot bot : copiedList) {
|
||||
try {
|
||||
if (discordEnabled) {
|
||||
final String channelId = bot.discord.servers.get(bot.host + ":" + bot.port);
|
||||
final String channelId = bot.discord.servers.get(bot.getServerString());
|
||||
|
||||
final MessageCreateAction messageAction = bot.discord.sendMessageInstantly(stoppingMessage, channelId, false);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class MailCommand extends Command {
|
||||
sender.profile.getName(),
|
||||
context.getString(false, true),
|
||||
Instant.now().toEpochMilli(),
|
||||
bot.host + ":" + bot.port,
|
||||
bot.getServerString(),
|
||||
context.getString(true, true)
|
||||
)
|
||||
);
|
||||
@@ -86,7 +86,7 @@ public class MailCommand extends Command {
|
||||
sender.profile.getName(),
|
||||
context.getString(true, true),
|
||||
Instant.now().toEpochMilli(),
|
||||
bot.host + ":" + bot.port,
|
||||
bot.getServerString(),
|
||||
output
|
||||
)
|
||||
);
|
||||
|
||||
@@ -29,18 +29,18 @@ public class NetMessageCommand extends Command {
|
||||
final Bot bot = context.bot;
|
||||
final List<Bot> bots = bot.bots;
|
||||
|
||||
final String hostAndPort = bot.host + ":" + bot.port;
|
||||
final String originServer = bot.getServerString();
|
||||
|
||||
final Component component = Component.translatable(
|
||||
"[%s]%s%s%s› %s",
|
||||
Component
|
||||
.text(hostAndPort)
|
||||
.text(originServer)
|
||||
.color(NamedTextColor.GRAY)
|
||||
.clickEvent(ClickEvent.copyToClipboard(hostAndPort))
|
||||
.clickEvent(ClickEvent.copyToClipboard(originServer))
|
||||
.hoverEvent(
|
||||
HoverEvent.showText(
|
||||
Component.empty()
|
||||
.append(Component.text(hostAndPort).color(NamedTextColor.GRAY))
|
||||
.append(Component.text(originServer).color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Click here to copy the server host and port to your clipboard").color(NamedTextColor.GREEN))
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
||||
public AuthPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.ownerIpForServer = bot.config.ownerAuthentication.ips.get(bot.host + ":" + bot.port);
|
||||
this.ownerIpForServer = bot.config.ownerAuthentication.ips.get(bot.getServerString());
|
||||
|
||||
if (!bot.config.ownerAuthentication.enabled || ownerIpForServer == null) return;
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ public class ConsolePlugin implements Completer {
|
||||
if (line == null) return;
|
||||
|
||||
for (Bot bot : allBots) {
|
||||
final String hostAndPort = bot.host + ":" + bot.port;
|
||||
final String server = bot.getServerString();
|
||||
|
||||
if (!hostAndPort.equals(consoleServer) && !consoleServer.equals("all")) continue;
|
||||
if (!server.equals(consoleServer) && !consoleServer.equals("all")) continue;
|
||||
|
||||
if (line.startsWith(prefix)) {
|
||||
final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DiscordPlugin {
|
||||
jda.getPresence().setPresence(Activity.playing(config.discord.statusMessage), false);
|
||||
|
||||
for (Bot bot : Main.bots) {
|
||||
final String channelId = servers.get(bot.host + ":" + bot.port);
|
||||
final String channelId = servers.get(bot.getServerString());
|
||||
|
||||
totalConnects.put(channelId, 0); // is this necessary?
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class GrepLogPlugin {
|
||||
|
||||
if (matches == 0) throw new CommandException(Component.text("No matches has been found"));
|
||||
|
||||
final String channelId = bot.discord.servers.get(bot.host + ":" + bot.port);
|
||||
final String channelId = bot.discord.servers.get(bot.getServerString());
|
||||
final TextChannel logChannel = bot.discord.jda.getTextChannelById(channelId);
|
||||
|
||||
if (logChannel == null) return;
|
||||
|
||||
@@ -209,7 +209,7 @@ public class IRCPlugin extends ListenerAdapter {
|
||||
}
|
||||
|
||||
private void addMessageToQueue (Bot bot, String message) {
|
||||
final String channel = servers.get(bot.host + ":" + bot.port);
|
||||
final String channel = servers.get(bot.getServerString());
|
||||
|
||||
addMessageToQueue(channel, message);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public class IRCPlugin extends ListenerAdapter {
|
||||
}
|
||||
|
||||
public void sendMessage (Bot bot, String message) {
|
||||
final String hostAndPort = bot.host + ":" + bot.port;
|
||||
final String hostAndPort = bot.getServerString();
|
||||
|
||||
final String channel = servers.get(hostAndPort);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class LoggerPlugin extends ChatPlugin.Listener {
|
||||
|
||||
final Component reason = event.getReason();
|
||||
|
||||
final String message = "Disconnected from " + bot.host + ":" + bot.port + ", reason: ";
|
||||
final String message = "Disconnected from " + bot.getServerString() + ", reason: ";
|
||||
|
||||
final String string = ComponentUtilities.stringify(reason);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
|
||||
} else {
|
||||
statement = bot.database.connection.prepareStatement(FIND_ALTS_SINGLE_SERVER);
|
||||
|
||||
statement.setString(1, bot.host + ":" + bot.port);
|
||||
statement.setString(1, bot.getServerString());
|
||||
statement.setString(2, ip);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
|
||||
updatePlayerStatement.setString(2, "$.ips");
|
||||
|
||||
final ObjectNode ipsObject = JsonNodeFactory.instance.objectNode();
|
||||
ipsObject.put(bot.host + ":" + bot.port, output);
|
||||
ipsObject.put(bot.getServerString(), output);
|
||||
|
||||
updatePlayerStatement.setString(3, objectMapper.writeValueAsString(ipsObject));
|
||||
|
||||
@@ -186,7 +186,7 @@ public class PlayersDatabasePlugin extends PlayersPlugin.Listener {
|
||||
final ObjectNode object = JsonNodeFactory.instance.objectNode();
|
||||
|
||||
object.put("time", Instant.now().toEpochMilli());
|
||||
object.put("server", bot.host + ":" + bot.port);
|
||||
object.put("server", bot.getServerString());
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class PlayersPlugin extends Bot.Listener {
|
||||
|
||||
if (ipsObject == null || ipsObject.isNull() || !ipsObject.isObject()) return null;
|
||||
|
||||
final JsonNode targetIP = ipsObject.get(bot.host + ":" + bot.port);
|
||||
final JsonNode targetIP = ipsObject.get(bot.getServerString());
|
||||
|
||||
if (targetIP == null || targetIP.isNull() || !targetIP.isTextual()) return null;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LoggerUtilities {
|
||||
final String formattedMessage = bot == null ? "" :
|
||||
String.format(
|
||||
"[%s] %s",
|
||||
bot.host + ":" + bot.port,
|
||||
bot.getServerString(),
|
||||
message
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user