html/beep_beep.pl


   1 #!/usr/bin/irssi
   2 #
   3 # irssi beep replace script (tested with irssi v0.8.8.CVS (20030126-1726))
   4 # (C) 2002-2004 Ge0rG@IRCnet (Georg Lukas <georg@op-co.de>)
   5 # inspired and tested by Macrotron@IRCnet (macrotron@president.eu.org)
   6 
   7 # added beep_flood to irssi settings: beep_cmd will be run not more often
   8 # then every $beep_flood milliseconds
   9 
  10 # fixed memory leak with timeout_add (made irssi waste 80mb and more after a day of IRC)
  11 # added > /dev/null, thx to Luis Oliveira
  12 # fixed timeout handling bug, thx to frizop@charter.net
  13 
  14 $VERSION = "0.10";
  15 %IRSSI = (
  16     authors	=> "Georg Lukas",
  17     contact	=> "georg\@op-co.de",
  18     name	=> "beep_beep",
  19     description	=> "runs arbitrary command instead of system beep, includes flood protection",
  20     license	=> "Public Domain",
  21     url		=> "http://op-co.de/irssi/",
  22 );
  23 
  24 use Irssi;
  25 
  26 my $might_beep = 1, $to_tag;
  27 
  28 sub beep_overflow_timeout() {
  29 	$might_beep = 1;
  30 	Irssi::timeout_remove($to_tag);
  31 }
  32 
  33 sub beep_beep() {
  34 	my $beep_cmd = Irssi::settings_get_str("beep_cmd");
  35 	if ($beep_cmd) {
  36 		if ($might_beep) {
  37 			my $beep_flood = Irssi::settings_get_int('beep_flood');
  38 			$beep_flood = 1000 if $beep_flood < 0;
  39 			Irssi::timeout_remove($to_tag);
  40 			$to_tag = Irssi::timeout_add($beep_flood, 'beep_overflow_timeout', undef);
  41 			system($beep_cmd);
  42 			$might_beep = 0;
  43 		}
  44 		Irssi::signal_stop();
  45 	}
  46 }
  47 
  48 Irssi::settings_add_str("lookandfeel", "beep_cmd", "play ~/.irssi/scripts/beep_beep.wav > /dev/null &");
  49 Irssi::settings_add_int("lookandfeel", "beep_flood", 250);
  50 Irssi::signal_add("beep", "beep_beep");
  51