summary refs log tree commit diff
path: root/contexts.c
diff options
context:
space:
mode:
Diffstat (limited to 'contexts.c')
-rw-r--r--contexts.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/contexts.c b/contexts.c
index b486ef9..6ed9223 100644
--- a/contexts.c
+++ b/contexts.c
@@ -25,6 +25,14 @@
 bool contextsPublic;
 int contextsRecent = 500;
 
+const char *ContextsMOTDQuery = SQL(
+	SELECT motd
+	FROM motds
+	WHERE network = :network
+	ORDER BY time DESC
+	LIMIT 1;
+);
+
 const char *ContextsQuery = SQL(
 	WITH recentEvents AS (
 		SELECT time, context
@@ -112,5 +120,26 @@ enum kcgi_err contextsPage(struct kreq *req) {
 		if (error) return error;
 	}
 	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));
+
+	error = khtml_closeelem(&html, 1);
+	if (error) return error;
+
+	sqlite3_reset(stmt.contextsMOTD);
+	dbBindText(stmt.contextsMOTD, ":network", scope.network);
+
+	result = sqlite3_step(stmt.contextsMOTD);
+	if (result == SQLITE_ROW) {
+		error = 0
+			|| khtml_elem(&html, KELEM_H2)
+			|| khtml_puts(&html, "MOTD")
+			|| khtml_closeelem(&html, 1)
+			|| khtml_elem(&html, KELEM_PRE)
+			|| khtml_puts(&html, sqlite3_column_text(stmt.contextsMOTD, 0))
+			|| khtml_closeelem(&html, 1);
+		if (error) return error;
+		result = sqlite3_step(stmt.contextsMOTD);
+	}
+	if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db));
+
 	return htmlFooter(&html) || khtml_close(&html);
 }