Awesome IRC bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.0 KiB

#!/usr/bin/env python
"""
.. module:: Urban
:synopsis: Lookup from urban dictionary
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
"""
from pyircbot.modulebase import ModuleBase, command
import requests
from pyircbot.modules.ModInfo import info
class Urban(ModuleBase):
@info("urban <term> lookup an urban dictionary definition", cmds=["urban", "u"])
@command("urban", "u")
def urban(self, msg, cmd):
definitions = requests.get("http://www.urbandictionary.com/iphone/search/define",
params={"term": cmd.args_str}).json()["list"]
if len(definitions) == 0:
self.bot.act_PRIVMSG(msg.args[0], "Urban definition: no results!")
else:
defstr = definitions[0]['definition'].replace('\n', ' ').replace('\r', '')
if len(defstr) > 360:
defstr = defstr[0:360] + "..."
self.bot.act_PRIVMSG(msg.args[0], "Urban definition: %s - http://urbanup.com/%s" %
(defstr, definitions[0]['defid']))