change !ud index syntax and put it in help text
This commit is contained in:
parent
208eb9cd47
commit
c488fb2a82
1 changed files with 9 additions and 8 deletions
|
@ -1,10 +1,8 @@
|
||||||
#--depends-on commands
|
#--depends-on commands
|
||||||
|
|
||||||
import json, re
|
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
|
URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define"
|
||||||
REGEX_DEFNUMBER = re.compile("-n ?(\d+) ")
|
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
_name = "UrbanDictionary"
|
_name = "UrbanDictionary"
|
||||||
|
@ -14,14 +12,17 @@ class Module(ModuleManager.BaseModule):
|
||||||
def ud(self, event):
|
def ud(self, event):
|
||||||
"""
|
"""
|
||||||
:help: Get the definition of a provided term from Urban Dictionary
|
:help: Get the definition of a provided term from Urban Dictionary
|
||||||
:usage: <term>
|
:usage: <term> [#index]
|
||||||
"""
|
"""
|
||||||
term = event["args"]
|
|
||||||
number = 1
|
number = 1
|
||||||
match = re.match(REGEX_DEFNUMBER, term)
|
term = event["args_split"]
|
||||||
if match:
|
if (event["args_split"][-1].startswith("#") and
|
||||||
number = int(match.group(1))
|
len(event["args_split"]) > 1 and
|
||||||
term = term.split(" ", 1)[1]
|
event["args_split"][-1][1:].isdigit()):
|
||||||
|
number = int(event["args_split"][-1][1:])
|
||||||
|
term = term[:-1]
|
||||||
|
term = " ".join(term)
|
||||||
|
|
||||||
page = utils.http.request(URL_URBANDICTIONARY,
|
page = utils.http.request(URL_URBANDICTIONARY,
|
||||||
get_params={"term": term}, json=True)
|
get_params={"term": term}, json=True)
|
||||||
if page:
|
if page:
|
||||||
|
|
Loading…
Reference in a new issue