# Fixes for multiple servers and window items by dg
#
# 2003-08-27 coekie:
# - use item names and server tags, fixes irssi crash if window item or server is destroyed
#
# 2003-08-19
# - changed timer stop code a bit.
# should fix the random timer o.O never happened to me before.
#
# 2002-12-21 darix:
# - nearly complete rewrite ;) the old version wasnt "use strict;" capable =)
# - still some warnings with "use warnings;"
# - use of command_runsub now :)
#
use strict;
use Data::Dumper;
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.8';
%IRSSI = (
authors => 'Kimmo Lehto, Marcus Rueckert',
contact => '[email protected], [email protected]' ,
name => 'Timer',
description => 'Provides /timer command for mIRC/BitchX type timer functionality.',
license => 'Public Domain',
changed => '2015-02-07'
);
Irssi::settings_add_bool('timer', 'timer_stop_msgs', 1);
our %timers;
# my %timer = { repeat => \d+, command => '' , windowitem => NULL , server=> NULL, timer = NULL};
sub timer_command {
my ( $name ) = @_;
if ( exists ( $timers{$name} ) ) {
my ($server, $item);
if ($timers{$name}->{'server'}) {
$server = Irssi::server_find_tag( $timers{$name}->{'server'} );
}
if ( $server ) {
if ( $timers{$name}->{'windowitem'}) {
$item = $server->window_find_item( $timers{$name}->{'windowitem'} );
}
($item ? $item : $server)->command( $timers{$name}->{'command'} );
} else {
command( $timers{$name}->{'command'} );
}
if ( $timers{$name}->{'repeat'} != -1 ) {
if ( --$timers{$name}->{'repeat'} == 0) {
cmd_timerstop( $name );
}
}
}
}
sub cmd_timerstop {
my ( $name ) = @_;
my $verbose = Irssi::settings_get_bool('timer_stop_msgs');
if ( exists ( $timers{$name} ) ) {
timeout_remove($timers{$name}->{'timer'});
$timers{$name} = ();
delete ( $timers{$name} );
print( CRAP "Timer \"$name\" stopped." ) if $verbose;
}
else {
print( CRAP "\cBTimer:\cB No such timer \"$name\"." ) if $verbose;
}
}
sub cmd_timer_help {
print ( <