support type names of spec arguments
This commit is contained in:
parent
341b314104
commit
478223f88c
2 changed files with 28 additions and 21 deletions
|
@ -38,12 +38,12 @@ class Module(ModuleManager.BaseModule):
|
|||
n = 0
|
||||
error = None
|
||||
|
||||
if spec_type.name == "time" and args:
|
||||
if spec_type.type == "time" and args:
|
||||
time, _ = utils.parse.timed_args(args)
|
||||
chunk = time
|
||||
n = 1
|
||||
error = "Invalid timeframe"
|
||||
elif spec_type.name == "rchannel":
|
||||
elif spec_type.type == "rchannel":
|
||||
if channel:
|
||||
chunk = channel
|
||||
elif args:
|
||||
|
@ -53,41 +53,41 @@ class Module(ModuleManager.BaseModule):
|
|||
error = "No such channel"
|
||||
else:
|
||||
error = "No channel provided"
|
||||
elif spec_type.name == "channel" and args:
|
||||
elif spec_type.type == "channel" and args:
|
||||
if args[0] in server.channels:
|
||||
chunk = server.channels.get(args[0])
|
||||
n = 1
|
||||
error = "No such channel"
|
||||
elif spec_type.name == "cuser" and args:
|
||||
elif spec_type.type == "cuser" and args:
|
||||
tuser = server.get_user(args[0], create=False)
|
||||
if tuser and channel.has_user(tuser):
|
||||
chunk = tuser
|
||||
n = 1
|
||||
error = "That user is not in this channel"
|
||||
elif spec_type.name == "ruser":
|
||||
elif spec_type.type == "ruser":
|
||||
if args:
|
||||
chunk = server.get_user(args[0], create=False)
|
||||
n = 1
|
||||
else:
|
||||
chunk = user
|
||||
error = "No such user"
|
||||
elif spec_type.name == "user":
|
||||
elif spec_type.type == "user":
|
||||
if args:
|
||||
chunk = server.get_user(args[0], create=False)
|
||||
n = 1
|
||||
error = "No such user"
|
||||
else:
|
||||
error = "No user provided"
|
||||
elif spec_type.name == "ouser" and args:
|
||||
elif spec_type.type == "ouser" and args:
|
||||
if server.has_user_id(args[0]):
|
||||
chunk = server.get_user(args[0])
|
||||
n = 1
|
||||
error = "Unknown nickname"
|
||||
elif spec_type.name == "word":
|
||||
elif spec_type.type == "word":
|
||||
if args:
|
||||
chunk = args[0]
|
||||
n = 1
|
||||
elif spec_type.name == "...":
|
||||
elif spec_type.type == "...":
|
||||
if args:
|
||||
chunk = " ".join(args)
|
||||
n = max(1, len(args))
|
||||
|
|
|
@ -157,7 +157,8 @@ def format_token_replace(s: str, vars: typing.Dict[str, str],
|
|||
return s
|
||||
|
||||
class ArgumentSpecType(object):
|
||||
def __init__(self, name: str, exported: str):
|
||||
def __init__(self, type_name: str, name: str, exported: str):
|
||||
self.type = type_name
|
||||
self.name = name
|
||||
self.exported = exported
|
||||
|
||||
|
@ -168,17 +169,23 @@ class ArgumentSpec(object):
|
|||
|
||||
def argument_spec(spec: str) -> typing.List[ArgumentSpec]:
|
||||
out: typing.List[ArgumentSpec] = []
|
||||
for type_names_str in spec.split(" "):
|
||||
optional = type_names_str[0] == "?"
|
||||
type_names_str = type_names_str[1:]
|
||||
for spec_argument in spec.split(" "):
|
||||
optional = spec_argument[0] == "?"
|
||||
|
||||
spec_types: typing.List[ArgumentSpecType] = []
|
||||
for type_name in type_names_str.split("|"):
|
||||
exported_name = ""
|
||||
if "~" in type_name:
|
||||
exported_name = type_name
|
||||
type_name = type_name.replace("~", "", 1)
|
||||
argument_types: typing.List[ArgumentSpecType] = []
|
||||
for argument_type in spec_argument[1:].split("|"):
|
||||
exported = ""
|
||||
if "~" in argument_type:
|
||||
exported = argument_type.split("~", 1)[1]
|
||||
argument_type = argument_type.replace("~", "", 1)
|
||||
|
||||
spec_types.append(ArgumentSpecType(type_name, exported_name))
|
||||
out.append(ArgumentSpec(optional, spec_types))
|
||||
argument_type_name = argument_type
|
||||
name_end = argument_type.find(">")
|
||||
if argument_type[0] == "<" and name_end > 0:
|
||||
argument_type_name = argument_type[1:name_end]
|
||||
argument_type = argument_type[name_end+1:]
|
||||
|
||||
argument_types.append(ArgumentSpecType(argument_type,
|
||||
argument_type_name, exported))
|
||||
out.append(ArgumentSpec(optional, argument_types))
|
||||
return out
|
||||
|
|
Loading…
Reference in a new issue