Added excludes option for file tailer. #10

This commit is contained in:
cnaude 2015-12-04 22:17:47 -07:00
parent 5fab8c3dc9
commit 07361bc6e8
3 changed files with 41 additions and 6 deletions

View File

@ -92,7 +92,7 @@ public class LogTailer {
} 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) {
@ -100,13 +100,30 @@ public class LogTailer {
} 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;

View File

@ -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;
@ -245,6 +246,7 @@ public final class PurpleBot {
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<>();
@ -759,6 +761,7 @@ public final class PurpleBot {
commandMap.clear();
extraCommandMap.clear();
commandUsermasksMap.clear();
tailerFilters.clear();
channelCmdNotifyEnabled = config.getBoolean("command-notify.enabled", false);
plugin.logDebug(" CommandNotifyEnabled => " + channelCmdNotifyEnabled);
@ -843,6 +846,17 @@ public final class PurpleBot {
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!");
@ -1021,7 +1035,7 @@ public final class PurpleBot {
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)) {
@ -1031,7 +1045,7 @@ public final class PurpleBot {
}
filters.put(channelName, f);
if (filters.isEmpty()) {
plugin.logInfo("World list is empty!");
plugin.logInfo("Filter list is empty!");
}
// build join notice
@ -2612,7 +2626,7 @@ public final class PurpleBot {
}
return message;
}
// Broadcast chat messages from IRC to the game
/**
*

View File

@ -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