forked from ChomeNS/chomens-bot-java
one of the worst fix owo
This commit is contained in:
parent
cb5c8721d7
commit
46673f3dac
6 changed files with 72 additions and 43 deletions
|
@ -92,9 +92,14 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true;
|
if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true;
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
|
final String string = ComponentUtilities.stringify(component);
|
||||||
|
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||||
|
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
if (!isCommandSuggestions) listener.systemMessageReceived(component);
|
if (string.length() < 25_000) {
|
||||||
listener.systemMessageReceived(component, isCommandSuggestions);
|
if (!isCommandSuggestions) listener.systemMessageReceived(component, string, ansi);
|
||||||
|
listener.systemMessageReceived(component, isCommandSuggestions, string, ansi);
|
||||||
|
}
|
||||||
|
|
||||||
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
||||||
}
|
}
|
||||||
|
@ -131,13 +136,20 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
Component.text(packet.getContent())
|
Component.text(packet.getContent())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final Component unsignedContent = packet.getUnsignedContent();
|
||||||
|
|
||||||
|
final String translation = getTranslationByChatType(packet.getChatType());
|
||||||
|
|
||||||
|
String string = null;
|
||||||
|
String ansi = null;
|
||||||
|
if (translation != null && unsignedContent != null) {
|
||||||
|
string = ComponentUtilities.stringify(unsignedContent);
|
||||||
|
ansi = ComponentUtilities.stringifyAnsi(unsignedContent);
|
||||||
|
}
|
||||||
|
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.playerMessageReceived(playerMessage);
|
listener.playerMessageReceived(playerMessage);
|
||||||
|
|
||||||
final Component unsignedContent = packet.getUnsignedContent();
|
|
||||||
|
|
||||||
final String translation = getTranslationByChatType(packet.getChatType());
|
|
||||||
|
|
||||||
if (translation != null && unsignedContent == null) {
|
if (translation != null && unsignedContent == null) {
|
||||||
TranslatableComponent component = Component.translatable(translation);
|
TranslatableComponent component = Component.translatable(translation);
|
||||||
|
|
||||||
|
@ -151,9 +163,13 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
component = component.args(playerMessage.displayName, playerMessage.contents);
|
component = component.args(playerMessage.displayName, playerMessage.contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.systemMessageReceived(component);
|
if (string.length() > 25_000) continue;
|
||||||
|
|
||||||
|
listener.systemMessageReceived(component, string, ansi);
|
||||||
} else {
|
} else {
|
||||||
listener.systemMessageReceived(unsignedContent);
|
if (string.length() > 25_000) continue;
|
||||||
|
|
||||||
|
listener.systemMessageReceived(unsignedContent, string, ansi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,8 +203,10 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
translatableComponent = translatableComponent.args(name, content);
|
translatableComponent = translatableComponent.args(name, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String string = ComponentUtilities.stringify(component);
|
||||||
|
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.systemMessageReceived(translatableComponent);
|
listener.systemMessageReceived(translatableComponent, string, ansi);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ChatParser parser : chatParsers) {
|
for (ChatParser parser : chatParsers) {
|
||||||
|
@ -207,9 +225,15 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
|
|
||||||
final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender, packet.getName(), parsedFromMessage.contents);
|
final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender, packet.getName(), parsedFromMessage.contents);
|
||||||
|
|
||||||
|
final String string = ComponentUtilities.stringify(component);
|
||||||
|
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||||
|
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
listener.playerMessageReceived(playerMessage);
|
listener.playerMessageReceived(playerMessage);
|
||||||
listener.systemMessageReceived(component);
|
|
||||||
|
if (string.length() > 25_000) continue;
|
||||||
|
|
||||||
|
listener.systemMessageReceived(component, string, ansi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -325,7 +349,7 @@ public class ChatPlugin extends Bot.Listener {
|
||||||
|
|
||||||
public static class Listener {
|
public static class Listener {
|
||||||
public void playerMessageReceived (PlayerMessage message) {}
|
public void playerMessageReceived (PlayerMessage message) {}
|
||||||
public void systemMessageReceived (Component component) {}
|
public void systemMessageReceived (Component component, String string, String ansi) {}
|
||||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions) {}
|
public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class CommandSpyPlugin extends ChatPlugin.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void systemMessageReceived(Component component) {
|
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||||
TextComponent textComponent;
|
TextComponent textComponent;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions) {
|
public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) {
|
||||||
if (!isCommandSuggestions) return;
|
if (!isCommandSuggestions) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -59,9 +59,20 @@ public class DiscordPlugin {
|
||||||
|
|
||||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void systemMessageReceived (Component component) {
|
public void systemMessageReceived (Component component, String string, String ansi) {
|
||||||
final String content = ComponentUtilities.stringifyAnsi(component);
|
if (string.length() > 2048) {
|
||||||
sendMessage(CodeBlockUtilities.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
|
sendMessage(CodeBlockUtilities.escape(string), channelId);
|
||||||
|
} else {
|
||||||
|
sendMessage(
|
||||||
|
CodeBlockUtilities.escape(
|
||||||
|
ansi
|
||||||
|
.replace(
|
||||||
|
"\u001b[9", "\u001b[3"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
channelId
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,11 +78,8 @@ public class LoggerPlugin extends ChatPlugin.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void systemMessageReceived(Component component) {
|
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||||
final String stringMessage = ComponentUtilities.stringify(component);
|
log(ansi, false, logToConsole);
|
||||||
final String ansiMessage = ComponentUtilities.stringifyAnsi(component);
|
log(string, true, false);
|
||||||
|
|
||||||
log(ansiMessage, false, logToConsole);
|
|
||||||
log(stringMessage, true, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
import land.chipmunk.chayapak.chomens_bot.Configuration;
|
import land.chipmunk.chayapak.chomens_bot.Configuration;
|
||||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
|
|
||||||
|
@ -47,31 +46,29 @@ public class SelfCarePlugin extends Bot.Listener {
|
||||||
|
|
||||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void systemMessageReceived(Component component) {
|
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||||
final String message = ComponentUtilities.stringify(component);
|
if (string.equals("Successfully enabled CommandSpy")) cspy = true;
|
||||||
|
else if (string.equals("Successfully disabled CommandSpy")) cspy = false;
|
||||||
|
|
||||||
if (message.equals("Successfully enabled CommandSpy")) cspy = true;
|
else if (string.equals("Vanish for " + bot.username + ": enabled")) vanish = true;
|
||||||
else if (message.equals("Successfully disabled CommandSpy")) cspy = false;
|
else if (string.equals("You are now completely invisible to normal users, and hidden from in-game commands.")) vanish = true;
|
||||||
|
else if (string.equals("Vanish for " + bot.username + ": disabled")) vanish = false;
|
||||||
|
|
||||||
else if (message.equals("Vanish for " + bot.username + ": enabled")) vanish = true;
|
else if (string.equals("You no longer have a nickname.")) nickname = true;
|
||||||
else if (message.equals("You are now completely invisible to normal users, and hidden from in-game commands.")) vanish = true;
|
else if (string.startsWith("Your nickname is now ")) nickname = false;
|
||||||
else if (message.equals("Vanish for " + bot.username + ": disabled")) vanish = false;
|
|
||||||
|
|
||||||
else if (message.equals("You no longer have a nickname.")) nickname = true;
|
else if (string.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true;
|
||||||
else if (message.startsWith("Your nickname is now ")) nickname = false;
|
else if (string.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false;
|
||||||
|
|
||||||
else if (message.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true;
|
else if (string.startsWith("You have been muted")) muted = true;
|
||||||
else if (message.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false;
|
else if (string.equals("You have been unmuted.")) muted = false;
|
||||||
|
|
||||||
else if (message.startsWith("You have been muted")) muted = true;
|
else if (string.equals("You now have the tag: " + bot.config.selfCare.prefix.prefix)) prefix = true;
|
||||||
else if (message.equals("You have been unmuted.")) muted = false;
|
else if (string.startsWith("You no longer have a tag")) prefix = false;
|
||||||
|
else if (string.startsWith("You now have the tag: ")) prefix = false;
|
||||||
|
|
||||||
else if (message.equals("You now have the tag: " + bot.config.selfCare.prefix.prefix)) prefix = true;
|
else if (string.equals("Successfully set your username to \"" + bot.username + "\"")) username = true;
|
||||||
else if (message.startsWith("You no longer have a tag")) prefix = false;
|
else if (string.startsWith("Successfully set your username to \"")) username = false;
|
||||||
else if (message.startsWith("You now have the tag: ")) prefix = false;
|
|
||||||
|
|
||||||
else if (message.equals("Successfully set your username to \"" + bot.username + "\"")) username = true;
|
|
||||||
else if (message.startsWith("Successfully set your username to \"")) username = false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue