Add zero-width-space option for bots.

This commit is contained in:
cnaude 2015-11-06 15:08:22 -07:00
parent cf7197ccd4
commit 8ec2a46c0a
4 changed files with 36 additions and 4 deletions

View File

@ -16,10 +16,13 @@
*/ */
package com.cnaude.purpleirc; package com.cnaude.purpleirc;
import java.util.ArrayList;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import org.pircbotx.Channel;
import org.pircbotx.User;
/** /**
* *
@ -62,14 +65,14 @@ public class IRCMessageQueueWatcher {
if (ircMessage != null) { if (ircMessage != null) {
plugin.logDebug("[" + queue.size() + "]: queueAndSend message detected"); plugin.logDebug("[" + queue.size() + "]: queueAndSend message detected");
for (String s : cleanupAndSplitMessage(ircMessage.message)) { for (String s : cleanupAndSplitMessage(ircMessage.message)) {
if (ircMessage.ctcpResponse) { if (ircMessage.ctcpResponse) {
blockingCTCPMessage(ircMessage.target, s); blockingCTCPMessage(ircMessage.target, s);
} else { } else {
blockingIRCMessage(ircMessage.target, s); blockingIRCMessage(ircMessage.target, s);
}
} }
} }
} }
}
private void blockingIRCMessage(final String target, final String message) { private void blockingIRCMessage(final String target, final String message) {
if (!ircBot.isConnected()) { if (!ircBot.isConnected()) {
@ -89,7 +92,31 @@ public class IRCMessageQueueWatcher {
plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message); plugin.logDebug("[blockingCTCPMessage] Message sent to " + target + ": " + message);
} }
private String addZeroWidthSpace(String s) {
if (s.length() > 1) {
String a = s.substring(0, 1);
String b = s.substring(1);
return a + "\u200B" + b;
}
return s;
}
private String pingFix(String message) {
for (Channel channel : ircBot.bot.getUserBot().getChannels()) {
for (User user : channel.getUsers()) {
if (message.toLowerCase().contains(user.getNick().toLowerCase())) {
message = message.replaceAll("(?i)" + user.getNick(), addZeroWidthSpace(user.getNick()));
plugin.logDebug("Adding ZWS to " + user.getNick());
}
}
}
return message;
}
private String[] cleanupAndSplitMessage(String message) { private String[] cleanupAndSplitMessage(String message) {
if (ircBot.pingFix) {
message = pingFix(message);
}
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF); return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);
} }

View File

@ -98,6 +98,7 @@ public final class PurpleBot {
public boolean channelCmdNotifyEnabled; public boolean channelCmdNotifyEnabled;
public boolean relayPrivateChat; public boolean relayPrivateChat;
public boolean partInvalidChannels; public boolean partInvalidChannels;
public boolean pingFix;
public int botServerPort; public int botServerPort;
public long chatDelay; public long chatDelay;
public String botServer; public String botServer;
@ -667,6 +668,7 @@ public final class PurpleBot {
rawMessage = config.getString("raw-message", ""); rawMessage = config.getString("raw-message", "");
relayPrivateChat = config.getBoolean("relay-private-chat", false); relayPrivateChat = config.getBoolean("relay-private-chat", false);
partInvalidChannels = config.getBoolean("part-invalid-channels", false); partInvalidChannels = config.getBoolean("part-invalid-channels", false);
pingFix = config.getBoolean("zero-width-space", false);
partInvalidChannelsMsg = config.getString("part-invalid-channels-message", ""); partInvalidChannelsMsg = config.getString("part-invalid-channels-message", "");
nick = config.getString("nick", ""); nick = config.getString("nick", "");
botNick = nick; botNick = nick;

View File

@ -653,7 +653,7 @@ public class ChatTokenizer {
String displayName = player.getDisplayName(); String displayName = player.getDisplayName();
String playerIP = ""; String playerIP = "";
try { try {
player.getAddress().getAddress().getHostAddress(); playerIP = player.getAddress().getAddress().getHostAddress();
} catch (Exception ex) { } catch (Exception ex) {
plugin.logDebug(ex.getMessage()); plugin.logDebug(ex.getMessage());
} }
@ -873,6 +873,7 @@ public class ChatTokenizer {
/** /**
* *
* @param sender
* @param targetPlayer * @param targetPlayer
* @param message * @param message
* @param template * @param template

View File

@ -80,6 +80,8 @@ flood-control:
part-invalid-channels: false part-invalid-channels: false
# Message when leaving invalid channel # Message when leaving invalid channel
part-invalid-channels-message: 'I should not be here! Bye!' part-invalid-channels-message: 'I should not be here! Bye!'
# Insert zero width space into nicks of IRC output to prevent client pings
zero-width-space: false
# Channel auto join delay in server ticks (20 ticks = 1 second) # Channel auto join delay in server ticks (20 ticks = 1 second)
channel-auto-join-delay: 20 channel-auto-join-delay: 20
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them. # If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.