html/pager.pl


   1 # $Id: pager.pl,v 1.23 2003/01/27 09:45:16 jylefort Exp $
   2 
   3 use Irssi 20020121.2020 ();
   4 $VERSION = "1.1";
   5 %IRSSI = (
   6 	  authors     => 'Jean-Yves Lefort',
   7 	  contact     => 'jylefort\@brutele.be',
   8 	  name        => 'pager',
   9 	  description => 'Notifies people if they send you a private message or a DCC chat offer while you are away; runs a shell command configurable via /set if they page you',
  10 	  license     => 'BSD',
  11 	  changed     => '$Date: 2003/01/27 09:45:16 $ ',
  12 );
  13 
  14 # note:
  15 #
  16 #	Irssi special variables (see IRSSI_DOC_DIR/special_vars.txt) will be
  17 #	expanded in *_notice /set's, and will NOT be expanded in page_command
  18 #	for obvious security reasons.
  19 #
  20 # /set's:
  21 #
  22 #	page_command	a shell command to run if someone sends you the
  23 #			private message 'page' while you are away
  24 #
  25 #	away_notice	a notice to send to someone sending you a private
  26 #			message while you are away
  27 #
  28 #	paged_notice	a notice to send to someone who has just paged you
  29 #
  30 #	dcc_notice	a notice to send to someone who has just sent you
  31 #			a DCC chat offer (this automatically pages you)
  32 #
  33 # changes:
  34 #
  35 #	2003-01-27	release 1.1
  36 #			* notices and commands are now optional
  37 #
  38 #	2002-07-04	release 1.01
  39 #			* things are now printed in the right order
  40 #			* signal_add's uses a reference instead of a string
  41 #
  42 #	2002-04-25	release 1.00
  43 #			* increased version number
  44 #
  45 #	2002-02-06	release 0.20
  46 #			* builtin expand deprecated;
  47 #			  now uses Irssi's special variables
  48 #
  49 #	2002-01-27	release 0.11
  50 #			* uses builtin expand
  51 #
  52 #	2002-01-23	initial release
  53 
  54 use strict;
  55 use Irssi::Irc;			# for DCC object
  56 
  57 sub message
  58   {
  59     my ($server, $msg, $nick, $address) = @_;
  60   
  61     if ($server->{usermode_away})
  62       {
  63 	if (lc($msg) eq "page")
  64 	  {
  65 	    my $page_command = Irssi::settings_get_str("page_command");
  66 	    my $paged_notice = Irssi::settings_get_str("paged_notice");
  67 
  68 	    if ($page_command)
  69 	      {
  70 		system($page_command);
  71 	      }
  72 	    if ($paged_notice)
  73 	      {
  74 		$server->command("EVAL NOTICE $nick $paged_notice");
  75 	      }
  76 	  }
  77 	else
  78 	  {
  79 	    my $away_notice = Irssi::settings_get_str("away_notice");
  80 	    
  81 	    if ($away_notice)
  82 	      {
  83 		$server->command("EVAL NOTICE $nick $away_notice");
  84 	      }
  85 	  }
  86       }
  87   }
  88 
  89 sub dcc_request
  90   {
  91     my ($dcc, $sendaddr) = @_;
  92     
  93     if ($dcc->{server}->{usermode_away} && $dcc->{type} eq "CHAT")
  94       {
  95 	my $page_command = Irssi::settings_get_str("page_command");
  96 	my $dcc_notice = Irssi::settings_get_str("dcc_notice");
  97 
  98 	if ($page_command)
  99 	  {
 100 	    system($page_command);
 101 	  }
 102 	if ($dcc_notice)
 103 	  {
 104 	    $dcc->{server}->command("EVAL NOTICE $dcc->{nick} $dcc_notice");
 105 	  }
 106       }
 107   }
 108 
 109 Irssi::settings_add_str("misc",	"page_command",
 110 			"esdplay ~/sound/events/page.wav &");
 111 Irssi::settings_add_str("misc", "away_notice",
 112 			'$N is away ($A). Type /MSG $N PAGE to page him.');
 113 Irssi::settings_add_str("misc", "paged_notice",
 114 			'$N has been paged.');
 115 Irssi::settings_add_str("misc",	"dcc_notice",
 116 			'$N is away ($A) and has been paged. Type /MSG $N PAGE to page him again.');
 117 
 118 Irssi::signal_add_priority("message private", \&message,
 119 			   Irssi::SIGNAL_PRIORITY_LOW + 1);
 120 Irssi::signal_add_priority("dcc request", \&dcc_request,
 121 			   Irssi::SIGNAL_PRIORITY_LOW + 1);