Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The individual bots have to process URLs, since only they know where …
…to look for them
  • Loading branch information
MasterDuke17 committed Jul 14, 2016
1 parent 5e6290f commit d5a9296
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Perl6IRCBotable.pm
Expand Up @@ -88,12 +88,12 @@ sub process_url {

my $response = HTTP::Tiny->new->get($url); # $body is actually a url
if (not $response->{success}) {
return "$message->{who}:It looks like a URL, but for some reason I cannot download it"
. " (HTTP status-code is $response->{status})",;
return (0, "$message->{who}:It looks like a URL, but for some reason I cannot download it"
. " (HTTP status-code is $response->{status}).");
}
if ($response->{headers}->{'content-type'} ne 'text/plain; charset=utf-8') {
return "$message->{who}:It looks like a URL, but mime type is '$response->{headers}->{'content-type'}'"
. " while I was expecting 'text/plain; charset=utf-8'. I can only understand raw links, sorry.";
return (0, "$message->{who}:It looks like a URL, but mime type is '$response->{headers}->{'content-type'}'"
. " while I was expecting 'text/plain; charset=utf-8'. I can only understand raw links, sorry.");
}
my $body = decode_utf8($response->{content});
$self->say(
Expand All @@ -102,7 +102,7 @@ sub process_url {
who => $message->{who},
);

return $body;
return (1, $body);
}

sub upload_output {
Expand All @@ -125,13 +125,6 @@ sub said {
if ($message->{address} eq 'msg') {
return 'Sorry, it is too private here';
} else {
if ($body =~ m{ ^https?:// }x ) {
$body = $self->process_url($body, $message);
return $body if ($body =~ / ^$message->{who}: /x);
} else {
$body =~ s//\n/g;
}

my $response = $self->process_message($message, $body);
$response = $self->upload_output($response) if (length $response > 500);

Expand Down
11 changes: 11 additions & 0 deletions benchable.pl
Expand Up @@ -38,6 +38,17 @@ sub process_message {
my @commits = split(',', $1);
my $code = $2;

if ($code =~ m{ ^https?:// }x ) {
my ($succeeded, $response) = $self->process_url($code);
if ($succeeded) {
$code = $response;
} else {
return $response;
}
} else {
$code =~ s//\n/g;
}

my $filename = $self->write_code($code);

my %times;
Expand Down
11 changes: 11 additions & 0 deletions bisectable.pl
Expand Up @@ -51,6 +51,17 @@ sub process_message {
my $bad = $2 // $3 // 'HEAD';
my $code = $5;

if ($code =~ m{ ^https?:// }x ) {
my ($succeeded, $response) = $self->process_url($code);
if ($succeeded) {
$code = $response;
} else {
return $response;
}
} else {
$code =~ s//\n/g;
}

# convert to real ids so we can look up the builds
my $full_good = $self->to_full_commit($good);
return "Cannot find 'good' revision" unless defined $full_good;
Expand Down
11 changes: 11 additions & 0 deletions committable.pl
Expand Up @@ -37,6 +37,17 @@ sub process_message {
my @commits = split(',', $1);
my $code = $2;

if ($code =~ m{ ^https?:// }x ) {
my ($succeeded, $response) = $self->process_url($code);
if ($succeeded) {
$code = $response;
} else {
return $response;
}
} else {
$code =~ s//\n/g;
}

my $filename = $self->write_code($code);

for my $commit (@commits) {
Expand Down

0 comments on commit d5a9296

Please sign in to comment.