]>
jfr.im git - irssi-scripts.git/blob - smshilight.pl
658aa5095cd65d6af0c365138234d590fcefe366
1 # smshi - sends highlights via SMS, using Twilio
2 # CC0 https://creativecommons.org/publicdomain/zero/1.0/
8 use vars
qw($VERSION %IRSSI);
11 my $ua = LWP
::UserAgent-
>new;
14 $ua->agent("irssi+SMSHi/$VERSION ");
16 authors
=> "John Runyon",
18 description
=> "send highlights via Twilio sms",
20 url
=> 'https://github.com/zonidjan/irssi-scripts',
21 contact
=> 'https://github.com/zonidjan/irssi-scripts/issues'
25 return unless Irssi
::settings_get_bool
('smshi_active');
27 my ($dest, $text, $stripped) = @_;
28 my $server = $dest->{server
};
29 my $mynick = $server->{nick
};
30 return unless ($dest->{level
} & MSGLEVEL_HILIGHT
) # continue if hilight...
31 or ($dest->{level
} & MSGLEVEL_MSGS
&& index($stripped, $mynick) != -1); # or if it's a PM containing my nick
32 return if $stripped =~ /<.?\Q$mynick\E>/; # avoid people quoting me
33 return if (!$server->{usermode_away
} && Irssi
::settings_get_bool
('smshi_away_only')); # and obey away_only
36 for my $c (split //, $stripped) {
37 if (ord($c) > 31 && ord($c) < 127) {
40 $msg .= '\\x'.sprintf("%02x", ord($c));
44 my $chname = $dest->{window
}->get_active_name();
45 my $sms = $server->{tag
}."/".$chname.$msg;
49 _send_sms
("This is an SMS test.");
54 my $sid = Irssi
::settings_get_str
('smshi_sid');
55 my $token = Irssi
::settings_get_str
('smshi_token');
56 my $from = Irssi
::settings_get_str
('smshi_from');
57 my $to = Irssi
::settings_get_str
('smshi_to');
59 my $url = "https://$sid:$token\@api.twilio.com/2010-04-01/Accounts/$sid/Messages.json";
60 my $req = HTTP
::Request-
>new('POST', $url);
61 $req->content_type('application/x-www-form-urlencoded');
62 $req->content("To=$to&From=$from&Body=$sms");
64 my $res = $ua->request($req);
65 return unless Irssi
::settings_get_bool
('smshi_debug');
66 if ($res->is_success) {
67 print "Good. Sent to $to from $from: $sms";
72 print $res->status_line;
77 Irssi
::settings_add_bool
('smshi', 'smshi_active', 0); # master switch
78 Irssi
::settings_add_bool
('smshi', 'smshi_away_only', 1); # send only when away?
79 Irssi
::settings_add_bool
('smshi', 'smshi_debug', 0); # show debugging info
80 Irssi
::settings_add_str
('smshi', 'smshi_sid', ''); # Twilio SID
81 Irssi
::settings_add_str
('smshi', 'smshi_token', ''); # Twilio token
82 Irssi
::settings_add_str
('smshi', 'smshi_from', ''); # From number (+12022345678)
83 Irssi
::settings_add_str
('smshi', 'smshi_to', ''); # To number (+12022345678)
85 Irssi
::signal_add
('print text', 'got_print');
86 Irssi
::command_bind
('testsms', 'test_sms');
87 Irssi
::print('%G>>%n '.$IRSSI{name
}.' '.$VERSION.' loaded');