pyircbot/pyircbot/modules/Urban.py

30 lines
1.0 KiB
Python
Raw Normal View History

2014-10-02 21:00:37 -07:00
#!/usr/bin/env python
"""
.. module:: Urban
2015-11-01 18:03:11 -08:00
:synopsis: Lookup from urban dictionary
2014-10-02 21:00:37 -07:00
.. moduleauthor:: Dave Pedu <dave@davepedu.com>
"""
2017-11-27 18:58:20 -08:00
from pyircbot.modulebase import ModuleBase, command
2017-12-03 23:18:33 -08:00
import requests
2017-11-27 18:58:20 -08:00
from pyircbot.modules.ModInfo import info
2014-10-02 21:00:37 -07:00
2017-01-01 14:59:01 -08:00
2014-10-02 21:00:37 -07:00
class Urban(ModuleBase):
2017-01-01 14:59:01 -08:00
2017-11-27 18:58:20 -08:00
@info("urban <term> lookup an urban dictionary definition", cmds=["urban", "u"])
@command("urban", "u")
def urban(self, msg, cmd):
2017-12-03 23:18:33 -08:00
definitions = requests.get("http://www.urbandictionary.com/iphone/search/define",
params={"term": cmd.args_str}).json()["list"]
2017-11-27 18:58:20 -08:00
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']))