about summary refs log tree commit diff
path: root/command.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-05 22:09:29 -0500
committerJune McEnroe <june@causal.agency>2020-02-05 22:09:29 -0500
commitb2cf8733048029354aeb794b14dd71d1bbb0b72d (patch)
tree6f9c94de4233c7155e1001a155ea6a553de72217 /command.c
parentAdd /quit (diff)
downloadcatgirl-b2cf8733048029354aeb794b14dd71d1bbb0b72d.tar.gz
catgirl-b2cf8733048029354aeb794b14dd71d1bbb0b72d.zip
Add /window
Diffstat (limited to 'command.c')
-rw-r--r--command.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/command.c b/command.c
index 7fb98af..8471214 100644
--- a/command.c
+++ b/command.c
@@ -57,9 +57,16 @@ static void commandMe(size_t id, char *params) {
 }
 
 static void commandQuit(size_t id, char *params) {
+	(void)id;
 	set(&self.quit, (params ? params : "Goodbye"));
 }
 
+static void commandWindow(size_t id, char *params) {
+	(void)id;
+	if (!params) return;
+	uiShowNum(strtoul(params, NULL, 10));
+}
+
 static const struct Handler {
 	const char *cmd;
 	Command *fn;
@@ -68,6 +75,7 @@ static const struct Handler {
 	{ "/notice", commandNotice },
 	{ "/quit", commandQuit },
 	{ "/quote", commandQuote },
+	{ "/window", commandWindow },
 };
 
 static int compar(const void *cmd, const void *_handler) {
@@ -97,21 +105,21 @@ const char *commandIsAction(size_t id, const char *input) {
 }
 
 void command(size_t id, char *input) {
-	if (id == Debug) {
+	if (id == Debug && input[0] != '/') {
 		commandQuote(id, input);
-		return;
-	}
-	if (commandIsPrivmsg(id, input)) {
+	} else if (commandIsPrivmsg(id, input)) {
 		commandPrivmsg(id, input);
-		return;
-	}
-	char *cmd = strsep(&input, " ");
-	const struct Handler *handler = bsearch(
-		cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
-	);
-	if (handler) {
-		handler->fn(id, input);
+	} else if (input[0] == '/' && isdigit(input[1])) {
+		commandWindow(id, &input[1]);
 	} else {
-		uiFormat(id, Hot, NULL, "No such command %s", cmd);
+		char *cmd = strsep(&input, " ");
+		const struct Handler *handler = bsearch(
+			cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
+		);
+		if (handler) {
+			handler->fn(id, input);
+		} else {
+			uiFormat(id, Hot, NULL, "No such command %s", cmd);
+		}
 	}
 }