[ddg] Dusting + !safeoff handling
This commit is contained in:
parent
787a5fd3da
commit
b75c54419f
2 changed files with 23 additions and 20 deletions
|
|
@ -5,6 +5,7 @@
|
|||
import imp
|
||||
|
||||
from nemubot import context
|
||||
from nemubot.exception import IRCException
|
||||
from nemubot.hooks import hook
|
||||
|
||||
nemubotversion = 3.4
|
||||
|
|
@ -16,25 +17,26 @@ from . import UrbanDictionnary
|
|||
|
||||
@hook("cmd_hook", "define")
|
||||
def define(msg):
|
||||
if len(msg.cmds) <= 1:
|
||||
return Response("Indicate a term to define",
|
||||
msg.channel, nick=msg.nick)
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate a term to define")
|
||||
|
||||
s = DDGSearch.DDGSearch(' '.join(msg.cmds[1:]))
|
||||
s = DDGSearch.DDGSearch(' '.join(msg.args))
|
||||
|
||||
res = Response(channel=msg.channel)
|
||||
return Response(s.definition, channel=msg.channel)
|
||||
|
||||
res.append_message(s.definition)
|
||||
|
||||
return res
|
||||
|
||||
@hook("cmd_hook", "search")
|
||||
def search(msg):
|
||||
if len(msg.cmds) <= 1:
|
||||
return Response("Indicate a term to search",
|
||||
msg.channel, nick=msg.nick)
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate a term to search")
|
||||
|
||||
s = DDGSearch.DDGSearch(' '.join(msg.cmds[1:]))
|
||||
if "!safeoff" in msg.args:
|
||||
msg.args.remove("!safeoff")
|
||||
safeoff = True
|
||||
else:
|
||||
safeoff = False
|
||||
|
||||
s = DDGSearch.DDGSearch(' '.join(msg.args), safeoff)
|
||||
|
||||
res = Response(channel=msg.channel, nomore="No more results",
|
||||
count=" (%d more results)")
|
||||
|
|
@ -47,21 +49,22 @@ def search(msg):
|
|||
for rt in s.relatedTopics:
|
||||
res.append_message(rt)
|
||||
|
||||
res.append_message(s.definition)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@hook("cmd_hook", "urbandictionnary")
|
||||
def udsearch(msg):
|
||||
if len(msg.cmds) <= 1:
|
||||
return Response("Indicate a term to search",
|
||||
msg.channel, nick=msg.nick)
|
||||
if not len(msg.args):
|
||||
raise IRCException("Indicate a term to search")
|
||||
|
||||
s = UrbanDictionnary.UrbanDictionnary(' '.join(msg.cmds[1:]))
|
||||
s = UrbanDictionnary.UrbanDictionnary(' '.join(msg.args))
|
||||
|
||||
res = Response(channel=msg.channel, nomore="No more results",
|
||||
count=" (%d more definitions)")
|
||||
|
||||
for d in s.definitions:
|
||||
res.append_message(d)
|
||||
res.append_message(d.replace("\n", " "))
|
||||
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue