Commit 4569dd1634aa4b3f5cb4730303e461b83aa62d48

Authored by Caesar Ahlenhed
1 parent 52114ad3

Added debug mode, version 0.6

Showing 1 changed file with 25 additions and 4 deletions   Show diff stats
prowl.pl
... ... @@ -22,6 +22,7 @@ use warnings;
22 22 # comma separated list of
23 23 # network tags that should
24 24 # be ignored.
  25 +#/set pushover_debug ON/OFF # Debug mode.
25 26 #
26 27 # "General hilight" basically referrs to ALL the hilights you have
27 28 # added manually in irssi, if many, it can get really bloated if
... ... @@ -45,8 +46,9 @@ use Irssi::Irc;
45 46 use vars qw($VERSION %IRSSI);
46 47  
47 48 use LWP::UserAgent;
  49 +use Data::Dumper;
48 50  
49   -$VERSION = "0.5";
  51 +$VERSION = "0.6";
50 52  
51 53 %IRSSI = (
52 54 authors => "Caesar 'sniker' Ahlenhed",
... ... @@ -55,7 +57,7 @@ $VERSION = "0.5";
55 57 description => "Sends prowlnotifcations when away",
56 58 license => "GPLv2",
57 59 url => "http://sniker.codebase.nu",
58   - changed => "Mon Jun 23 17:14:23 CEST 2014",
  60 + changed => "Sun Jan 25 18:40:23 CET 2015",
59 61 );
60 62  
61 63 # Configuration settings and default values.
... ... @@ -65,6 +67,7 @@ Irssi::settings_add_str("prowl", "prowl_priority_channel", 0);
65 67 Irssi::settings_add_str("prowl", "prowl_priority_pm", 0);
66 68 Irssi::settings_add_str("prowl", "prowl_priority_general", 0);
67 69 Irssi::settings_add_str("prowl", "prowl_ignore_nettag", "");
  70 +Irssi::settings_add_bool("prowl", "prowl_debug", 0);
68 71  
69 72 # The whole "send_noti" function is pretty much taken from the prowl example script.
70 73 sub send_noti {
... ... @@ -93,7 +96,7 @@ sub send_noti {
93 96  
94 97 my ($userAgent, $request, $response, $requestURL);
95 98 $userAgent = LWP::UserAgent->new;
96   - $userAgent->agent("ProwlScript/0.5");
  99 + $userAgent->agent("ProwlScript/0.6");
97 100  
98 101 $requestURL = sprintf("https://prowl.weks.net/publicapi/add?apikey=%s&application=%s&event=%s&description=%s&priority=%d",
99 102 $options{'apikey'},
... ... @@ -107,10 +110,28 @@ sub send_noti {
107 110  
108 111 if ($response->is_success) {
109 112 # I guess it worked, eh?
  113 + # Debug:
  114 + if(Irssi::settings_get_bool("prowl_debug")){
  115 + Irssi::print($IRSSI{'name'} . " DEBUG:");
  116 + Irssi::print("What was posted: " . Dumper(\%options));
  117 + Irssi::print("HTTP Code: " . $response->status_line());
  118 + Irssi::print("Notification posted/Response: " . $response->content);
  119 + }
110 120 } elsif ($response->code == 401) {
  121 + if(Irssi::settings_get_bool("prowl_debug")){
  122 + Irssi::print($IRSSI{'name'} . " DEBUG:");
  123 + Irssi::print("What was posted: " . Dumper(\%options));
  124 + Irssi::print("HTTP Code: " . $response->status_line());
  125 + Irssi::print("Notification posted/Response: " . $response->content);
  126 + }
111 127 Irssi::print( "Notification not posted: incorrect API key.");
112 128 } else {
113   - Irssi::print("Notification not posted: " . $response->content);
  129 + if(Irssi::settings_get_bool("prowl_debug")){
  130 + Irssi::print($IRSSI{'name'} . " DEBUG:");
  131 + Irssi::print("What was posted: " . Dumper(\%options));
  132 + Irssi::print("HTTP Code: " . $response->status_line());
  133 + }
  134 + Irssi::print("Notification not posted/Response: " . $response->content);
114 135 }
115 136 }
116 137  
... ...