-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms.pl
executable file
·67 lines (51 loc) · 1.26 KB
/
sms.pl
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
use Irssi;
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = '0.02';
%IRSSI = (
authors => 'Dylan Johnston',
contact => '[email protected]',
name => 'SMS Highlights when Away',
description => 'texts you your highlights if you\'re away.',
license => 'GPL',
);
my $away = 0; # should probably figure out if we are away or not
sub sms {
my ($msg) = @_;
my $token = "PUT YOUR TROPO TOKEN HERE";
my $apiurl = "https://api.tropo.com/1.0/sessions?action=create&token=";
$msg =~ s/#/\%23/g;
my $url = $apiurl . $token . "&msg=" . $msg;
my $cmd = "wget \"" . $url ."\"";
$SIG{CHLD} = 'IGNORE';
if(fork() == 0) {
close(STDOUT);
close(STDIN);
close(STDERR);
system( "wget", $url, "-O", "/dev/null" );
exit(0);
}
}
sub parse_msg {
my ($dest, $text, $stripped) = @_;
if ( $dest->{level} & MSGLEVEL_HILIGHT && $away ) {
sms($dest->{target}. " " .$stripped );
}
}
sub parse_privmsg {
my ($server, $msg, $nick, $address) = @_;
if ( $away ) {
sms($nick.": " .$msg );
}
}
sub parse_away {
my ($server ) = @_;
if ( $server->{usermode_away} ) {
$away = 1;
} else {
$away = 0;
}
}
Irssi::signal_add('print text', \&parse_msg );
Irssi::signal_add('message private', \&parse_privmsg );
Irssi::signal_add('away mode changed', \&parse_away );