1use Irssi; 2use Irssi::TextUI; 3use strict; 4use vars qw($VERSION %IRSSI); 5 6#Setting variables: 7 8#first_away_message - The first /away messsage 9#second_away_message - The second /away message 10#first_away_timeout - Number of seconds to activate the first away state 11#second_away_timeout - Number of seconds to activate the second away state 12#away_servers - list of servertags seperated by spaces where auto_away will work. 13# If empty (/set -clear away_servers, it will work on every network 14# 15# CHANGELOG: 16# 21 DEC 2004: 17# the timer is only being reset when pressing enter. and the away timer starts counting after the last time you pressed enter. 18# this is less CPU consuming :-D 19 20$VERSION = '0.2'; 21%IRSSI = ( 22 authors => 'Tijmen Ruizendaal', 23 contact => 'tijmen@fokdat.nl', 24 name => 'auto_away.pl', 25 description => 'server specific autoaway with two different away states at different intervals', 26 license => 'GPLv2', 27 url => 'http://the-timing.nl/stuff/irssi-bitlbee', 28 changed => '2004-12-21', 29); 30 31 32my $timer; 33 34Irssi::settings_add_str('misc', 'first_away_message', undef); 35Irssi::settings_add_str('misc', 'second_away_message', undef); 36Irssi::settings_add_int('misc', 'first_away_timeout', undef); 37Irssi::settings_add_int('misc', 'second_away_timeout', undef); 38Irssi::settings_add_str('misc', 'away_servers', undef); 39 40sub reset_timer{ 41 my $key=shift; 42 if($key == 10){ 43 my (@servers) = Irssi::servers(); 44 foreach my $server (@servers) { 45 if($server->{usermode_away} == 1){ 46 $server->command("AWAY -one"); 47 } 48 } 49 Irssi::timeout_remove($timer); 50 my $timeout = Irssi::settings_get_int('first_away_timeout'); 51 if ($timeout){ 52 $timer = Irssi::timeout_add_once($timeout*1000, 'first_away', undef); ## activate first away state 53 } 54 } 55} 56sub first_away{ 57 away(1); 58 my $timeout = Irssi::settings_get_int('second_away_timeout'); 59 if ($timeout){ 60 Irssi::timeout_remove($timer); 61 $timer = Irssi::timeout_add_once($timeout*1000, 'away', 2); ## activate second away state 62 } 63} 64sub away{ 65 my $state = shift; 66 my $server_string = Irssi::settings_get_str('away_servers'); 67 my (@away_servers) = split (/ +/, $server_string); 68 my (@servers) = Irssi::servers(); 69 my $message; 70 71 if($state == 1){ 72 $message = Irssi::settings_get_str('first_away_message'); 73 }elsif($state == 2){ 74 $message = Irssi::settings_get_str('second_away_message'); 75 } 76 if($server_string){ 77 foreach my $away_server (@away_servers) { 78 #print "|$away_server|"; 79 foreach my $server (@servers) { 80 if ($away_server eq $server->{tag} && ($server->{usermode_away} == 0 || $state == 2) ){ 81 $server->command("AWAY -one $message"); 82 } 83 } 84 } 85 }else{ 86 my $server=$servers[0]; 87 $server->command("AWAY -all $message"); 88 } 89} 90Irssi::signal_add_last('gui key pressed', 'reset_timer'); 91