summaryrefslogtreecommitdiffstats
path: root/scripts/trigger.pl
diff options
context:
space:
mode:
authorWouter Coekaerts2015-11-07 14:03:17 -0300
committerdequis2015-11-07 14:04:14 -0300
commitae8b7a06e6b199923c5ff0c194891a924bf35015 (patch)
tree56fb82c9a0321e3a47b5633dc13d6bc3d1db1594 /scripts/trigger.pl
parent1d7f4a7a4996ba53d4041b34f7d74ae6a16eebba (diff)
downloadscripts.irssi.org-ae8b7a06e6b199923c5ff0c194891a924bf35015.tar.bz2
trigger.pl: Update to '1.0+'
Diffstat (limited to 'scripts/trigger.pl')
-rw-r--r--scripts/trigger.pl131
1 files changed, 77 insertions, 54 deletions
diff --git a/scripts/trigger.pl b/scripts/trigger.pl
index 02f8951..6b88cbd 100644
--- a/scripts/trigger.pl
+++ b/scripts/trigger.pl
@@ -1,7 +1,7 @@
# trigger.pl - execute a command or replace text, triggered by an event in irssi
# Do /TRIGGER HELP or look at http://wouter.coekaerts.be/irssi/ for help
-# Copyright (C) 2002-2006 Wouter Coekaerts <wouter@coekaerts.be>
+# Copyright (C) 2002-2010 Wouter Coekaerts <wouter@coekaerts.be>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@ use Text::ParseWords;
use IO::File;
use vars qw($VERSION %IRSSI);
-$VERSION = '1.0';
+$VERSION = '1.0+';
%IRSSI = (
authors => 'Wouter Coekaerts',
contact => 'wouter@coekaerts.be',
@@ -31,7 +31,7 @@ $VERSION = '1.0';
description => 'execute a command or replace text, triggered by an event in irssi',
license => 'GPLv2 or later',
url => 'http://wouter.coekaerts.be/irssi/',
- changed => '$LastChangedDate: 2006-01-23 13:10:19 +0100 (Mon, 23 Jan 2006) $',
+ changed => '$LastChangedDate: 2009-02-07 21:35:47 +0100 (Sat, 07 Feb 2009) $',
);
sub cmd_help {
@@ -45,11 +45,11 @@ TRIGGER DELETE <number>
TRIGGER CHANGE <number> ...
TRIGGER ADD ...
-When to match:
-On which types of event to trigger:
+%U%_When to match%_%U
+%UOn which types of event to trigger%U
These are simply specified by -name_of_the_type
The normal IRC event types are:
- publics, %|privmsgs, pubactions, privactions, pubnotices, privnotices, joins, parts, quits, kicks, topics, invites, nick_changes, dcc_msgs, dcc_actions, dcc_ctcps
+ publics, %|privmsgs, (pub|priv)actions, (pub|priv)notices, (pub|priv)ctcps, (pub|priv)ctcpreplies, joins, parts, quits, kicks, topics, invites, nick_changes, dcc_msgs, dcc_actions, dcc_ctcps
mode_channel: %|a mode on the (whole) channel (like +t, +i, +b)
mode_nick: %|a mode on someone in the channel (like +o, +v)
-all is an alias for all of those.
@@ -63,9 +63,11 @@ On which types of event to trigger:
notify_away: %|someone in your notify list goes away
notify_unaway: %|someone in your notify list goes unaway
notify_unidle: %|someone in your notify list stops idling
+ (pub|priv)flood: %|flood in a channel or in private detected. See /set flood. Be careful, these flood signals can trigger many times for one flood (unless you have autoignore enabled)
-Filters (conditions) the event has to satisfy. They all take one parameter.
-If you can give a list, seperate elements by space and use quotes around the list.
+%UFilters (conditions) the event has to satisfy%U
+They all take one parameter. If you can give a list, seperate elements by space and use quotes around the list.
+All filters except for -pattern and -regexp can also be inversed by prefixing with -not_.
-pattern: %|The message must match the given pattern. ? and * can be used as wildcards
-regexp: %|The message must match the given regexp. (see man perlre)
%|if -nocase is given as an option, the regexp or pattern is matched case insensitive
@@ -76,15 +78,15 @@ If you can give a list, seperate elements by space and use quotes around the lis
-masks: %|The person who triggers it must match one of the given list of masks
-hasmode: %|The person who triggers it must have the give mode
Examples: %|'-o' means not opped, '+ov' means opped OR voiced, '-o&-v' means not opped AND not voiced
- -hasflag: %|Only trigger if if friends.pl (friends_shasta.pl) or people.pl is loaded and the person who triggers it has the given flag in the script (same syntax as -hasmode)
+ -hasflag: %|Only trigger if friends.pl (friends_shasta.pl) or people.pl is loaded and the person who triggers it has the given flag in the script (same syntax as -hasmode)
-other_masks
-other_hasmode
-other_hasflag: %|Same as above but for the victim for kicks or mode_nick.
-What to do when it matches:
+%U%_What to do when it matches%_%U
-command: Execute the given Irssi-command
%|You are able to use $1, $2 and so on generated by your regexp pattern.
- %|For multiple commands ; (or $;) can be used as seperator
+ %|For multiple commands ; can be used as seperator
%|The following variables are also expanded:
$T: %|Server tag
$C: %|Channel name
@@ -98,42 +100,41 @@ What to do when it matches:
${mode_char}: %|The mode char ('o' for ops, 'b' for ban,...)
${mode_arg} : %|The argument to the mode (if there is one)
%|$\X, with X being one of the above expands (e.g. $\M), escapes all non-alphanumeric characters, so it can be used with /eval or /exec. Don't use /eval or /exec without this, it's not safe.
-
-replace: %|replaces the matching part with the given replacement in the event (requires a -regexp or -pattern)
-once: %|remove the trigger if it is triggered, so it only executes once and then is forgotten.
-stop: %|stops the signal. It won't get displayed by Irssi. Like /IGNORE
-debug: %|print some debugging info
-Other options:
+%U%_Other options%_%U
-disabled: %|Same as removing it, but keeps it in case you might need it later
-name: %|Give the trigger a name. You can refer to the trigger with this name in add/del/change commands
-Examples:
+%U%_Examples%_%U
Knockout people who do a !list:
- /TRIGGER ADD %|-publics -channels "#channel1 #channel2" -nocase -regexp ^!list -command "KN $N This is not a warez channel!"
+ %#/TRIGGER ADD %|-publics -channels "#channel1 #channel2" -nocase -regexp ^!list -command "KN $N This is not a warez channel!"
React to !echo commands from people who are +o in your friends-script:
- /TRIGGER ADD %|-publics -regexp '^!echo (.*)' -hasflag '+o' -command 'say echo: $1'
+ %#/TRIGGER ADD %|-publics -regexp '^!echo (.*)' -hasflag '+o' -command 'say echo: $1'
Ignore all non-ops on #channel:
- /TRIGGER ADD %|-publics -actions -channels "#channel" -hasmode '-o' -stop
+ %#/TRIGGER ADD %|-publics -actions -channels "#channel" -hasmode '-o' -stop
Send a mail to yourself every time a topic is changed:
- /TRIGGER ADD %|-topics -command 'exec echo $\N changed topic of $\C to: $\M | mail you@somewhere.com -s topic'
+ %#/TRIGGER ADD %|-topics -command 'exec echo $\N changed topic of $\C to: $\M | mail you@somewhere.com -s topic'
-Examples with -replace:
+%U%_Examples with -replace%_%U
%|Replace every occurence of shit with sh*t, case insensitive:
- /TRIGGER ADD %|-all -nocase -regexp shit -replace sh*t
+ %#/TRIGGER ADD %|-all -nocase -regexp shit -replace sh*t
%|Strip all colorcodes from *!lamer@*:
- /TRIGGER ADD %|-all -masks *!lamer@* -regexp '\x03\d?\d?(,\d\d?)?|\x02|\x1f|\x16|\x06' -replace ''
+ %#/TRIGGER ADD %|-all -masks *!lamer@* -regexp '\x03\d?\d?(,\d\d?)?|\x02|\x1f|\x16|\x06' -replace ''
%|Never let *!bot1@foo.bar or *!bot2@foo.bar hilight you
%|(this works by cutting your nick in 2 different parts, 'myn' and 'ick' here)
%|you don't need to understand the -replace argument, just trust that it works if the 2 parts separately don't hilight:
- /TRIGGER ADD %|-all masks '*!bot1@foo.bar *!bot2@foo.bar' -regexp '(myn)(ick)' -nocase -replace '$1\x02\x02$2'
+ %#/TRIGGER ADD %|-all masks '*!bot1@foo.bar *!bot2@foo.bar' -regexp '(myn)(ick)' -nocase -replace '$1\x02\x02$2'
%|Avoid being hilighted by !top10 in eggdrops with stats.mod (but show your nick in bold):
- /TRIGGER ADD %|-publics -regexp '(Top.0\(.*\): 1.*)(my)(nick)' -replace '$1\x02$2\x02\x02$3\x02'
+ %#/TRIGGER ADD %|-publics -regexp '(Top.0\(.*\): 1.*)(my)(nick)' -replace '$1\x02$2\x02\x02$3\x02'
%|Convert a Windows-1252 Euro to an ISO-8859-15 Euro (same effect as euro.pl):
- /TRIGGER ADD %|-regexp '\x80' -replace '\xA4'
+ %#/TRIGGER ADD %|-regexp '\x80' -replace '\xA4'
%|Show tabs as spaces, not the inverted I (same effect as tab_stop.pl):
- /TRIGGER ADD %|-all -regexp '\t' -replace ' '
+ %#/TRIGGER ADD %|-all -regexp '\t' -replace ' '
SCRIPTHELP_EOF
} # /
@@ -164,16 +165,16 @@ my @allchanmsg_types = qw(publics pubactions pubnotices pubctcps pubctcpreplies
# trigger types with a message
my @allmsg_types = (@allchanmsg_types, qw(privmsgs privactions privnotices privctcps privctcpreplies dcc_msgs dcc_actions dcc_ctcps));
# trigger types with a channel
-my @allchan_types = (@allchanmsg_types, qw(mode_channel mode_nick joins invites));
+my @allchan_types = (@allchanmsg_types, qw(mode_channel mode_nick joins invites pubflood));
# trigger types in -all
my @all_types = (@allmsg_types, qw(mode_channel mode_nick joins invites nick_changes));
# trigger types with a server
-my @all_server_types = (@all_types, qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle));
+my @all_server_types = (@all_types, qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle pubflood privflood));
# all trigger types
my @trigger_types = (@all_server_types, qw(send_command send_text beep));
#trigger types that are not in -all
#my @notall_types = grep {my $a=$_; return (!grep {$_ eq $a} @all_types);} @trigger_types;
-my @notall_types = qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle send_command send_text beep);
+my @notall_types = qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle send_command send_text beep pubflood privflood);
my @signals = (
# "message public", SERVER_REC, char *msg, char *nick, char *address, char *target
@@ -376,9 +377,22 @@ my @signals = (
'sub' => sub {
my ($server, $args, $nick, $addr, $target) = @_;
if ($target eq $server->{'nick'}) {
- check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcps');
+ check_signal_message(\@_, 1, $server, undef, $nick, $addr, 'privctcpreplies');
} else {
- check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcps');
+ check_signal_message(\@_, 1, $server, $target, $nick, $addr, 'pubctcpreplies');
+ }
+ }
+},
+# "flood", SERVER_REC, char *nick, char *host, int level, char *target
+{
+ 'types' => ['pubflood', 'privflood'],
+ 'signal' => 'flood',
+ 'sub' => sub {
+ my ($server, $nick, $host, $level, $target) = @_;
+ if ($target eq $server->{'nick'}) {
+ check_signal_message(\@_, -1, $server, undef, $nick, $host, 'privflood');
+ } else {
+ check_signal_message(\@_, -1, $server, $target, $nick, $host, 'pubflood');
}
}
}
@@ -539,8 +553,10 @@ sub hasmode {
my @trigger_switches = (@trigger_types, qw(all nocase stop once debug disabled));
# parameters (with an argument)
my @trigger_params = qw(pattern regexp command replace name);
+# all options that can be used to set filters, including negative matches (not_<filter>)
+my @trigger_filter_options = map(($_,'not_'.$_), keys(%filters));
# list of all options (including switches) for /TRIGGER ADD
-my @trigger_add_options = (@trigger_switches, @trigger_params, keys(%filters));
+my @trigger_add_options = (@trigger_switches, @trigger_params, @trigger_filter_options);
# same for /TRIGGER CHANGE, this includes the -no<option>'s
my @trigger_options = map(($_,'no'.$_) ,@trigger_add_options);
@@ -564,9 +580,10 @@ sub check_signal_message {
TRIGGER:
foreach my $trigger (@{$triggers_by_type{$condition}}) {
# check filters
- foreach my $trigfilter (@{$trigger->{'filters'}}) {
- if (! ($trigfilter->[2]($trigfilter->[1], $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra))) {
-
+ foreach my $trigfilter (filters_for_trigger($trigger)) {
+ my $filter_sub = $trigfilter->{'filter'}->{'sub'};
+ my $filter_matches = !!(&$filter_sub($trigfilter->{'param'}, $signal, $parammessage, $server, $channelname, $nickname, $address, $condition, $extra));
+ if ($filter_matches != $trigfilter->{'must_match'}) { # if it didn't match, or if it's a -not_* filter and it did match
next TRIGGER;
}
}
@@ -646,6 +663,12 @@ TRIGGER:
$recursion_depth--;
}
+# return array of filters for the given trigger
+sub filters_for_trigger($) {
+ my ($trigger) = @_;
+ return values(%{$trigger->{'filters'}});
+}
+
# used in check_signal_message to expand $'s
# $inthis is a string that can contain $ stuff (like 'foo$1bar$N')
sub do_expands {
@@ -789,8 +812,8 @@ sub rebuild {
ALLTYPES:
foreach my $type (@all_types) {
# check if all filters can apply to $type
- foreach my $filter (@{$trigger->{'filters'}}) {
- if (! grep {$_ eq $type} $filters{$filter->[0]}->{'types'}) {
+ foreach my $trigfilter (filters_for_trigger($trigger)) {
+ if (! grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
next ALLTYPES;
}
}
@@ -910,12 +933,6 @@ sub cmd_load {
$converted = 1;
}
- if (defined($trigger->{'replace'}) && ! $trigger->{'regexp'}) {
- Irssi::print("Trigger: trigger ".($index+1)." had -replace but no -regexp, removed it");
- splice (@old_triggers,$index,1);
- $index--; # nr of next trigger now is the same as this one was
- }
-
# convert to text with compat, and then to new trigger hash
$text = to_string($trigger,1);
my @args = &shellwords($text . ' a');
@@ -927,6 +944,7 @@ sub cmd_load {
} else { # new format
while ( $text = $io->getline ) {
chop($text);
+ next if ($text =~ /^[ ]*$|^#/);
my @args = &shellwords($text . ' a');
my $trigger = parse_options({},@args);
if ($trigger) {
@@ -977,8 +995,8 @@ sub to_string {
}
}
} else {
- foreach my $trigfilter (@{$trigger->{'filters'}}) {
- $string .= '-' . $trigfilter->[0] . param_to_string($trigfilter->[1]);
+ foreach my $trigfilter (filters_for_trigger($trigger)) {
+ $string .= '-' . $trigfilter->{'option'} . param_to_string($trigfilter->{'param'});
}
}
@@ -1092,17 +1110,22 @@ ARGS: for (my $arg = shift @args; $arg; $arg = shift @args) {
}
}
- # -<filter> <value>
- if ($filters{$option}) {
- push @{$trigger->{'filters'}}, [$option, shift @args, $filters{$option}->{'sub'}];
+ # -[not_]<filter> <value>
+ if ($option =~ /^(not_)?(.*)$/ && $filters{$2}) {
+ $trigger->{'filters'}->{$option} = {
+ option => $option,
+ must_match => ($1 ne 'not_'), # if false, trigger must only be done if filter sub returns false
+ filter_name => $2,
+ filter => $filters{$2},
+ param => shift @args
+ };
+
next ARGS;
}
- # -<nofilter>
+ # -no<filter>
if ($option =~ /^no(.*)$/ && $filters{$1}) {
- my $filter = $1;
- # the new filters are the old grepped for everything except ones with name $filter
- @{$trigger->{'filters'}} = grep( $_->[0] ne $filter, @{$trigger->{'filters'}} );
+ delete $trigger->{'filters'}->{$option};
}
}
@@ -1126,9 +1149,9 @@ ARGS: for (my $arg = shift @args; $arg; $arg = shift @args) {
# remove types for which the filters don't apply
foreach my $type (@trigger_types) {
if ($trigger->{$type}) {
- foreach my $filter (@{$trigger->{'filters'}}) {
- if (!grep {$_ eq $type} @{$filters{$filter->[0]}->{'types'}}) {
- Irssi::print("Warning: the filter -" . $filter->[0] . " can't apply to an event of type -$type, so I'm removing that type from this trigger.");
+ foreach my $trigfilter (filters_for_trigger($trigger)) {
+ if (!grep {$_ eq $type} @{$trigfilter->{'filter'}->{'types'}}) {
+ Irssi::print("Warning: the filter -" . $trigfilter->{'option'} . " can't apply to an event of type -$type, so I'm removing that type from this trigger.");
delete $trigger->{$type};
}
}