Commit 707aea7d66f7e52c6916429eccbd988b8ff33429

Authored by Caesar Ahlenhed
0 parents

First comment

Showing 1 changed file with 112 additions and 0 deletions   Show diff stats
boxcarirssi.pl 0 → 100755
  1 +++ a/boxcarirssi.pl
... ... @@ -0,0 +1,112 @@
  1 +use strict;
  2 +use warnings;
  3 +
  4 +#####################################################################
  5 +# This script sends notifications to your
  6 +# iPhone using your boxcar email and password when you are away.
  7 +#
  8 +# Originally I made this script for Prowl, but since people tend to
  9 +# be cheap and rather use boxcar(which is not as good) I ported it
  10 +# to boxcar. Boxcar lacks features such as priority.
  11 +#
  12 +# Commands:
  13 +# /set boxcar_email something@example.com
  14 +# /set boxcar_password password
  15 +# /set boxcar_general_hilight on/off
  16 +#
  17 +# "General hilight" basically referrs to ALL the hilights you have
  18 +# added manually in irssi, if many, it can get really bloated if
  19 +# turned on. Default is Off.
  20 +#
  21 +# You will need the following packages:
  22 +# LWP::UserAgent (You can install this using cpan -i LWP::UserAgent)
  23 +# Crypt::SSLeay (You can install this using cpan -i Crypt::SSLeay)
  24 +#
  25 +# Or if you're using Debian GNU/Linux:
  26 +# apt-get update;apt-get install libwww-perl libcrypt-ssleay-perl
  27 +#
  28 +#
  29 +# eth0 will prevail. || irc.eth0.info
  30 +#
  31 +#####################################################################
  32 +
  33 +
  34 +use Irssi;
  35 +use Irssi::Irc;
  36 +use vars qw($VERSION %IRSSI);
  37 +use LWP::UserAgent;
  38 +use HTTP::Request::Common;
  39 +
  40 +$VERSION = "0.1";
  41 +
  42 +%IRSSI = (
  43 + authors => "Caesar 'sniker' Ahlenhed",
  44 + contact => "sniker\@se.linux.org",
  45 + name => "boxcarirssi",
  46 + description => "Sends notifcations when away",
  47 + license => "GPLv2",
  48 + url => "http://sniker.codebase.nu",
  49 + changed => "Sat Feb 12 23:56:32 CET 2011",
  50 +);
  51 +
  52 +# Configuration settings and default values.
  53 +Irssi::settings_add_str("boxcarirssi", "boxcarirssi_email", "");
  54 +Irssi::settings_add_str("boxcarirssi", "boxcarirssi_password", "");
  55 +Irssi::settings_add_bool("boxcarirssi", "boxcarirssi_general_hilight", 0);
  56 +
  57 +sub send_noti {
  58 + my ($text) = @_;
  59 +
  60 + my %options = ();
  61 +
  62 + $options{'application'} ||= "Irssi";
  63 + $options{'notification'} = $text;
  64 +
  65 + my ($userAgent, $req, $response);
  66 + $userAgent = LWP::UserAgent->new;
  67 + $userAgent->agent("BoxcarIrssi/1.0");
  68 +
  69 + $req = HTTP::Request->new(POST => "https://boxcar.io/notifications");
  70 + $req->content("notification[from_screen_name]=" . $options{'application'} . "&notification[message]=" . $options{'notification'});
  71 + $req->authorization_basic(Irssi::settings_get_str("boxcarirssi_email") => Irssi::settings_get_str("boxcarirssi_password"));
  72 +
  73 + $response = $userAgent->request($req);
  74 +
  75 + if ($response->is_success) {
  76 + # I guess it worked, eh?
  77 + } else {
  78 + Irssi::print("Notification not posted: " . $response->content);
  79 + }
  80 +}
  81 +
  82 +sub pubmsg {
  83 + my ($server, $data, $nick) = @_;
  84 +
  85 + if($server->{usermode_away} == 1 && $data =~ /$server->{nick}/i){
  86 + send_noti("Hilighted - " . $nick . ': ' . $data);
  87 + }
  88 +}
  89 +
  90 +sub privmsg {
  91 + my ($server, $data, $nick) = @_;
  92 + if($server->{usermode_away} == 1){
  93 + send_noti("PM - " . $nick . ': ' . $data);
  94 + }
  95 +}
  96 +
  97 +sub genhilight {
  98 + my($dest, $text, $stripped) = @_;
  99 + my $server = $dest->{server};
  100 +
  101 + if($dest->{level} & MSGLEVEL_HILIGHT) {
  102 + if($server->{usermode_away} == 1){
  103 + if(Irssi::settings_get_bool("boxcarirssi_general_hilight")){
  104 + send_noti("General Hilight - " . $stripped);
  105 + }
  106 + }
  107 + }
  108 +}
  109 +
  110 +Irssi::signal_add_last('message public', 'pubmsg');
  111 +Irssi::signal_add_last('message private', 'privmsg');
  112 +Irssi::signal_add_last('print text', 'genhilight');
... ...