Skip to content

Instantly share code, notes, and snippets.

@LifeIsPain
Last active December 19, 2015 23:18
Show Gist options
  • Save LifeIsPain/6033564 to your computer and use it in GitHub Desktop.
Save LifeIsPain/6033564 to your computer and use it in GitHub Desktop.
XChat script to not highlight a line if it matches a pattern
# Name: highlightexceptions.pl
# Version: 002
# Author: LifeIsPain < idontlikespam (at) orvp [dot] net >
# Date: 2013-07-18
# Description: Do not highlight a line if it matches a pattern
# Version History
# 001 2013-07-18 Initial Version from nochannelhighlight
# 002 2013-07-18 Fixed case where special regex characters in nick
use strict;
use warnings;
use Xchat qw(register hook_server get_prefs command hook_timer KEEP REMOVE EAT_NONE);
# -------- CONFIGURATION --------
# List the phrases you wish to not highlight on, even if they include your nick. Accepts regular expressions, case insensitive
my @no_highlight = (
# Any line that starts with a string
'^Start of line',
'^<mynick>',
# Any line that ends with a string
'end of line.$',
# Any number that is at least a million
'\d,?\d\d\d,?\d\d\d',
);
register('Highlight Exceptions', '002', 'Don\'t highlight if message matches a pattern');
hook_server('PRIVMSG', \&no_chan_highlight);
sub no_chan_highlight {
my $message = $_[1][3];
$message =~ s/^://;
foreach (@no_highlight) {
if ($message =~ m/$_/i) {
my ($from) = $_[0][0] =~ m/^:([^!]+)/;
my $current_list = get_prefs('irc_no_hilight');
# perhaps the list is blank
unless ($current_list) {
command("set -quiet irc_no_hilight $from");
# unset after event has gone through
delaycommand("set -e -quiet irc_no_hilight");
}
# make sure the user isn't already in the list
elsif ($current_list !~ m/(?:^|,)\Q$from\E(?:$|,)/i) {
command("set -quiet irc_no_hilight $current_list,$from");
# after the event has gone through, set to original
delaycommand("set -quiet irc_no_hilight $current_list");
}
last;
}
}
return EAT_NONE;
}
# my favorite delaycommand sub, so stuff happens after the raw is totally processed
sub delaycommand {
my $command = $_[0];
hook_timer( 0,
sub {
command($command);
return REMOVE;
}
);
return EAT_NONE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment