From 47662c9ecaafa92ebbfd6e880b619aa6568585d9 Mon Sep 17 00:00:00 2001 From: randomuser Date: Mon, 2 Aug 2021 21:54:49 -0500 Subject: [PATCH] move commandparsing to utils.py, add error checking to default.cmd['load'] --- mods/default.py | 14 +++++++++----- mods/utils.py | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mods/default.py b/mods/default.py index 8eea45a..6c382b3 100644 --- a/mods/default.py +++ b/mods/default.py @@ -1,9 +1,13 @@ import utils def cmd(line, srv): - splitted = line.params[1].split(' ') - command = splitted[0][1:] + command, params = utils.cmdparse(line) if command == "load": - srv.load_mod(splitted[1]) - utils.message(srv, line.params[0], - "loaded: " + splitted[1]) + try: + srv.load_mod(params[0]) + except ModuleNotFoundError: + utils.message(srv, line.params[0], + "failed to load `" + params[0] + "'") + else: + utils.message(srv, line.params[0], + "loaded: `" + params[0] + "'") diff --git a/mods/utils.py b/mods/utils.py index ee1fdcc..16f8342 100644 --- a/mods/utils.py +++ b/mods/utils.py @@ -18,3 +18,12 @@ from irctokens import build def message(srv, 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) +