Replace more LWP::Simple with timeout-configuring LWP::UserAgent. Change the way...
authorpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Thu, 30 Oct 2008 19:54:50 +0000 (19:54 +0000)
committerpdbogen <pdbogen@088b83a4-0077-4247-935c-42ec02c2848b>
Thu, 30 Oct 2008 19:54:50 +0000 (19:54 +0000)
git-svn-id: https://www.cernu.us/~pdbogen/svn/destult2@75 088b83a4-0077-4247-935c-42ec02c2848b

commands.yaml

index 464c4e3..4519b50 100644 (file)
@@ -877,7 +877,6 @@ RSS: |-
   sub {
     use WWW::Shorten 'SnipURL';
     use XML::RSS;
-    use LWP::Simple;
     use Time::CTime;
   
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
@@ -907,7 +906,14 @@ RSS: |-
     }
     
     my $xml;
-    if( !( $xml = get( $url ) ) ) {
+    use LWP::UserAgent;
+    my $ua = LWP::UserAgent->new;
+    $ua->timeout(5);
+    my $req = HTTP::Request->new( GET => $url );
+    my $res = $ua->request( $req );
+    if( $res->is_success ) {
+      $xml = $res->content;
+    } else {
       $kernel->post( $src, $replypath, "Failed to fetch RSS feed from $url", $dest );
       return;
     }
@@ -1095,7 +1101,6 @@ REPLACE: |-
 
 FANDANGO: |-
   sub {
-    use LWP::Simple;
     use POSIX;
     
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
@@ -1138,7 +1143,17 @@ FANDANGO: |-
     }
     if( $#args == 0 ) {
       if( $args[0] =~ /^[0-9]{5}$/ ) {
-        my $site = get( 'http://www.fandango.com/TheaterListings.aspx?location='.$args[0] );
+        my $site
+        use LWP::UserAgent;
+        my $ua = LWP::UserAgent->new;
+        $ua->timeout(5);
+        my $req = HTTP::Request->new( GET =>  'http://www.fandango.com/TheaterListings.aspx?location='.$args[0] );
+        my $res = $ua->request( $req );
+        if( $res->is_success ) {
+          $site = $res->content;
+        } else {
+          $kernel->post( $src, $replypath, "Accessing Fandango page failed.", $dest );
+        }
         $site =~ s/&nbsp;/ /gi;
         my @lines = split( /\n/, $site );
         my @pages;
@@ -1460,12 +1475,13 @@ CLEARRSVP: |-
 GROUPHUG: |-
   sub {
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
+    my @hugs;
+
     use LWP::UserAgent;
     my $ua = LWP::UserAgent->new;
     $ua->timeout(5);
     my $req = HTTP::Request->new( GET => 'http://grouphug.us/random' );
     my $res = $ua->request( $req );
-    my @hugs;
     if( $res->is_success ) {
       my $content = $res->content;
       $content =~ s/[\n\r]//g;
@@ -1716,6 +1732,7 @@ KARMA: |-
 
 TITLE: |-
   sub {
+    use POE::Component::IRC::Common qw( :ALL );
     my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_;
     if( $what !~ /^https?:\/\/.+$/ ) {
       $kernel->post( $src, $replypath, "Usage: TITLE <URL>", $dest );
@@ -1735,9 +1752,11 @@ TITLE: |-
       if( $content =~ /<title>(.*?)<\/title>/si ) {
         use HTML::Entities;
         my $title = decode_entities( $1 );
-        $kernel->post( $src, $replypath, "Title: $title (".makeashorterlink( $what ).")", $dest );
+        $title =~ s/[[:space:]]+/ /gs;
+        $title =~ s/(^[[:space:]]*)|([[:space:]]*$)//gs;
+        $kernel->post( $src, $replypath, BOLD . makeashorterlink( $what ) . NORMAL . " ($title)", $dest );
       } else {
-        $kernel->post( $src, $replypath, "Title: None (".makeashorterlink( $what ).")", $dest );
+        $kernel->post( $src, $replypath, BOLD . makeashorterlink( $what ) . NORMAL, $dest );
       }
     }
   }