/var/www/www.irssi.org-old/scripts/html/away2web.pl


   1 #!/usr/bin/perl
   2 
   3 use strict;
   4 use vars qw($VERSION %IRSSI);
   5 $VERSION = "2003100201";
   6 %IRSSI = (
   7     authors     => "Oskari 'Okko' Ojala",
   8     contact     => "sorter.irssi-scripts\@okko.net",
   9     name        => "away2web",
  10     description => "Write /away information to a file to be used on web pages",
  11     license     => "BSD",
  12     changed     => "$VERSION",
  13 );
  14 use Irssi 20020324;
  15 
  16 #
  17 # Writes /away information to a file. A web page script (cgi / php / pl..) can
  18 # then read the file and display online/offline information.
  19 # 
  20 # The web page script is left as an excersise for the user because the platforms
  21 # vary. :-)
  22 # 
  23 # Tip: You can also modify this script to directly write HTML and then just include
  24 # the file on your web page.
  25 #
  26 #
  27 # Format of the file:
  28 # First line:  Either "1" or "0". 0=Offline (away), 1=Online (not away).
  29 # Second line: The away reason (message). If the user is Online, second line is
  30 #              empty but exists.
  31 #
  32 # File is written to ~/.irssi/away2web-status.
  33 #
  34 
  35 sub catch_away {
  36 	my $server = shift;
  37 
  38 	open(STATUSFILE, '> '.$ENV{'HOME'}.'/.irssi/away2web-status') || die ("away2web.pl: Could not open file for writing:".$!);
  39 
  40 	if ($server->{usermode_away}) {
  41 	    # User is offline.
  42 	    print STATUSFILE "0\n";
  43 	} else {
  44 	    # User is online.
  45 	    print STATUSFILE "1\n";
  46 	}
  47 
  48 	print STATUSFILE $server->{'away_reason'}."\n";
  49 
  50 	close(STATUSFILE);
  51 
  52 }
  53 
  54 Irssi::signal_add("away mode changed", "catch_away");
  55 
  56 print CLIENTCRAP '%B>>%n '.$IRSSI{name}.' '.$VERSION.' (c) '.$IRSSI{authors}.' loaded';
  57 
  58 # end of script.