Skip to content

Instantly share code, notes, and snippets.

@thatfunkymunki
Last active July 2, 2020 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatfunkymunki/b8028d4f2313612b36e2c1a44230809f to your computer and use it in GitHub Desktop.
Save thatfunkymunki/b8028d4f2313612b36e2c1a44230809f to your computer and use it in GitHub Desktop.
use strict;
use Irssi;
use LWP::UserAgent;
our $VERSION = '1.0';
our %IRSSI = (
authors => 'munki',
contact => 'thatfunkymunki@gmail.com',
name=> 'troll-as-a-service',
description=> 'spits out a string from my webapp',
license=>'MIT',
url=>'http://github.com/thatfunkymunki',
changed=>'05-23-2017 2005'
);
sub troll{
my ($data, $server, $witem) = @_;
my $troll = get_troll (($data =~ /lower/ ? "1" : "0" ), ($data =~ /space/ ? "1" : "0" ));
my $lower = $data =~ /lower/;
my $space = $data =~ /space/;
$witem->command("MSG $witem->{name} $troll");
}
sub get_troll {
my ($lower, $space) = @_;
my $ua = LWP::UserAgent->new;
$ua->agent("irssi/0.1");
my $request = HTTP::Request->new(GET => "http://troll-as-a-service.herokuapp.com/troll?num=20".($lower ? "&downcase=true" : "").($space ? "&space=true" : "" ));
my $result = $ua->request($request);
return substr($result->content, 0, 400);
}
Irssi::command_bind ( troll => \&troll );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment