summaryrefslogtreecommitdiffstats
path: root/scripts/msg2notice_regex.pl
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason2016-03-15 17:52:13 +0000
committerÆvar Arnfjörð Bjarmason2016-03-16 11:07:11 +0000
commita098b519551471f4ef84f4c942b57fe9e640ab5d (patch)
treebbf9abca036bdd37664b67284c8a7b40628034b2 /scripts/msg2notice_regex.pl
parent5dbfd9f54b6dbc114458ea02bbb1a75e1f447302 (diff)
downloadscripts.irssi.org-a098b519551471f4ef84f4c942b57fe9e640ab5d.tar.bz2
Submit my collection of scripts from my dotfiles.git
These are all irssi scripts that I maintain & use myself that I think are useful for general use, none of this has anything hardcoded related to me and when applicable has a configurable interface.
Diffstat (limited to 'scripts/msg2notice_regex.pl')
-rw-r--r--scripts/msg2notice_regex.pl56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/msg2notice_regex.pl b/scripts/msg2notice_regex.pl
new file mode 100644
index 0000000..9ecedf6
--- /dev/null
+++ b/scripts/msg2notice_regex.pl
@@ -0,0 +1,56 @@
+use strict;
+use warnings;
+use Irssi;
+
+our $VERSION = '1.0';
+our %IRSSI = (
+ authors => 'Fernando Vezzosi & Ævar Arnfjörð Bjarmason',
+ contact => 'irssi@repnz.net & avarab@gmail.com',
+ name => 'msg2notice_regex.pl',
+ description => 'For a configured list of nicks or nicks matching a regex, convert all their messages to a notices',
+ license => 'Public Domain',
+ url => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/msg2notice_regex.pl & https://github.com/bucciarati/irssi-script-msg_to_notice',
+);
+
+# HOWTO:
+#
+# /load msg2notice_regex.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.
+
+sub privmsg_msg2notice_regex {
+ use Data::Dumper;
+ my ($server, $data, $nick, $nick_and_address) = @_;
+ my ($target, $message) = split /:/, $data, 2;
+
+ # Irssi::print("server<$server> data<$data>[$target:$message] nick<$nick> mask<$nick_and_address>");
+ my $is_noticeable = 0;
+ 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/^~//;
+
+ # Irssi::print("Checking <$nick> to <$noticeable_nick> via <" . ($is_regexp ? "rx" : "eq") . ">");
+ if ( $is_regexp and $nick =~ $noticeable_nick ) {
+ # Irssi::print("Matched <$nick> to <$noticeable_nick> via <rx>");
+ $is_noticeable = 1;
+ last;
+ } elsif ( not $is_regexp and lc $noticeable_nick eq lc $nick ){
+ # Irssi::print("Matched <$nick> to <$noticeable_nick> via <eq>");
+ $is_noticeable = 1;
+ last;
+ }
+ }
+ return unless $is_noticeable;
+
+ Irssi::signal_emit('event notice', $server, $data, $nick, $nick_and_address);
+ Irssi::signal_stop();
+}
+
+Irssi::settings_add_str('msg_to_notice', 'noticeable_nicks', '~\[bot\]$,root,deploy');
+Irssi::signal_add('event privmsg', 'privmsg_msg2notice_regex');