summaryrefslogtreecommitdiffstats
path: root/scripts/pager.pl
blob: 50d78994f9f9fd91e52922bbb94ed63f8aa41c94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# $Id: pager.pl,v 1.23 2003/01/27 09:45:16 jylefort Exp $

use strict;
use Irssi 20020121.2020 ();

use vars qw/$VERSION %IRSSI/;
$VERSION = "1.2";
%IRSSI = (
	  authors     => 'Jean-Yves Lefort',
	  contact     => 'jylefort\@brutele.be',
	  name        => 'pager',
	  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',
	  license     => 'BSD',
	  changed     => '$Date: 2017/03/06 $ ',
);

# note:
#
#	Irssi special variables (see IRSSI_DOC_DIR/special_vars.txt) will be
#	expanded in *_notice /set's, and will NOT be expanded in page_command
#	for obvious security reasons.
#
# /set's:
#
#	page_command	a shell command to run if someone sends you the
#			private message 'page' while you are away
#
#	away_notice	a notice to send to someone sending you a private
#			message while you are away
#
#	paged_notice	a notice to send to someone who has just paged you
#
#	dcc_notice	a notice to send to someone who has just sent you
#			a DCC chat offer (this automatically pages you)
#
# changes:
#
#	2017-03-06	release 1.2
#			* declaration $VERSION %IRSSI
#
#	2003-01-27	release 1.1
#			* notices and commands are now optional
#
#	2002-07-04	release 1.01
#			* things are now printed in the right order
#			* signal_add's uses a reference instead of a string
#
#	2002-04-25	release 1.00
#			* increased version number
#
#	2002-02-06	release 0.20
#			* builtin expand deprecated;
#			  now uses Irssi's special variables
#
#	2002-01-27	release 0.11
#			* uses builtin expand
#
#	2002-01-23	initial release

use strict;
use Irssi::Irc;			# for DCC object

sub message
  {
    my ($server, $msg, $nick, $address) = @_;
  
    if ($server->{usermode_away})
      {
	if (lc($msg) eq "page")
	  {
	    my $page_command = Irssi::settings_get_str("page_command");
	    my $paged_notice = Irssi::settings_get_str("paged_notice");

	    if ($page_command)
	      {
		system($page_command);
	      }
	    if ($paged_notice)
	      {
		$server->command("EVAL NOTICE $nick $paged_notice");
	      }
	  }
	else
	  {
	    my $away_notice = Irssi::settings_get_str("away_notice");
	    
	    if ($away_notice)
	      {
		$server->command("EVAL NOTICE $nick $away_notice");
	      }
	  }
      }
  }

sub dcc_request
  {
    my ($dcc, $sendaddr) = @_;
    
    if ($dcc->{server}->{usermode_away} && $dcc->{type} eq "CHAT")
      {
	my $page_command = Irssi::settings_get_str("page_command");
	my $dcc_notice = Irssi::settings_get_str("dcc_notice");

	if ($page_command)
	  {
	    system($page_command);
	  }
	if ($dcc_notice)
	  {
	    $dcc->{server}->command("EVAL NOTICE $dcc->{nick} $dcc_notice");
	  }
      }
  }

Irssi::settings_add_str("misc",	"page_command",
			"esdplay ~/sound/events/page.wav &");
Irssi::settings_add_str("misc", "away_notice",
			'$N is away ($A). Type /MSG $N PAGE to page him.');
Irssi::settings_add_str("misc", "paged_notice",
			'$N has been paged.');
Irssi::settings_add_str("misc",	"dcc_notice",
			'$N is away ($A) and has been paged. Type /MSG $N PAGE to page him again.');

Irssi::signal_add_priority("message private", \&message,
			   Irssi::SIGNAL_PRIORITY_LOW + 1);
Irssi::signal_add_priority("dcc request", \&dcc_request,
			   Irssi::SIGNAL_PRIORITY_LOW + 1);