html/notonline.pl


   1 # Answers "$nick: No." if you're away and someone asks are you online on a channel.
   2 
   3 use strict;
   4 use Irssi;
   5 use locale;
   6 
   7 use vars qw($VERSION %IRSSI %answers $floodlimit %floodi);
   8 
   9 $VERSION = '0.9';
  10 %IRSSI = (
  11     authors     => 'Johan "Ion" Kiviniemi',
  12     contact     => 'ion at hassers.org',
  13     name        => 'NotOnline',
  14     description =>
  15 'Answers "$nick: No." if you\'re away and someone asks are you online on a channel',
  16     license => 'Public Domain',
  17     url     => 'http://ion.amigafin.org/irssi/',
  18     changed => 'Tue Mar 12 22:20 EET 2002',
  19 );
  20 
  21 %answers = (
  22     'online'    => 'Offline.',
  23     'there'     => 'Not here.',
  24     'idle'      => 'Of course.',
  25     'paikalla'  => 'En, vaan paikassa.',
  26     'siellä'    => 'Ei kun tuolla.',
  27     'siellä'   => 'Ei kun tuolla.',
  28     'hereillä'  => 'Nukkumassa.',
  29     'hereillä' => 'Nukkumassa.',
  30 );
  31 
  32 $floodlimit = 600;    # notice the same channel only once in N seconds
  33 %floodi     = ();
  34 
  35 Irssi::signal_add_last(
  36     'message public' => sub {
  37         my ($server, $msg, $nick, $address, $target) = @_;
  38 
  39         # Am i away?
  40         return unless $server->{usermode_away};
  41 
  42         # Am i asked about something?
  43         my $own_nick = $server->{nick};
  44         $own_nick =~ s/\W//g;
  45         return
  46           unless $msg =~ /^(\Q$server->{nick}\E|\Q$own_nick\E)\s*[,:].+\?/i;
  47 
  48         # Is it me who's talking?
  49         return if $nick eq $server->{nick};
  50 
  51         # Are you asking the right question?
  52         my $answer;
  53         foreach (keys %answers) {
  54             $answer = $answers{$_} if $msg =~ /\b\Q$_\E\b/i;
  55         }
  56         return unless $answer;
  57 
  58         # You aren't flooding, are you?
  59         if (defined $floodi{$target}) {
  60             if (time - $floodi{$target} < $floodlimit) {
  61                 return;
  62             } else {
  63                 undef $floodi{$target};
  64             }
  65         }
  66 
  67         $nick =~ s/\W//g;
  68         $nick = lc $nick
  69           if Irssi::settings_get_bool('completion_nicks_lowercase');
  70         $nick .= Irssi::settings_get_str('completion_char') || ":";
  71 
  72         $floodi{$target} = time;
  73         $server->command("msg $target $nick $answer");
  74         # Irssi::print("msg $target $nick $answer");
  75     }
  76 );