User:Mike.lifeguard/stalkwords.pl
From Meta, a Wikimedia project coordination wiki
use strict; use warnings; use Xchat qw( :all ); my $name = 'Regex stalkwords'; my $version = '1.1'; my $description = 'Regex stalkwords'; Xchat::register($name, $version, $description); Xchat::print("Loading $name $version: $description"); foreach ('Channel Message', 'Channel Action') { hook_print($_, \&channel_highlight, {priority => PRI_HIGHEST, data => $_}); } my $highlight = qr/\b(?:one|two|three)\b/i; # These are normal-ish stalkwords my $stalkwords = qr/!(four|five|six)\b/i; # For !admin@mywiki or whatever sub channel_highlight { if (defined get_info('away')) {return EAT_NONE;} # Don't highlight if we're away my $event = $_[1]; my $nick = $_[0][0]; my $msg = ($_[0][1] ? strip_code($_[0][1]) : ''); # We override colours etc because it's a highlight (and that can mess up matching) # If $_[0][1] is undefined, use a zero-length string for safety $_[0][1] = ($_[0][1] ? strip_code($_[0][1]) : ''); # We also want to strip it from the value in the array, for display purposes if (get_prefs('irc_no_hilight') ne ''){ my $ignored = '(?:' . get_prefs('irc_no_hilight') . ')'; # Grabs your pref for who not to highlight, and excludes them $ignored =~ s/,/\|/g; $ignored = qr/$ignored/; if (($nick !~ m/$ignored/) and (($msg =~ $highlight) || ($msg =~ $stalkwords))) { if ($event eq 'Channel Message') {$event = 'Channel Msg Hilight';} else {$event = 'Channel Action Hilight';} emit_print($event, @{$_[0]}); command('gui color 3'); # Change the tab colour return EAT_XCHAT; } return EAT_NONE; } else { if (($msg =~ $highlight) || ($msg =~ $stalkwords)) { if ($event eq 'Channel Message') {$event = 'Channel Msg Hilight';} else {$event = 'Channel Action Hilight';} emit_print($event, @{$_[0]}); command('gui color 3'); # Change the tab colour return EAT_XCHAT; } return EAT_NONE; } }