2010-03-21 02:58:01 +00:00
|
|
|
import urllib2
|
|
|
|
import json
|
2010-01-17 04:24:36 +00:00
|
|
|
|
2010-03-21 02:58:01 +00:00
|
|
|
from util import hook
|
2010-03-01 02:32:41 +00:00
|
|
|
|
|
|
|
#Scaevolus: factormystic if you commit a re-enabled goonsay I'm
|
|
|
|
# going to revoke your commit access
|
2010-01-17 04:24:36 +00:00
|
|
|
#@hook.command
|
2010-03-21 02:58:01 +00:00
|
|
|
#def goonsay(inp, say=None):
|
|
|
|
# say(' __________ /')
|
|
|
|
# say('(--[. ]-[ .] /')
|
|
|
|
# say('(_______o__)')
|
|
|
|
|
2010-03-27 08:42:27 +00:00
|
|
|
|
2010-03-21 02:58:01 +00:00
|
|
|
@hook.command
|
|
|
|
@hook.command('gs')
|
|
|
|
def goonsay(inp):
|
2010-03-27 08:42:27 +00:00
|
|
|
".gs/.goonsay <id|add [message]> -- Get's the goonsay.com result for <id> "
|
|
|
|
" or add a new :goonsay: to the database. With no args, random result."
|
2010-03-21 02:58:01 +00:00
|
|
|
|
|
|
|
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:
|
2010-03-27 08:42:27 +00:00
|
|
|
req = urllib2.Request('%s/%d/' % (url, int(inp)), None,
|
|
|
|
req_headers)
|
2010-03-21 02:58:01 +00:00
|
|
|
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'])
|