summaryrefslogtreecommitdiffstats
path: root/scripts/anotherway.pl
blob: f7a0ca885ae7f0746eab27b0357b476ccb0d1396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
#
# by Stefan Tomanek <stefan@pico.ruhr.de>

use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "2003010201";
%IRSSI = (
    authors     => "Stefan 'tommie' Tomanek",
    contact     => "stefan\@pico.ruhr.de",
    name        => "anotherway",
    description => "Another auto away script",
    license     => "GPLv2",
    changed     => "$VERSION",
);
use Irssi 20020324;
use vars qw($timer @signals);

@signals = ('message own_public', 'message own_private');

sub go_away {
    #Irssi::print "%R>>%n Going away...$timer";
    Irssi::timeout_remove($timer);
    my $reason = Irssi::settings_get_str("anotherway_reason");
    my @servers = Irssi::servers();
    return unless @servers;
    Irssi::signal_remove($_ , "reset_timer") foreach (@signals);
    $servers[0]->command('AWAY '.$reason);
    Irssi::signal_add($_ , "reset_timer") foreach (@signals);
}

sub reset_timer {
    #Irssi::print "%R>>%n RESET";
    Irssi::signal_remove($_ , "reset_timer") foreach (@signals);
    foreach (Irssi::servers()) {
	$_->command('AWAY') if $_->{usermode_away};
	last;
    }
    #Irssi::signal_add('nd', "reset_timer");
    Irssi::timeout_remove($timer);
    my $timeout = Irssi::settings_get_int("anotherway_timeout");
    $timer = Irssi::timeout_add($timeout*1000, "go_away", undef);
    Irssi::signal_add($_, "reset_timer") foreach (@signals);
}

Irssi::settings_add_str($IRSSI{name}, 'anotherway_reason', 'a-nother-way');
Irssi::settings_add_int($IRSSI{name}, 'anotherway_timeout', 300);

{
    Irssi::signal_add($_, "reset_timer") foreach (@signals);
    reset_timer();
}

print CLIENTCRAP '%B>>%n '.$IRSSI{name}.' '.$VERSION.' loaded';