1#!/usr/local/bin/perl
2#
3# irssi beep with-command-script
4# (C) 2003 Remco den Breeje
5# inspired by Georg Lukas
6
7# howtoinstall:
8#  copy this file to ~/.irssi/scripts/
9#  in irssi:
10#   $/script load my_beep.pl
11#  change the settings
12#   $/set beep_msg_level HILIGHT
13#   $/set beep_cmd beep
14
15use strict;
16use vars qw($VERSION %IRSSI);
17$VERSION = "0.9";
18%IRSSI = (
19    authors	=> "Remco den Breeje",
20    contact	=> "stacium or stek (most of the time) @ quakenet.org",
21    name	=> "my_beep",
22    description	=> "runs arbitrary command instead of system beep, includes flood protection",
23    license	=> "Public Domain",
24    url		=> "http://www.xs4all.nl/~stacium/irssi/my_beep.html",
25);
26
27use Irssi;
28
29my $can_I_beep = 1;
30my ($timeout_tag, $autoaway_to_tag);
31
32sub beep_overflow_timeout() {
33	$can_I_beep = 1;
34	# and kill the loop
35        Irssi::timeout_remove($timeout_tag);
36        $autoaway_to_tag = undef;
37}
38
39sub my_beep() {
40	my $beep_cmd = Irssi::settings_get_str("beep_cmd");
41	if ($beep_cmd) {
42		my $beep_flood = Irssi::settings_get_int('beep_flood');
43                # check on given beep_flood
44                if($beep_flood < 0)
45		{
46			Irssi::print("Warning! Wrong value for beep_flood (time in milisecs)");
47			Irssi::signal_stop();
48			return;
49		}
50		if ($can_I_beep) {
51		        $timeout_tag = Irssi::timeout_add($beep_flood, 'beep_overflow_timeout', undef);
52			system($beep_cmd);
53			$can_I_beep = 0;
54		}
55		Irssi::signal_stop();
56	}
57}
58
59Irssi::settings_add_str("lookandfeel", "beep_cmd", "echo INeedToBeSet > /dev/null");
60Irssi::settings_add_int("lookandfeel", "beep_flood", 2000);
61Irssi::signal_add("beep", "my_beep");
62