move commandparsing to utils.py, add error checking to default.cmd['load']

This commit is contained in:
randomuser 2021-08-02 21:54:49 -05:00
parent 621aeee7a0
commit 47662c9eca
2 changed files with 18 additions and 5 deletions

View File

@ -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] + "'")

View File

@ -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)