Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add zero-width-space option for bots.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Nov 6, 2015
1 parent b2ba872 commit ed203fe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/main/java/com/cnaude/purpleirc/IRCMessageQueueWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.pircbotx.Channel;
import org.pircbotx.User;

/**
*
Expand Down Expand Up @@ -89,7 +91,31 @@ private void blockingCTCPMessage(final String target, final String 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) {
if (ircBot.pingFix) {
message = pingFix(message);
}
return message.replaceAll(REGEX_CLEAN, "").replaceAll(REGEX_CRLF, "\n").split(LF);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public final class PurpleBot {
public boolean channelCmdNotifyEnabled;
public boolean relayPrivateChat;
public boolean partInvalidChannels;
public boolean pingFix;
public int botServerPort;
public long chatDelay;
public String botServer;
Expand Down Expand Up @@ -667,6 +668,7 @@ private boolean loadConfig() {
rawMessage = config.getString("raw-message", "");
relayPrivateChat = config.getBoolean("relay-private-chat", false);
partInvalidChannels = config.getBoolean("part-invalid-channels", false);
pingFix = config.getBoolean("zero-width-space", false);
partInvalidChannelsMsg = config.getString("part-invalid-channels-message", "");
nick = config.getString("nick", "");
botNick = nick;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public String playerTokenizer(Player player, String message) {
String displayName = player.getDisplayName();
String playerIP = "";
try {
player.getAddress().getAddress().getHostAddress();
playerIP = player.getAddress().getAddress().getHostAddress();
} catch (Exception ex) {
plugin.logDebug(ex.getMessage());
}
Expand Down Expand Up @@ -873,6 +873,7 @@ public String msgChatResponseTokenizer(String target, String message, String tem

/**
*
* @param sender
* @param targetPlayer
* @param message
* @param template
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/SampleBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ flood-control:
part-invalid-channels: false
# Message when leaving invalid channel
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: 20
# If your irc-chat message has a %CUSTOMPREFIX% then these custom prefixes can replace them.
Expand Down

0 comments on commit ed203fe

Please sign in to comment.