old_contents: from urllib.request import urlopen
  import json
  
  from cardinal.decorators import command, help
  
  URBANDICT_API_PREFIX = 'http://api.urbandictionary.com/v0/define?term='
  
  
  class UrbanDictPlugin:
      @command(['ud', 'urbandict'])
      @help('Returns the top Urban Dictionary definition for a given word.')
      @help('Syntax: .ud <word>')
      def get_ud(self, cardinal, user, channel, msg):
          try:
              word = msg.split(' ', 1)[1]
          except IndexError:
              cardinal.sendMsg(channel, 'Syntax: .ud <word>')
              return
  
          try:
              url = URBANDICT_API_PREFIX + word
              f = urlopen(url).read()
              data = json.loads(f)
  
              word_def = data['list'][0]['definition']
              link = data['list'][0]['permalink']
  
              response = 'UD for %s: %s (%s)' % (word, word_def, link)
  
              cardinal.sendMsg(channel, response)
          except Exception:
              cardinal.sendMsg(channel, "Could not retrieve definition for %s" % word)
  
  
  def setup():
      return UrbanDictPlugin()
  
new_contents: import logging
  
  from cardinal.decorators import command, help
  
  import requests
  
  URBANDICT_API_PREFIX = 'http://api.urbandictionary.com/v0/define'
  
  
  class UrbanDictPlugin:
      def __init__(self):
          self.logger = logging.getLogger(__name__)
  
      @command(['ud', 'urbandict'])
      @help('Returns the top Urban Dictionary definition for a given word.')
      @help('Syntax: .ud <word>')
      def get_ud(self, cardinal, user, channel, msg):
          try:
              word = msg.split(' ', 1)[1]
          except IndexError:
              cardinal.sendMsg(channel, 'Syntax: .ud <word>')
              return
  
          try:
              url = URBANDICT_API_PREFIX
              data = requests.get(url, params={'term': word}).json()
  
              entry = data['list'].pop(0)
  
              definition = entry['definition']
              thumbs_up = entry['thumbs_up']
              thumbs_down = entry['thumbs_down']
              link = entry['permalink']
  
              response = ' UD [%s] - %s [\u25b2%d|\u25bc%d] - %s' % (
                  word, definition, thumbs_up, thumbs_down, link
              )
  
              cardinal.sendMsg(channel, response)
          except Exception:
              self.logger.exception("Error with definition: %s", word)
              cardinal.sendMsg(channel, "Could not retrieve definition for %s" % word)
  
  
  def setup():
      return UrbanDictPlugin()
  
subject: Add upvotes/downvotes to urbandict plugin (closes #166)