Skip to content

Commit

Permalink
Port the QMark plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
grickit committed Aug 17, 2014
1 parent 123177b commit 0972491
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/IRC/Freenode/Output.pm
Expand Up @@ -35,6 +35,7 @@ sub new {
my $self = {};

$self->{'core'} = shift;
$self->{'lines_sent'} = 0;

bless($self,$class);
return $self;
Expand Down Expand Up @@ -139,6 +140,7 @@ sub parse {
return '';
}

$self->{'lines_sent'}++;
return 1;
}

Expand Down
42 changes: 42 additions & 0 deletions modules/PluginParser/Internet/QMarkAPI.pm
@@ -0,0 +1,42 @@
package PluginParser::Internet::QMarkAPI;
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(match);

sub match {
my ($self,$core) = @_;
if($core->{'receiver_nick'} ne $core->{'botname'}) { return ''; }
if($core->{'event'} ne 'on_public_message' and $core->{'event'} ne 'on_private_message') { return ''; }


if($core->{'output'}->{'lines_sent'} == 0) {
return qmark($core,$core->{'receiver_chan'},$core->{'target'},$core->{'message'});
}


return '';
}

sub qmark {
my ($core,$chan,$target,$message) = @_;

my $request = LWP::UserAgent->new;
$request->timeout(60);
$request->env_proxy;
$request->agent('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)');
$request->max_size('1024000');
$request->parse_head(0);
my $content = $request->post('http://qmark.tk/qmai.php',{'q' => $message})->decoded_content;
$content =~ s/[\r\n]+/ /g;

if($content !~ /<html>/) {
$core->{'output'}->parse("MESSAGE>${chan}>${target}: ${content}");
}
else {
$core->{'output'}->parse("MESSAGE>${chan}>${target}: f**k I'm sooo confused %)");
$core->log_error("Weird QMark output: ${content}");
}
}
4 changes: 3 additions & 1 deletion parsers/plugin_parser2/example.pl
Expand Up @@ -74,4 +74,6 @@ sub module_load {
module_load('PluginParser::Games::Buttcoins');
module_load('PluginParser::Games::Dice');
module_load('PluginParser::Games::Eightball');
module_load('PluginParser::Subreddit');
module_load('PluginParser::Subreddit');

module_load('PluginParser::Internet::QMarkAPI');

0 comments on commit 0972491

Please sign in to comment.