From: Matt Mullins Date: Sun, 18 Dec 2011 01:12:18 +0000 (-0800) Subject: Fixed QDB.us support X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=HEAD;p=destult.git Fixed QDB.us support * QDB.us was returning the iPhone random page rather than the requested quote without setting a URL * Changed page parsing to match actual results --- diff --git a/commands.yaml b/commands.yaml index 0b9bf10..017f0f1 100644 --- a/commands.yaml +++ b/commands.yaml @@ -851,46 +851,42 @@ BASH: |- QDB: |- sub { my( $kernel, $heap, $who, $what, $src, $dest, $replypath ) = @_; - + unless( $what =~ /^([0-9]+)|(random)$/ ) { $kernel->post( $src, $replypath, "Quote # should be a postive integer.", $dest ); return; } use LWP::UserAgent; - my $ua = LWP::UserAgent->new; + my $ua = LWP::UserAgent->new( agent => "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0" ); $ua->timeout(5); my $req = HTTP::Request->new( GET => 'http://qdb.us/?'.$what ); my $res = $ua->request( $req ); my @quotes; - if( $res->is_success ) { + if( $res->is_success or $res->code == "404" ) { my $content = $res->content; $content =~ s/[\n\r]//g; - - if( $content =~ s/]*?class="quote">(.*?)<\/table>//i ) { - my $table = $1; - my( $num, $body ); - while( $table =~ s/]*>(.*?)<\/tr>//i ) { - my $text = $1; - $text =~ s/
/\n/gi; - $text =~ s/<[^>]*>//gi; - $text =~ s/<//gi; - $text =~ s/&/&/gi; - $text =~ s/"/"/gi; - $text =~ s/ / /gi; - if( $text =~ /^(#[0-9]+)/ ) { - $num = $1; - } elsif( $text eq "-+" ) { - if( defined $num && defined $body ) { - push @quotes, [$num, $body]; - } - undef $num; - undef $body; - } else { - $body = $text; - } + + while( $content =~ s/]*?class=qt id=qt(\d+)>(.*?)<\/span>//i ) { + my $num = $1; + my $text = $2; + my $body; + $text =~ s/
/\n/gi; + $text =~ s/<[^>]*>//gi; + $text =~ s/<//gi; + $text =~ s/&/&/gi; + $text =~ s/"/"/gi; + $text =~ s/ / /gi; + + $body = $text; + if( defined $num && defined $body ) { + push @quotes, [$num, $body]; } + undef $num; + undef $body; + } + if( $#quotes > -1 ) { my $quote = $quotes[ int(rand($#quotes+1)) ]; $kernel->post( $src, $replypath, $quote->[0].":\n".$quote->[1], $dest ); } else {