summary refs log tree commit diff
path: root/handle.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--handle.c127
1 files changed, 93 insertions, 34 deletions
diff --git a/handle.c b/handle.c
index adc8f59..71fab12 100644
--- a/handle.c
+++ b/handle.c
@@ -93,8 +93,7 @@ static bool isSelf(const char *nick, const char *user) {
 	return false;
 }
 
-static bool isPing(const char *nick, const char *user, const char *mesg) {
-	if (isSelf(nick, user)) return false;
+static bool isPing(const char *mesg) {
 	size_t len = strlen(self.nick);
 	const char *match = mesg;
 	while (NULL != (match = strcasestr(match, self.nick))) {
@@ -108,6 +107,13 @@ static bool isPing(const char *nick, const char *user, const char *mesg) {
 	return false;
 }
 
+static char *dequote(char *mesg) {
+	if (mesg[0] == '"') mesg = &mesg[1];
+	size_t len = strlen(mesg);
+	if (mesg[len - 1] == '"') mesg[len - 1] = '\0';
+	return mesg;
+}
+
 typedef void (*Handler)(char *prefix, char *params);
 
 static void handlePing(char *prefix, char *params) {
@@ -118,39 +124,46 @@ static void handlePing(char *prefix, char *params) {
 static void handleReplyErroneousNickname(char *prefix, char *params) {
 	char *mesg;
 	shift(prefix, NULL, NULL, NULL, params, 3, 0, NULL, NULL, &mesg);
-	uiLog(TAG_STATUS, L"You can't use that name here");
-	uiFmt(TAG_STATUS, "Sheriff says, \"%s\"", mesg);
-	uiLog(TAG_STATUS, L"Type /nick <name> to choose a new one");
+	// FIXME: Better formatting.
+	uiLog(TAG_STATUS, UI_HOT, L"You can't use that name here");
+	uiFmt(TAG_STATUS, UI_HOT, "Sheriff says, \"%s\"", mesg);
+	uiLog(TAG_STATUS, UI_HOT, L"Type /nick <name> to choose a new one");
 }
 
 static void handleReplyWelcome(char *prefix, char *params) {
 	char *nick;
 	shift(prefix, NULL, NULL, NULL, params, 1, 0, &nick);
+
 	if (strcmp(nick, self.nick)) selfNick(nick);
-	tabTouch(TAG_STATUS, self.nick);
 	if (self.join) ircFmt("JOIN %s\r\n", self.join);
-	uiLog(TAG_STATUS, L"You have arrived");
+	tabTouch(TAG_STATUS, self.nick);
+
+	uiLog(TAG_STATUS, UI_WARM, L"You have arrived");
 }
 
 static void handleReplyMOTD(char *prefix, char *params) {
 	char *mesg;
 	shift(prefix, NULL, NULL, NULL, params, 2, 0, NULL, &mesg);
 	if (mesg[0] == '-' && mesg[1] == ' ') mesg = &mesg[2];
+
 	urlScan(TAG_STATUS, mesg);
-	uiFmt(TAG_STATUS, "%s", mesg);
+	uiFmt(TAG_STATUS, UI_COLD, "%s", mesg);
 }
 
 static void handleJoin(char *prefix, char *params) {
 	char *nick, *user, *chan;
 	shift(prefix, &nick, &user, NULL, params, 1, 0, &chan);
 	struct Tag tag = tagFor(chan);
+
 	if (isSelf(nick, user)) {
 		tabTouch(TAG_NONE, chan);
 		uiViewTag(tag);
 	}
 	tabTouch(tag, nick);
+
 	uiFmt(
-		tag, "\3%d%s\3 arrives in \3%d%s\3",
+		tag, UI_COLD,
+		"\3%d%s\3 arrives in \3%d%s\3",
 		color(user), nick, color(chan), chan
 	);
 }
@@ -159,16 +172,24 @@ static void handlePart(char *prefix, char *params) {
 	char *nick, *user, *chan, *mesg;
 	shift(prefix, &nick, &user, NULL, params, 1, 1, &chan, &mesg);
 	struct Tag tag = tagFor(chan);
-	(void)(isSelf(nick, user) ? tabClear(tag) : tabRemove(tag, nick));
+
+	if (isSelf(nick, user)) {
+		tabClear(tag);
+	} else {
+		tabRemove(tag, nick);
+	}
+
 	if (mesg) {
 		urlScan(tag, mesg);
 		uiFmt(
-			tag, "\3%d%s\3 leaves \3%d%s\3, \"%s\"",
+			tag, UI_COLD,
+			"\3%d%s\3 leaves \3%d%s\3, \"%s\"",
 			color(user), nick, color(chan), chan, mesg
 		);
 	} else {
 		uiFmt(
-			tag, "\3%d%s\3 leaves \3%d%s\3",
+			tag, UI_COLD,
+			"\3%d%s\3 leaves \3%d%s\3",
 			color(user), nick, color(chan), chan
 		);
 	}
@@ -178,16 +199,26 @@ static void handleKick(char *prefix, char *params) {
 	char *nick, *user, *chan, *kick, *mesg;
 	shift(prefix, &nick, &user, NULL, params, 2, 1, &chan, &kick, &mesg);
 	struct Tag tag = tagFor(chan);
-	(void)(isSelf(nick, user) ? tabClear(tag) : tabRemove(tag, nick));
+	bool kicked = !strcmp(kick, self.nick);
+
+	if (kicked) {
+		tabClear(tag);
+	} else {
+		tabRemove(tag, kick);
+	}
+
 	if (mesg) {
 		urlScan(tag, mesg);
 		uiFmt(
-			tag, "\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3, \"%s\"",
-			color(user), nick, color(kick), kick, color(chan), chan, mesg
+			tag, (kicked ? UI_HOT : UI_COLD),
+			"\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3, \"%s\"",
+			color(user), nick, color(kick), kick, color(chan), chan,
+			dequote(mesg)
 		);
 	} else {
 		uiFmt(
-			tag, "\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3",
+			tag, (kicked ? UI_HOT : UI_COLD),
+			"\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3",
 			color(user), nick, color(kick), kick, color(chan), chan
 		);
 	}
@@ -196,18 +227,20 @@ static void handleKick(char *prefix, char *params) {
 static void handleQuit(char *prefix, char *params) {
 	char *nick, *user, *mesg;
 	shift(prefix, &nick, &user, NULL, params, 0, 1, &mesg);
-	char *quot = (mesg && mesg[0] == '"') ? "" : "\"";
+
 	struct Tag tag;
 	while (TAG_NONE.id != (tag = tabTag(nick)).id) {
 		tabRemove(tag, nick);
+
 		if (mesg) {
 			urlScan(tag, mesg);
 			uiFmt(
-				tag, "\3%d%s\3 leaves, %s%s%s",
-				color(user), nick, quot, mesg, quot
+				tag, UI_COLD,
+				"\3%d%s\3 leaves, \"%s\"",
+				color(user), nick, dequote(mesg)
 			);
 		} else {
-			uiFmt(tag, "\3%d%s\3 leaves", color(user), nick);
+			uiFmt(tag, UI_COLD, "\3%d%s\3 leaves", color(user), nick);
 		}
 	}
 }
@@ -216,10 +249,12 @@ static void handleReplyTopic(char *prefix, char *params) {
 	char *chan, *topic;
 	shift(prefix, NULL, NULL, NULL, params, 3, 0, NULL, &chan, &topic);
 	struct Tag tag = tagFor(chan);
+
 	urlScan(tag, topic);
 	uiTopic(tag, topic);
 	uiFmt(
-		tag, "The sign in \3%d%s\3 reads, \"%s\"",
+		tag, UI_COLD,
+		"The sign in \3%d%s\3 reads, \"%s\"",
 		color(chan), chan, topic
 	);
 }
@@ -228,11 +263,14 @@ static void handleTopic(char *prefix, char *params) {
 	char *nick, *user, *chan, *topic;
 	shift(prefix, &nick, &user, NULL, params, 2, 0, &chan, &topic);
 	struct Tag tag = tagFor(chan);
+
 	if (!isSelf(nick, user)) tabTouch(tag, nick);
+
 	urlScan(tag, topic);
 	uiTopic(tag, topic);
 	uiFmt(
-		tag, "\3%d%s\3 places a new sign in \3%d%s\3, \"%s\"",
+		tag, UI_COLD,
+		"\3%d%s\3 places a new sign in \3%d%s\3, \"%s\"",
 		color(user), nick, color(chan), chan, topic
 	);
 }
@@ -256,7 +294,10 @@ static void handleReplyWho(char *prefix, char *params) {
 		params, 6, 0, NULL, &chan, &user, NULL, NULL, &nick
 	);
 	struct Tag tag = tagFor(chan);
+
+	// FIXME: Don't clobber order if they already exist.
 	tabTouch(tag, nick);
+
 	size_t cap = sizeof(who.buf) - who.len;
 	int len = snprintf(
 		&who.buf[who.len], cap,
@@ -270,8 +311,10 @@ static void handleReplyEndOfWho(char *prefix, char *params) {
 	char *chan;
 	shift(prefix, NULL, NULL, NULL, params, 2, 0, NULL, &chan);
 	struct Tag tag = tagFor(chan);
+
 	uiFmt(
-		tag, "In \3%d%s\3 are %s",
+		tag, UI_COLD,
+		"In \3%d%s\3 are %s",
 		color(chan), chan, who.buf
 	);
 	who.len = 0;
@@ -280,12 +323,16 @@ static void handleReplyEndOfWho(char *prefix, char *params) {
 static void handleNick(char *prefix, char *params) {
 	char *prev, *user, *next;
 	shift(prefix, &prev, &user, NULL, params, 1, 0, &next);
+
 	if (isSelf(prev, user)) selfNick(next);
+
 	struct Tag tag;
 	while (TAG_NONE.id != (tag = tabTag(prev)).id) {
 		tabReplace(tag, prev, next);
+
 		uiFmt(
-			tag, "\3%d%s\3 is now known as \3%d%s\3",
+			tag, UI_COLD,
+			"\3%d%s\3 is now known as \3%d%s\3",
 			color(user), prev, color(user), next
 		);
 	}
@@ -296,11 +343,15 @@ static void handleCTCP(struct Tag tag, char *nick, char *user, char *mesg) {
 	char *ctcp = strsep(&mesg, " ");
 	char *params = strsep(&mesg, "\1");
 	if (strcmp(ctcp, "ACTION")) return;
-	if (!isSelf(nick, user)) tabTouch(tag, nick);
+
+	bool self = isSelf(nick, user);
+	if (!self) tabTouch(tag, nick);
+
 	urlScan(tag, params);
-	bool ping = isPing(nick, user, params);
+	bool ping = !self && isPing(params);
 	uiFmt(
-		tag, "%c\3%d* %s\17 %s",
+		tag, (ping ? UI_HOT : UI_WARM),
+		"%c\3%d* %s\17 %s",
 		ping["\17\26"], color(user), nick, params
 	);
 }
@@ -313,12 +364,15 @@ static void handlePrivmsg(char *prefix, char *params) {
 		handleCTCP(tag, nick, user, mesg);
 		return;
 	}
-	if (!isSelf(nick, user)) tabTouch(tag, nick);
-	urlScan(tag, mesg);
+
 	bool self = isSelf(nick, user);
-	bool ping = isPing(nick, user, mesg);
+	if (!self) tabTouch(tag, nick);
+
+	urlScan(tag, mesg);
+	bool ping = !self && isPing(mesg);
 	uiFmt(
-		tag, "%c\3%d%c%s%c\17 %s",
+		tag, (ping ? UI_HOT : UI_WARM),
+		"%c\3%d%c%s%c\17 %s",
 		ping["\17\26"], color(user), self["<("], nick, self[">)"], mesg
 	);
 }
@@ -328,11 +382,16 @@ static void handleNotice(char *prefix, char *params) {
 	shift(prefix, &nick, &user, NULL, params, 2, 0, &chan, &mesg);
 	struct Tag tag = TAG_STATUS;
 	if (user) tag = (strcmp(chan, self.nick) ? tagFor(chan) : tagFor(nick));
-	if (!isSelf(nick, user)) tabTouch(tag, nick);
+
+	bool self = isSelf(nick, user);
+	if (!self) tabTouch(tag, nick);
+
 	urlScan(tag, mesg);
+	bool ping = !self && isPing(mesg);
 	uiFmt(
-		tag, "\3%d-%s-\3 %s",
-		color(user), nick, mesg
+		tag, (ping ? UI_HOT : UI_WARM),
+		"%c\3%d-%s-\17 %s",
+		ping["\17\26"], color(user), nick, mesg
 	);
 }