-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgiphy.pl
38 lines (28 loc) · 918 Bytes
/
giphy.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#use strict;
use URI::Escape;
use HTTP::Tiny;
use vars qw($VERSION %IRSSI);
use JSON::PP;
use Data::Dumper;
use Irssi;
my $json = JSON::PP->new->allow_nonref;
$VERSION = '0.0.2';
%IRSSI = (
name => 'giphy',
authors => 'Lee Helpingstine',
contact => '[email protected]',
description => 'Searches giphy to emulate slack\'s /giphy command.'
);
my $api_key = 'dc6zaTOxFJmzC';
sub searchGiphy {
my ($search, $server, $dest) = @_;
my $url = "http://api.giphy.com/v1/gifs/search?api_key=dc6zaTOxFJmzC&limit=10&q=" . uri_escape($search);
my $http = HTTP::Tiny->new();
my $response = $http->get($url);
my $obj = $json->decode($response->{content});
my $link = $obj->{data}[int(rand(scalar(keys $obj->{data})))]->{url};
if ($dest->{type} eq "CHANNEL" || $dest->{type} eq "QUERY") {
$dest->command("/msg " . $dest->{name} . " " . $link);
}
}
Irssi::command_bind('giphy', \&searchGiphy);