51 command_error ('unknown valuetype %s, expected one of: degrees, radians (angle conversion), ' + |
52 command_error ('unknown valuetype %s, expected one of: degrees, radians (angle conversion), ' + |
52 'celsius, fahrenheit (temperature conversion)' % valuetype) |
53 'celsius, fahrenheit (temperature conversion)' % valuetype) |
53 |
54 |
54 def cmd_ud (bot, args, replyto, **rest): |
55 def cmd_ud (bot, args, replyto, **rest): |
55 try: |
56 try: |
56 url = 'http://api.urbandictionary.com/v0/define?term=%s' % ('%20'.join (args)) |
57 url = 'http://api.urbandictionary.com/v0/define?term=%s' % (args['term'].replace (' ', '%20')) |
57 response = urllib2.urlopen (url).read() |
58 response = urllib2.urlopen (url).read() |
58 data = json.loads (response) |
59 data = json.loads (response) |
59 |
60 |
60 if not 'list' in data \ |
61 if not 'list' in data \ |
61 or len(data['list']) == 0 \ |
62 or len(data['list']) == 0 \ |
65 |
66 |
66 word = data['list'][0]['word'] |
67 word = data['list'][0]['word'] |
67 definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ') |
68 definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ') |
68 up = data['list'][0]['thumbs_up'] |
69 up = data['list'][0]['thumbs_up'] |
69 down = data['list'][0]['thumbs_down'] |
70 down = data['list'][0]['thumbs_down'] |
70 bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % |
71 bot.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) |
71 (word, definition, up, down)) |
|
72 except Exception as e: |
72 except Exception as e: |
73 command_error ('Urban dictionary lookup failed: %s' % e) |
73 command_error ('Urban dictionary lookup failed: %s' % e) |