2016-03-30 18:31:23 +00:00
|
|
|
#--require-config wordnik-api-key
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
import Utils
|
|
|
|
|
|
|
|
URL_WORDNIK = "http://api.wordnik.com:80/v4/word.json/%s/definitions"
|
|
|
|
|
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2016-03-29 11:56:58 +00:00
|
|
|
self.bot = bot
|
2018-08-31 11:55:52 +00:00
|
|
|
events.on("received").on("command").on("define").hook(
|
2016-04-06 11:02:44 +00:00
|
|
|
self.define, help="Define a provided term",
|
|
|
|
usage="<phrase>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def define(self, event):
|
|
|
|
if event["args"]:
|
|
|
|
word = event["args"]
|
|
|
|
else:
|
2018-08-28 11:23:57 +00:00
|
|
|
word = event["buffer"].get(from_self=False)
|
2016-03-29 11:56:58 +00:00
|
|
|
page = Utils.get_url(URL_WORDNIK % event["args"], get_params={
|
|
|
|
"useCanonical": "true", "limit": 1,
|
|
|
|
"sourceDictionaries": "wiktionary", "api_key": self.bot.config[
|
|
|
|
"wordnik-api-key"]}, json=True)
|
|
|
|
if page:
|
|
|
|
if len(page):
|
|
|
|
event["stdout"].write("%s: %s" % (page[0]["word"],
|
|
|
|
page[0]["text"]))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("No definitions found")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Failed to load results")
|