]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
timer.pl: minor improvements
authorDoug Freed <redacted>
Wed, 17 Jan 2018 05:32:02 +0000 (00:32 -0500)
committerGitHub <redacted>
Wed, 17 Jan 2018 05:32:02 +0000 (00:32 -0500)
* Remove finished timers during their last cycle, rather than one
  interval after
* Allow timer names to contain anything other than whitespace

scripts/timer.pl

index cd8f8602d73c341f8327ea34a4f8a0d0ced8035c..1c5a8c725f799c0655832f10b0e66644cca53d6b 100644 (file)
@@ -19,7 +19,7 @@ use warnings;
 use vars  qw ($VERSION %IRSSI);
 use Irssi 20020325 qw (command_bind command_runsub command timeout_add timeout_remove signal_add_first);
 
-$VERSION = '0.6';
+$VERSION = '0.7';
 %IRSSI = (
     authors     => 'Kimmo Lehto, Marcus Rueckert',
     contact     => 'kimmo@a-men.org, darix@irssi.org' ,
@@ -35,13 +35,6 @@ our %timers;
 sub timer_command {
     my ( $name ) = @_;
     if ( exists ( $timers{$name} ) ) {
-        if ( $timers{$name}->{'repeat'} != -1 ) {
-            if ( $timers{$name}->{'repeat'}-- == 0) {
-                cmd_timerstop( $name );
-                return;
-            }
-        }
-
         my ($server, $item);
         if ($timers{$name}->{'server'}) {
             $server = Irssi::server_find_tag( $timers{$name}->{'server'} );
@@ -54,6 +47,12 @@ sub timer_command {
         } else {
             command( $timers{$name}->{'command'} );
         }
+
+        if ( $timers{$name}->{'repeat'} != -1 ) {
+            if ( --$timers{$name}->{'repeat'} == 0) {
+                cmd_timerstop( $name );
+            }
+        }
     }
 }
 
@@ -88,11 +87,11 @@ command_bind 'timer add' => sub {
     my ( $data, $server, $item ) = @_;
     my ( $name, $interval, $times, $command );
 
-    if ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(-?\d+)\s+(.*)$/ ) {
+    if ( $data =~ /^\s*(\S+)\s+(\d+(?:\.\d+)?)\s+(-?\d+)\s+(.*)$/ ) {
         ( $name, $interval, $times, $command ) = ( $1, $2, $3, $4 );
         $times = -1 if ( $times == 0 );
     }
-    elsif ( $data =~ /^\s*(\w+)\s+(\d+(?:\.\d+)?)\s+(.*)$/ )
+    elsif ( $data =~ /^\s*(\S+)\s+(\d+(?:\.\d+)?)\s+(.*)$/ )
     {
         ( $name, $interval, $times, $command ) = ( $1, $2, -1, $3 );
     }
git clone https://git.99rst.org/PROJECT