summaryrefslogtreecommitdiffstats
path: root/wmd
diff options
context:
space:
mode:
authorjason2014-04-23 15:21:30 -0600
committerjason2014-05-28 01:41:18 -0600
commit126f8a496be0b089e95cbbc357400fc90d6b8571 (patch)
tree150888d3b52fcbba7eb9940f88f938d78f4e6f96 /wmd
parent79614a5336e765b115de9a8c7effe970fde9e896 (diff)
downloadwarmachine-126f8a496be0b089e95cbbc357400fc90d6b8571.tar.gz
warmachine-126f8a496be0b089e95cbbc357400fc90d6b8571.zip
new giphy search
Diffstat (limited to 'wmd')
-rw-r--r--wmd/actions/giphy.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/wmd/actions/giphy.py b/wmd/actions/giphy.py
new file mode 100644
index 0000000..556e573
--- /dev/null
+++ b/wmd/actions/giphy.py
@@ -0,0 +1,32 @@
1__author__ = 'jason@zzq.org'
2__version__ = 1.0
3
4import urllib2
5import json as simplejson
6
7from wmd.actions import Action
8
9import settings
10
11
12class GiphySearch(Action):
13 def recv_msg(self, irc, obj_data):
14 args = obj_data.params.split(" ")
15 channel = args[0]
16 if channel == settings.NICKNAME:
17 channel = obj_data.get_username()
18
19 if "PRIVMSG" in obj_data.command and ":!gif" in args[1].lower():
20 search_string = " ".join(args[2:])
21 url = "http://api.giphy.com/v1/gifs/search?q=%s&api_key=dc6zaTOxFJmzC&limit=1" % \
22 (search_string.replace(" ", "%20"), )
23 req = urllib2.Request(url)
24 opener = urllib2.build_opener()
25 data = opener.open(req).read()
26
27 data = simplejson.loads(data)
28 try:
29 result = data['data'][0]['images']['original']['url']
30 irc.privmsg(channel, result)
31 except IndexError:
32 pass