summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-09-15 10:46:21 -0400
committerJune McEnroe <june@causal.agency>2021-09-15 10:46:21 -0400
commit2f1db2d67ab40f8a72513935bf00710427568242 (patch)
treea7eeb5e7b3f9e87a93db262192f08cdd245e34fd /bin
parentAdd downgrade IRC bot (diff)
downloadsrc-2f1db2d67ab40f8a72513935bf00710427568242.tar.gz
src-2f1db2d67ab40f8a72513935bf00710427568242.zip
Factor out common parts of downgrade messages
Also bump the message cap to 1024 because that is ostensibly useful
for replying to older messages.
Diffstat (limited to 'bin')
-rw-r--r--bin/downgrade.c48
1 files changed, 13 insertions, 35 deletions
diff --git a/bin/downgrade.c b/bin/downgrade.c
index 1b41df13..168510ce 100644
--- a/bin/downgrade.c
+++ b/bin/downgrade.c
@@ -55,7 +55,7 @@ static void format(const char *format, ...) {
 static bool invite;
 static const char *join;
 
-enum { Cap = 256 };
+enum { Cap = 1024 };
 static struct Message {
 	char *id;
 	char *nick;
@@ -198,12 +198,9 @@ static void handle(char *ptr) {
 		}
 	} else if (react && reply) {
 		struct Message *to = find(reply);
+		format("NOTICE %s :* %s reacted to ", msg.chan, msg.nick);
 		if (to && strcmp(to->chan, msg.chan)) {
-			format(
-				"NOTICE %s :"
-				"* %s reacted to a message in another channel with \"%s\"\r\n",
-				msg.chan, msg.nick, react
-			);
+			format("a message in another channel");
 		} else if (to && to->mesg) {
 			size_t len = 0;
 			for (size_t n; to->mesg[len]; len += n) {
@@ -211,23 +208,15 @@ static void handle(char *ptr) {
 				if (len + n > 50) break;
 			}
 			format(
-				"NOTICE %s :"
-				"* %s reacted to %s's message (\"%.*s\"%s) with \"%s\"\r\n",
-				msg.chan, msg.nick,
-				to->nick, (int)len, to->mesg, (to->mesg[len] ? "..." : ""),
-				react
+				"%s's message (\"%.*s\"%s)",
+				to->nick, (int)len, to->mesg, (to->mesg[len] ? "..." : "")
 			);
 		} else if (to) {
-			format(
-				"NOTICE %s :* %s reacted to %s's reaction with \"%s\"\r\n",
-				msg.chan, msg.nick, to->nick, react
-			);
+			format("%s's reaction", to->nick);
 		} else {
-			format(
-				"NOTICE %s :* %s reacted to an unknown message with \"%s\"\r\n",
-				msg.chan, msg.nick, react
-			);
+			format("an unknown message");
 		}
+		format(" with \"%s\"\r\n", react);
 	} else if (react) {
 		format(
 			"NOTICE %s :* %s reacted to nothing with \"%s\"\r\n",
@@ -235,12 +224,9 @@ static void handle(char *ptr) {
 		);
 	} else if (reply) {
 		struct Message *to = find(reply);
+		format("NOTICE %s :* %s was replying to ", msg.chan, msg.nick);
 		if (to && strcmp(to->chan, msg.chan)) {
-			format(
-				"NOTICE %s :"
-				"* %s was replying to a message in another channel!\r\n",
-				msg.chan, msg.nick
-			);
+			format("a message in another channel!\r\n");
 		} else if (to && to->mesg) {
 			size_t len = 0;
 			for (size_t n; to->mesg[len]; len += n) {
@@ -248,21 +234,13 @@ static void handle(char *ptr) {
 				if (len + n > 50) break;
 			}
 			format(
-				"NOTICE %s :"
-				"* %s was replying to %s's message (\"%.*s\"%s)\r\n",
-				msg.chan, msg.nick,
+				"%s's message (\"%.*s\"%s)\r\n",
 				to->nick, (int)len, to->mesg, (to->mesg[len] ? "..." : "")
 			);
 		} else if (to) {
-			format(
-				"NOTICE %s :* %s was replying to %s's reaction\r\n",
-				msg.chan, msg.nick, to->nick
-			);
+			format("%s's reaction\r\n", to->nick);
 		} else {
-			format(
-				"NOTICE %s :* %s was replying to an unknown message!\r\n",
-				msg.chan, msg.nick
-			);
+			format("an unknown message!\r\n");
 		}
 	}
 }