]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
trigger.pl: various improvements
authorDoug Freed <redacted>
Tue, 1 Aug 2017 03:01:45 +0000 (23:01 -0400)
committerGitHub <redacted>
Tue, 1 Aug 2017 03:01:45 +0000 (23:01 -0400)
* Allow notify trigger types to use -masks

They have masks, so allow matching them.

* Allow matching old nick using -other_masks for nick changes

Matching the old nick has its uses, so shoehorn it under -other_masks.

* Add -last option; if trigger with this option matched, doesn't
  process any more triggers for that message

Useful if the trigger's action does something like kickban or akill.

* Allow moving triggers entirely by name

Useful for programmatic rearranging of triggers, as you don't need to
know the number of the target.  First trigger will be placed before
second trigger.  (Goes well with -last, too)

scripts/trigger.pl

index fb2650f809f7b080f60725c976a0a3cc2d9095ab..0b05ad9f9766a6d9c9a0564e34de8a33d4f58f6c 100644 (file)
@@ -23,7 +23,7 @@ use Text::ParseWords;
 use IO::File;
 use vars qw($VERSION %IRSSI);
 
-$VERSION = '1.1';
+$VERSION = '1.2';
 %IRSSI = (
        authors     => 'Wouter Coekaerts',
        contact     => 'wouter@coekaerts.be',
@@ -104,6 +104,7 @@ All filters except for -pattern and -regexp can also be inversed by prefixing wi
      -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
+     -last: %|Don't process any more triggers for this message
 
 %U%_Other options%_%U 
      -disabled: %|Same as removing it, but keeps it in case you might need it later
@@ -168,8 +169,10 @@ my @allmsg_types = (@allchanmsg_types, qw(privmsgs privactions privnotices privc
 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 that can use -masks
+my @mask_types = (@all_types, qw(notify_join notify_part notify_away notify_unaway notify_unidle));
 # trigger types with a server
-my @all_server_types = (@all_types, qw(rawin notify_join notify_part notify_away notify_unaway notify_unidle pubflood privflood));
+my @all_server_types = (@mask_types, qw(rawin pubflood privflood));
 # all trigger types
 my @trigger_types = (@all_server_types, qw(send_command send_text beep));
 #trigger types that are not in -all
@@ -253,7 +256,7 @@ my @signals = (
 {
        'types' => ['nick_changes'],
        'signal' => 'message nick',
-       'sub' => sub {check_signal_message(\@_,-1,$_[0],undef,$_[1],$_[3],'nick_changes');}
+       'sub' => sub {check_signal_message(\@_,-1,$_[0],undef,$_[1],$_[3],'nick_changes',{'other'=>$_[2]});}
 },
 # "message dcc", DCC_REC *dcc, char *msg
 {
@@ -453,7 +456,7 @@ my %filters = (
        }
 },
 'masks' => {
-       'types' => \@all_types,
+       'types' => \@mask_types,
        'sub' => sub {
                my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
                $address //= '';
@@ -461,11 +464,11 @@ my %filters = (
        }
 },
 'other_masks' => {
-       'types' => ['kicks', 'mode_nick'],
+       'types' => ['kicks', 'mode_nick', 'nick_changes'],
        'sub' => sub {
                my ($param, $signal,$parammessage,$server,$channelname,$nickname,$address,$condition,$extra) = @_;
                return 0 unless defined($extra->{'other'});
-               my $other_address = get_address($extra->{'other'}, $server, $channelname);
+               my $other_address = ($condition ne 'nick_changes') ? get_address($extra->{'other'}, $server, $channelname) : $address;
                return defined($other_address) && $server->masks_match($param, $extra->{'other'}, $other_address);
        }
 },
@@ -551,7 +554,7 @@ sub hasmode {
 }
 
 # list of all switches
-my @trigger_switches = (@trigger_types, qw(all nocase stop once debug disabled));
+my @trigger_switches = (@trigger_types, qw(all nocase stop once debug disabled last));
 # 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>)
@@ -649,6 +652,9 @@ TRIGGER:
                        }
                        $need_rebuild = 1;
                }
+               if ($trigger->{'last'}) {
+                       last TRIGGER;
+               }
        }
 
        if ($need_rebuild) {
@@ -1195,17 +1201,14 @@ sub cmd_move {
        my @args = &shellwords($data);
        my $index = find_trigger(shift @args);
        if ($index != -1) {
-               my $newindex = shift @args;
-               if ($newindex < 1 || $newindex > scalar(@triggers)) {
-                       Irssi::print("$newindex is not a valid trigger number");
-                       return;
+               my $newindex = find_trigger(shift @args);
+               if ($newindex != -1) {
+                       Irssi::print("Moved from " . ($index+1) . " to " . ($newindex+1) . ": " . to_string($triggers[$index]));
+                       my $trigger = splice (@triggers,$index,1); # remove from old place
+                       splice (@triggers,$newindex,0,($trigger)); # insert at new place
+                       rebuild();
+                       $changed_since_last_save = 1;
                }
-               Irssi::print("Moved from ". ($index+1) ." to $newindex: ". to_string($triggers[$index]));
-               $newindex -= 1; # array starts counting from 0
-               my $trigger = splice (@triggers,$index,1); # remove from old place
-               splice (@triggers,$newindex,0,($trigger)); # insert at new place
-               rebuild();
-               $changed_since_last_save = 1;
        }
 }
 
git clone https://git.99rst.org/PROJECT