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;
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
final String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
if (!isCommandSuggestions) listener.systemMessageReceived(component);
|
||||
listener.systemMessageReceived(component, isCommandSuggestions);
|
||||
if (string.length() < 25_000) {
|
||||
if (!isCommandSuggestions) listener.systemMessageReceived(component, string, ansi);
|
||||
listener.systemMessageReceived(component, isCommandSuggestions, string, ansi);
|
||||
}
|
||||
|
||||
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
||||
}
|
||||
|
@ -131,13 +136,20 @@ public class ChatPlugin extends Bot.Listener {
|
|||
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) {
|
||||
listener.playerMessageReceived(playerMessage);
|
||||
|
||||
final Component unsignedContent = packet.getUnsignedContent();
|
||||
|
||||
final String translation = getTranslationByChatType(packet.getChatType());
|
||||
|
||||
if (translation != null && unsignedContent == null) {
|
||||
TranslatableComponent component = Component.translatable(translation);
|
||||
|
||||
|
@ -151,9 +163,13 @@ public class ChatPlugin extends Bot.Listener {
|
|||
component = component.args(playerMessage.displayName, playerMessage.contents);
|
||||
}
|
||||
|
||||
listener.systemMessageReceived(component);
|
||||
if (string.length() > 25_000) continue;
|
||||
|
||||
listener.systemMessageReceived(component, string, ansi);
|
||||
} 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);
|
||||
}
|
||||
|
||||
final String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
for (Listener listener : listeners) {
|
||||
listener.systemMessageReceived(translatableComponent);
|
||||
listener.systemMessageReceived(translatableComponent, string, ansi);
|
||||
}
|
||||
|
||||
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 String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
listener.playerMessageReceived(playerMessage);
|
||||
listener.systemMessageReceived(component);
|
||||
|
||||
if (string.length() > 25_000) continue;
|
||||
|
||||
listener.systemMessageReceived(component, string, ansi);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -325,7 +349,7 @@ public class ChatPlugin extends Bot.Listener {
|
|||
|
||||
public static class Listener {
|
||||
public void playerMessageReceived (PlayerMessage message) {}
|
||||
public void systemMessageReceived (Component component) {}
|
||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions) {}
|
||||
public void systemMessageReceived (Component component, String string, String ansi) {}
|
||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CommandSpyPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component) {
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
TextComponent textComponent;
|
||||
|
||||
try {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions) {
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) {
|
||||
if (!isCommandSuggestions) return;
|
||||
|
||||
try {
|
||||
|
|
|
@ -59,9 +59,20 @@ public class DiscordPlugin {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived (Component component) {
|
||||
final String content = ComponentUtilities.stringifyAnsi(component);
|
||||
sendMessage(CodeBlockUtilities.escape(content.replace("\u001b[9", "\u001b[3")), channelId);
|
||||
public void systemMessageReceived (Component component, String string, String ansi) {
|
||||
if (string.length() > 2048) {
|
||||
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
|
||||
public void systemMessageReceived(Component component) {
|
||||
final String stringMessage = ComponentUtilities.stringify(component);
|
||||
final String ansiMessage = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
log(ansiMessage, false, logToConsole);
|
||||
log(stringMessage, true, false);
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
log(ansi, false, logToConsole);
|
||||
log(string, true, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.Configuration;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
||||
|
@ -47,31 +46,29 @@ public class SelfCarePlugin extends Bot.Listener {
|
|||
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived(Component component) {
|
||||
final String message = ComponentUtilities.stringify(component);
|
||||
public void systemMessageReceived(Component component, String string, String ansi) {
|
||||
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 (message.equals("Successfully disabled CommandSpy")) cspy = false;
|
||||
else if (string.equals("Vanish for " + bot.username + ": enabled")) vanish = true;
|
||||
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 (message.equals("You are now completely invisible to normal users, and hidden from in-game commands.")) vanish = true;
|
||||
else if (message.equals("Vanish for " + bot.username + ": disabled")) vanish = false;
|
||||
else if (string.equals("You no longer have a nickname.")) nickname = true;
|
||||
else if (string.startsWith("Your nickname is now ")) nickname = false;
|
||||
|
||||
else if (message.equals("You no longer have a nickname.")) nickname = true;
|
||||
else if (message.startsWith("Your nickname is now ")) nickname = false;
|
||||
else if (string.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true;
|
||||
else if (string.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false;
|
||||
|
||||
else if (message.equals("SocialSpy for " + bot.username + ": enabled")) socialspy = true;
|
||||
else if (message.equals("SocialSpy for " + bot.username + ": disabled")) socialspy = false;
|
||||
else if (string.startsWith("You have been muted")) muted = true;
|
||||
else if (string.equals("You have been unmuted.")) muted = false;
|
||||
|
||||
else if (message.startsWith("You have been muted")) muted = true;
|
||||
else if (message.equals("You have been unmuted.")) muted = false;
|
||||
else if (string.equals("You now have the tag: " + bot.config.selfCare.prefix.prefix)) prefix = true;
|
||||
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 (message.startsWith("You no longer have a tag")) prefix = 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;
|
||||
else if (string.equals("Successfully set your username to \"" + bot.username + "\"")) username = true;
|
||||
else if (string.startsWith("Successfully set your username to \"")) username = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue