2019-05-25 21:40:06 +01:00
|
|
|
#--depends-on commands
|
2016-03-30 19:31:23 +01:00
|
|
|
#--require-config bighugethesaurus-api-key
|
|
|
|
|
2018-10-03 13:22:37 +01:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 12:56:58 +01:00
|
|
|
|
|
|
|
URL_THESAURUS = "http://words.bighugelabs.com/api/2/%s/%s/json"
|
|
|
|
|
2018-09-27 11:46:10 +01:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-06-26 10:59:03 +01:00
|
|
|
@utils.hook("received.command.synonym", min_args=1)
|
|
|
|
@utils.hook("received.command.antonym", min_args=1)
|
2016-03-29 12:56:58 +01:00
|
|
|
def thesaurus(self, event):
|
2018-09-26 18:27:17 +01:00
|
|
|
"""
|
2018-09-30 17:29:09 +01:00
|
|
|
:help: Get synonyms/antonyms for a provided phrase
|
|
|
|
:usage: <word> [type]
|
2018-09-26 18:27:17 +01:00
|
|
|
"""
|
2016-03-29 12:56:58 +01:00
|
|
|
phrase = event["args_split"][0]
|
2018-12-11 22:26:38 +00:00
|
|
|
page = utils.http.request(URL_THESAURUS % (self.bot.config[
|
2016-03-29 12:56:58 +01:00
|
|
|
"bighugethesaurus-api-key"], phrase), json=True)
|
|
|
|
syn_ant = event["command"][:3]
|
|
|
|
if page:
|
2018-12-16 11:03:36 +00:00
|
|
|
if page.code == 404:
|
|
|
|
raise utils.EventError("Word not found")
|
|
|
|
|
2016-03-29 12:56:58 +01:00
|
|
|
if not len(event["args_split"]) > 1:
|
|
|
|
word_types = []
|
2018-12-11 22:26:38 +00:00
|
|
|
for word_type in page.data.keys():
|
|
|
|
if syn_ant in page.data[word_type]:
|
2016-03-29 12:56:58 +01:00
|
|
|
word_types.append(word_type)
|
|
|
|
if word_types:
|
|
|
|
word_types = sorted(word_types)
|
|
|
|
event["stdout"].write(
|
|
|
|
"Available categories for %s: %s" % (
|
|
|
|
phrase, ", ".join(word_types)))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("No categories available")
|
|
|
|
else:
|
|
|
|
category = event["args_split"][1].lower()
|
2018-12-11 22:26:38 +00:00
|
|
|
if category in page.data:
|
|
|
|
if syn_ant in page.data[category]:
|
2016-03-29 12:56:58 +01:00
|
|
|
event["stdout"].write("%ss for %s: %s" % (
|
|
|
|
event["command"].title(), phrase, ", ".join(
|
2018-12-11 22:26:38 +00:00
|
|
|
page.data[category][syn_ant])))
|
2016-03-29 12:56:58 +01:00
|
|
|
else:
|
|
|
|
event["stderr"].write("No %ss for %s" % (
|
|
|
|
event["command"], phrase))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Category not found")
|
|
|
|
else:
|
2018-10-20 20:51:29 +01:00
|
|
|
raise utils.EventsResultsError()
|