move commandparsing to utils.py, add error checking to default.cmd['load']
This commit is contained in:
parent
621aeee7a0
commit
47662c9eca
|
@ -1,9 +1,13 @@
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
def cmd(line, srv):
|
def cmd(line, srv):
|
||||||
splitted = line.params[1].split(' ')
|
command, params = utils.cmdparse(line)
|
||||||
command = splitted[0][1:]
|
|
||||||
if command == "load":
|
if command == "load":
|
||||||
srv.load_mod(splitted[1])
|
try:
|
||||||
utils.message(srv, line.params[0],
|
srv.load_mod(params[0])
|
||||||
"loaded: " + splitted[1])
|
except ModuleNotFoundError:
|
||||||
|
utils.message(srv, line.params[0],
|
||||||
|
"failed to load `" + params[0] + "'")
|
||||||
|
else:
|
||||||
|
utils.message(srv, line.params[0],
|
||||||
|
"loaded: `" + params[0] + "'")
|
||||||
|
|
|
@ -18,3 +18,12 @@ from irctokens import build
|
||||||
|
|
||||||
def message(srv, channel, msg):
|
def message(srv, channel, msg):
|
||||||
srv.send(build("PRIVMSG", [channel, msg]))
|
srv.send(build("PRIVMSG", [channel, msg]))
|
||||||
|
|
||||||
|
def cmdparse(line):
|
||||||
|
splitted = line.params[1].split(' ')
|
||||||
|
try: command = splitted[0][1:]
|
||||||
|
except IndexError: command = None
|
||||||
|
try: params = splitted[1:]
|
||||||
|
except IndexError: params = None
|
||||||
|
return (command, params)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue