added interaction with goonsay.com
This commit is contained in:
parent
24975bbf7e
commit
8b08a10afc
|
@ -1,10 +1,63 @@
|
||||||
from util import hook
|
import urllib2
|
||||||
|
import json
|
||||||
|
|
||||||
|
from util import hook
|
||||||
|
|
||||||
#Scaevolus: factormystic if you commit a re-enabled goonsay I'm
|
#Scaevolus: factormystic if you commit a re-enabled goonsay I'm
|
||||||
# going to revoke your commit access
|
# going to revoke your commit access
|
||||||
#@hook.command
|
#@hook.command
|
||||||
def goonsay(inp, say=None):
|
#def goonsay(inp, say=None):
|
||||||
say(' __________ /')
|
# say(' __________ /')
|
||||||
say('(--[. ]-[ .] /')
|
# say('(--[. ]-[ .] /')
|
||||||
say('(_______o__)')
|
# say('(_______o__)')
|
||||||
|
|
||||||
|
@hook.command
|
||||||
|
@hook.command('gs')
|
||||||
|
def goonsay(inp):
|
||||||
|
".gs/.goonsay <id|add [message]> -- Get's the goonsay.com result for <id> or "
|
||||||
|
"add a new :goonsay: to the database. If no arg it will get a random result."
|
||||||
|
|
||||||
|
url = "http://goonsay.com/api/goonsays"
|
||||||
|
|
||||||
|
req_headers = {
|
||||||
|
'User-Agent': 'Skybot/1.0 http://bitbucket.org/Scaevolus/skybot/',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
q = inp.split(' ', 1)
|
||||||
|
print q
|
||||||
|
|
||||||
|
if len(q) == 2:
|
||||||
|
cmd = q[0]
|
||||||
|
args = q[1]
|
||||||
|
|
||||||
|
if cmd == 'add':
|
||||||
|
try:
|
||||||
|
data = json.dumps({'text': args})
|
||||||
|
req = urllib2.Request('%s/' % (url,), data, req_headers)
|
||||||
|
j = json.loads(urllib2.urlopen(req).read())
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
return e
|
||||||
|
return '#%d - %s' % (j['id'], j['text'])
|
||||||
|
else:
|
||||||
|
return goonsay.__doc__
|
||||||
|
|
||||||
|
if len(inp):
|
||||||
|
try:
|
||||||
|
req = urllib2.Request('%s/%d/' % (url, int(inp)), None, req_headers)
|
||||||
|
j = json.loads(urllib2.urlopen(req).read())
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
if e.code == 410 or e.code == 404:
|
||||||
|
return 'There is no :goonsay: by that id'
|
||||||
|
return e
|
||||||
|
except ValueError:
|
||||||
|
return goonsay.__doc__
|
||||||
|
return '#%d - %s' % (j['id'], j['text'])
|
||||||
|
|
||||||
|
try:
|
||||||
|
req = urllib2.Request('%s/random/' % (url,), None, req_headers)
|
||||||
|
j = json.loads(urllib2.urlopen(req).read())
|
||||||
|
except urllib2.HTTPError, e:
|
||||||
|
return e
|
||||||
|
|
||||||
|
return '#%d - %s' % (j['id'], j['text'])
|
||||||
|
|
Loading…
Reference in New Issue