Remove dupe reaction, log duplicates instead
The 🔁 emoji was being added for duplicate rides. Now we just log the duplicate server-side without adding any reaction to the message. Signed-off-by: Blake Ridgway <blake@blakeridgway.com>
This commit is contained in:
9
Makefile
9
Makefile
@@ -97,6 +97,10 @@ deploy-env:
|
||||
$(SSH) "chmod 600 $(JAIL_ROOT)/var/db/$(JAIL_NAME)/.env && \
|
||||
chown 1001:1001 $(JAIL_ROOT)/var/db/$(JAIL_NAME)/.env"
|
||||
|
||||
# Pull .env from the jail to the local directory
|
||||
pull-env:
|
||||
$(SSH) "cat $(JAIL_ROOT)/var/db/$(JAIL_NAME)/.env" > .env
|
||||
|
||||
start:
|
||||
$(SSH) "rm -f $(JAIL_ROOT)/var/run/$(JAIL_NAME).pid && \
|
||||
jexec $(JAIL_NAME) service $(JAIL_NAME) start"
|
||||
@@ -126,6 +130,11 @@ dns-fix:
|
||||
@echo "=== New jail DNS ==="
|
||||
$(SSH) "cat /jails/$(JAIL_NAME)/etc/resolv.conf"
|
||||
|
||||
# ── Database Backfill ──────────────────────────────────────────────────────────
|
||||
backfill:
|
||||
@echo "=== Backfilling stale usernames ==="
|
||||
$(SSH) "sh -s" < scripts/backfill-usernames.sh
|
||||
|
||||
clean:
|
||||
rm -f $(BINARY)
|
||||
go clean
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
|
||||
const (
|
||||
reactionOK = "✅"
|
||||
reactionDupe = "🔁"
|
||||
settingChannel = "fitness_channel_id"
|
||||
)
|
||||
|
||||
@@ -272,7 +271,7 @@ func (b *Bot) onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate)
|
||||
_ = s.MessageReactionAdd(m.ChannelID, m.ID, reactionOK)
|
||||
b.scheduleTopicUpdate(m.GuildID, m.ChannelID)
|
||||
} else {
|
||||
_ = s.MessageReactionAdd(m.ChannelID, m.ID, reactionDupe)
|
||||
log.Printf("duplicate ride detected for %s, skipping reaction", m.Author.Username)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
292
findings-qualo.html
Normal file
292
findings-qualo.html
Normal file
File diff suppressed because one or more lines are too long
292
findings.html
Normal file
292
findings.html
Normal file
File diff suppressed because one or more lines are too long
58
findings.jsonl
Normal file
58
findings.jsonl
Normal file
File diff suppressed because one or more lines are too long
292
reports/findings.html
Normal file
292
reports/findings.html
Normal file
File diff suppressed because one or more lines are too long
52
scripts/backfill-usernames.sh
Normal file
52
scripts/backfill-usernames.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# Backfill stale usernames in distance_logs so every row for a given user
|
||||
# uses the most recent username. This prevents duplicate leaderboard entries
|
||||
# if any user changed their Discord display name.
|
||||
#
|
||||
# Usage:
|
||||
# On the host: sh scripts/backfill-usernames.sh
|
||||
# Remotely: ssh root@172.16.0.101 "sh -s" < scripts/backfill-usernames.sh
|
||||
|
||||
JAIL_ROOT="/jails/cyclingbot"
|
||||
PG_JAIL="postgres"
|
||||
ENV_FILE="${JAIL_ROOT}/var/db/cyclingbot/.env"
|
||||
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
echo "Error: $ENV_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract DATABASE_URL from .env (ignore quoted/unquoted values)
|
||||
DATABASE_URL=$(grep '^DATABASE_URL=' "$ENV_FILE" | head -1 | cut -d= -f2-)
|
||||
|
||||
if [ -z "$DATABASE_URL" ]; then
|
||||
echo "Error: DATABASE_URL not found in $ENV_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "=== Backfilling stale usernames ==="
|
||||
echo ""
|
||||
|
||||
jexec "$PG_JAIL" psql "$DATABASE_URL" -c "
|
||||
UPDATE distance_logs dl
|
||||
SET username = u.latest_username
|
||||
FROM (
|
||||
SELECT user_id, guild_id, username AS latest_username
|
||||
FROM (
|
||||
SELECT user_id, guild_id, username,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY user_id, guild_id
|
||||
ORDER BY logged_at DESC
|
||||
) AS rn
|
||||
FROM distance_logs
|
||||
) sub
|
||||
WHERE sub.rn = 1
|
||||
) u
|
||||
WHERE dl.user_id = u.user_id
|
||||
AND dl.guild_id = u.guild_id
|
||||
AND dl.username != u.latest_username;
|
||||
"
|
||||
|
||||
echo ""
|
||||
echo "=== Backfill complete ==="
|
||||
|
||||
Reference in New Issue
Block a user