From 37feb109b3aca4635e1a44f0669ccae4a6a79594 Mon Sep 17 00:00:00 2001 From: waffle2k Date: Sun, 13 Sep 2026 16:40:30 -0700 Subject: [PATCH] Fix --since in welcomebot-reputation A relative bound has to be datetime('now', '-24 hours'); datetime('-24 hours') returns NULL, so the comparison was false for every row and --since silently reported nothing rather than erroring. Caught when a --since '-10 minutes' came back empty for queries that had demonstrably just happened. Absolute forms ('2026-09-13') still take the single-argument path. --- bin/welcomebot-reputation | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/welcomebot-reputation b/bin/welcomebot-reputation index 33b426b..7a5caa4 100755 --- a/bin/welcomebot-reputation +++ b/bin/welcomebot-reputation @@ -92,6 +92,18 @@ def limited(sql): return sql if limit == "all" else f"{sql} LIMIT {int(limit)}" +def since_expr(column): + """SQL for the --since bound. + + A leading +/- means "relative to now" — sqlite needs that spelled + datetime('now', '-24 hours'), NOT datetime('-24 hours'), which returns + NULL and silently matches no rows. + """ + if since.startswith(("+", "-")): + return f"{column} >= datetime('now', ?)" + return f"{column} >= datetime(?)" + + def tables_exist(): names = {r[0] for r in conn.execute( "SELECT name FROM sqlite_master WHERE type = 'table'")} @@ -106,7 +118,7 @@ if not tables_exist(): if mode == "stats": where, params = [], [] if since: - where.append("queried_at >= datetime(?)") + where.append(since_expr("queried_at")) params.append(since) clause = (" WHERE " + " AND ".join(where)) if where else "" row = conn.execute( @@ -150,7 +162,7 @@ if mode == "blocks": where.append("kind = ?") params.append(kind) if since: - where.append("first_blocked_at >= datetime(?)") + where.append(since_expr("first_blocked_at")) params.append(since) clause = (" WHERE " + " AND ".join(where)) if where else "" rows = conn.execute(limited( @@ -179,7 +191,7 @@ if kind: where.append("kind = ?") params.append(kind) if since: - where.append("queried_at >= datetime(?)") + where.append(since_expr("queried_at")) params.append(since) clause = (" WHERE " + " AND ".join(where)) if where else ""