add ruser/rchannel (r for relevant) to command_spec.py

This commit is contained in:
jesopo 2020-01-24 15:29:13 +00:00
parent 52c3cab627
commit 4e2f463d39

View file

@ -1,7 +1,7 @@
from src import ModuleManager, utils from src import ModuleManager, utils
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _spec_chunk(self, server, channel, types, args): def _spec_chunk(self, server, channel, user, types, args):
options = [] options = []
first_error = None first_error = None
for type in types: for type in types:
@ -14,17 +14,32 @@ class Module(ModuleManager.BaseModule):
chunk = time chunk = time
n = 1 n = 1
error = "Invalid timeframe" error = "Invalid timeframe"
elif type == "rchannel":
if channel:
chunk = channel
else:
n = 1
if args[0] in server.channels:
chunk = server.channels.get(args[0])
error = "No such channel"
elif type == "channel" and args: elif type == "channel" and args:
if args[0] in server.channels: if args[0] in server.channels:
chunk = server.channels.get(args[0]) chunk = server.channels.get(args[0])
n = 1 n = 1
error = "No such channel" error = "No such channel"
elif type == "cuser" and args: elif type == "cuser" and args:
user = server.get_user(args[0], create=False) tuser = server.get_user(args[0], create=False)
if user and channel.has_user(user): if tuser and channel.has_user(tuser):
chunk = user chunk = tuser
n = 1 n = 1
error = "That user is not in this channel" error = "That user is not in this channel"
elif type == "ruser":
if args:
chunk = server.get_user(args[0], create=False)
n = 1
else:
chunk = user
error = "No such user"
elif type == "user" and args: elif type == "user" and args:
chunk = server.get_user(args[0], create=False) chunk = server.get_user(args[0], create=False)
n = 1 n = 1
@ -45,6 +60,7 @@ class Module(ModuleManager.BaseModule):
if not spec == None: if not spec == None:
server = event["server"] server = event["server"]
channel = event["target"] if event["is_channel"] else None channel = event["target"] if event["is_channel"] else None
user = event["user"]
args = event["args_split"].copy() args = event["args_split"].copy()
out = [] out = []
@ -52,7 +68,7 @@ class Module(ModuleManager.BaseModule):
types = word[1:].split("|") types = word[1:].split("|")
optional = word[0] == "?" optional = word[0] == "?"
options = self._spec_chunk(server, channel, types, args) options = self._spec_chunk(server, channel, user, types, args)
found = None found = None
first_error = None first_error = None