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

Commit

Permalink
Added excludes option for file tailer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Dec 5, 2015
1 parent 4d19fce commit b5b137f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/main/java/com/cnaude/purpleirc/LogTailer.java
Expand Up @@ -92,21 +92,38 @@ public void handle(String line) {
} else {
okayToSend = true;
}
if (okayToSend) {
if (okayToSend && !excludesMatch(line)) {
String template = plugin.getMsgTemplate(ircBot.botNick, target, TemplateName.LOG_TAILER);
String message = plugin.tokenizer.logTailerTokenizer(file.getName(), line, template);
if (ctcp) {
blockingCTCPMessage(target, message);
} else {
blockingIRCMessage(target, message);
}
} else {
plugin.logDebug("[MyTailerListener] Can't send to " + target + " yet.");
}
}

}

private boolean excludesMatch(String message) {
if (!ircBot.tailerFilters.isEmpty()) {
for (String filter : ircBot.tailerFilters) {
if (filter.startsWith("/") && filter.endsWith("/")) {
filter = filter.substring(1, filter.length() - 1);
if (message.matches(filter)) {
return true;
}
} else {
plugin.logDebug("Filtering " + filter + " from " + message);
if (message.contains(filter)) {
return true;
}
}
}
}
return false;
}

private void blockingIRCMessage(final String target, final String message) {
if (!ircBot.isConnected()) {
return;
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -125,6 +125,7 @@ public final class PurpleBot {
public CaseInsensitiveMap<Collection<String>> tabIgnoreNicks;
public CaseInsensitiveMap<Boolean> tabIgnoreDuplicates;
public CaseInsensitiveMap<Collection<String>> filters;
public ArrayList<String> tailerFilters;
public CaseInsensitiveMap<String> channelPassword;
public CaseInsensitiveMap<String> channelTopic;
public CaseInsensitiveMap<Boolean> channelTopicChanserv;
Expand Down Expand Up @@ -245,6 +246,7 @@ public PurpleBot(File file, PurpleIRC plugin) {
this.tabIgnoreNicks = new CaseInsensitiveMap<>();
this.tabIgnoreDuplicates = new CaseInsensitiveMap<>();
this.filters = new CaseInsensitiveMap<>();
this.tailerFilters = new ArrayList<>();
this.channelNicks = new CaseInsensitiveMap<>();
this.channelTopicChanserv = new CaseInsensitiveMap<>();
this.joinMsg = new CaseInsensitiveMap<>();
Expand Down Expand Up @@ -759,6 +761,7 @@ private boolean loadConfig() {
commandMap.clear();
extraCommandMap.clear();
commandUsermasksMap.clear();
tailerFilters.clear();

channelCmdNotifyEnabled = config.getBoolean("command-notify.enabled", false);
plugin.logDebug(" CommandNotifyEnabled => " + channelCmdNotifyEnabled);
Expand Down Expand Up @@ -843,6 +846,17 @@ private boolean loadConfig() {
if (channelCmdNotifyIgnore.isEmpty()) {
plugin.logInfo(" No command-notify ignores defined.");
}

// build tailer filter list
for (String re : config.getStringList("file-tailer.excludes")) {
if (!tailerFilters.contains(re)) {
tailerFilters.add(re);
}
plugin.logDebug("Filtered from tailer => " + re);
}
if (tailerFilters.isEmpty()) {
plugin.logInfo("Tailer filter list is empty!");
}

if (config.getConfigurationSection("channels") == null) {
plugin.logError("No channels found!");
Expand Down Expand Up @@ -1021,7 +1035,7 @@ private boolean loadConfig() {
actionCommands.add("/me");
}

// build valid world list
// build message filter list
Collection<String> f = new ArrayList<>();
for (String word : config.getStringList("channels." + enChannelName + ".filter-list")) {
if (!f.contains(word)) {
Expand All @@ -1031,7 +1045,7 @@ private boolean loadConfig() {
}
filters.put(channelName, f);
if (filters.isEmpty()) {
plugin.logInfo("World list is empty!");
plugin.logInfo("Filter list is empty!");
}

// build join notice
Expand Down Expand Up @@ -2612,7 +2626,7 @@ public String filterMessage(String message, String channelName) {
}
return message;
}

// Broadcast chat messages from IRC to the game
/**
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -75,6 +75,10 @@ file-tailer:
extra_files: []
recipient: '#minecraft-test'
ctcp: false
# If a line matches then it is excluded from being sent to IRC.
# Place slashes around a pattern to use regular expressions.
excludes:
- '/\s+\[PurpleIRC\]\s+/'
# Messaging flood control (game and IRC)
flood-control:
# Enable or disable flood control
Expand Down

0 comments on commit b5b137f

Please sign in to comment.