Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow matching nicks via regexp #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions msg_to_notice.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
changed => '2013-04-24T17:40+0200',
);

# HOWTO:
#
# /load msg_to_notice.pl
# /set noticeable_nicks ~\[bot\]$,~mon-[0-9]+$,~^mon-.*-[0-9]+$,root,deploy,log,jenkins,nagmetoo
#
# The nicks that match will be turned into notices, useful for marking
# bots as such. Note that if the nicks start with ~ the rest is taken
# to be a regex. Due to limitations of our dummy parser you can't use
# {x,y} character classes or other regex constructs that require a
# comma, but usually that's something you can work around.

use constant {
I_SERVER => 0,
I_DATA => 1,
Expand All @@ -31,8 +42,15 @@ sub handle_privmsg {
for my $noticeable_nick ( split /[\s,]+/, Irssi::settings_get_str('noticeable_nicks') ) {
$noticeable_nick =~ s/\A \s+//x;
$noticeable_nick =~ s/\s+ \z//x;
my $is_regexp; $is_regexp = 1 if $noticeable_nick =~ s/^~//;

if ( lc $noticeable_nick eq lc $_[I_NICK] ){
# Irssi::print("Checking <$_[I_NICK]> to <$noticeable_nick> via <" . ($is_regexp ? "rx" : "eq") . ">");
if ( $is_regexp and $_[I_NICK] =~ $noticeable_nick ) {
# Irssi::print("Matched <$_[I_NICK]> to <$noticeable_nick> via <rx>");
$is_noticeable = 1;
last;
} elsif ( not $is_regexp and lc $noticeable_nick eq lc $_[I_NICK] ){
# Irssi::print("Matched <$_[I_NICK]> to <$noticeable_nick> via <eq>");
$is_noticeable = 1;
last;
}
Expand All @@ -43,7 +61,7 @@ sub handle_privmsg {
Irssi::signal_stop();
}

Irssi::settings_add_str('msg_to_notice', 'noticeable_nicks', 'root,deploy');
Irssi::settings_add_str('msg_to_notice', 'noticeable_nicks', '~\[bot\]$,root,deploy');
Irssi::signal_add('event privmsg', 'handle_privmsg');

# vim: filetype=perl tabstop=4 shiftwidth=4 expandtab cindent: