[ddg] Split the module in two: ddg for search and urbandict for urbandictionnary
This commit is contained in:
parent
aca073faff
commit
2b96c32063
5 changed files with 175 additions and 171 deletions
37
modules/urbandict.py
Normal file
37
modules/urbandict.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""Search definition from urbandictionnary"""
|
||||
|
||||
# PYTHON STUFFS #######################################################
|
||||
|
||||
from urllib.parse import quote
|
||||
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.hooks import hook
|
||||
from nemubot.tools import web
|
||||
|
||||
from more import Response
|
||||
|
||||
# MODULE CORE #########################################################
|
||||
|
||||
def search(terms):
|
||||
return web.getJSON(
|
||||
"http://api.urbandictionary.com/v0/define?term=%s"
|
||||
% quote(' '.join(terms)))
|
||||
|
||||
|
||||
# MODULE INTERFACE ####################################################
|
||||
|
||||
@hook("cmd_hook", "urbandictionnary")
|
||||
def udsearch(msg):
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate a term to search")
|
||||
|
||||
s = search(msg.args)
|
||||
|
||||
res = Response(channel=msg.channel, nomore="No more results",
|
||||
count=" (%d more definitions)")
|
||||
|
||||
for i in s["list"]:
|
||||
res.append_message(i["definition"].replace("\n", " "),
|
||||
title=i["word"])
|
||||
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue