Commit Graph

65 Commits

Author SHA1 Message Date
e488b2b227 feat: extract and save memories after chat conversations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 13:02:42 -05:00
196f8c8ae5 fix: remove owner notification on topic drift escalation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 22:29:01 -05:00
c63913cf14 fix: anonymize usernames before LLM analysis to prevent name-based scoring bias
Display names like "Calm your tits" were causing the LLM to inflate toxicity
scores on completely benign messages. Usernames are now replaced with User1,
User2, etc. before sending to the LLM, then mapped back to real names in the
results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 22:20:53 -05:00
cb8ef8542b fix: guard against malformed LLM findings in conversation validation
Filter out non-dict entries from user_findings and handle non-dict
result to prevent 'str' object has no attribute 'setdefault' errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 21:38:02 -05:00
f46caf9ac5 fix: tag context messages with [CONTEXT] to prevent LLM from scoring them
The triage LLM was blending context message content into its reasoning
for new messages (e.g., citing profanity from context when the new
message was just "I'll be here"). Added per-message [CONTEXT] tags
inline and strengthened the prompt to explicitly forbid referencing
context content in reasoning/scores.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 20:08:23 -05:00
660086a500 refactor: extract sentiment cog into package with shared _process_finding
Convert cogs/sentiment.py (1050 lines) into cogs/sentiment/ package:
- __init__.py (656 lines): core SentimentCog with new _process_finding()
  that deduplicates the per-user finding loop from _process_buffered and
  _run_mention_scan (~90 lines each → single shared method)
- actions.py: mute_user, warn_user
- topic_drift.py: handle_topic_drift
- channel_redirect.py: handle_channel_redirect, build_channel_context
- coherence.py: handle_coherence_alert
- log_utils.py: log_analysis, log_action, score_color
- state.py: save_user_state, flush_dirty_states

All extracted modules use plain async functions (not methods) receiving
bot/config as parameters. Named log_utils.py to avoid shadowing stdlib
logging. Also update CLAUDE.md with comprehensive project documentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 17:06:27 -05:00
188370b1fd Fix LLM scoring usernames as toxic content
The display name "Calm your tits" was being factored into toxicity
scores. Updated the analysis prompt to explicitly instruct the LLM
to ignore all usernames/display names when scoring messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 15:51:14 -05:00
7417908142 fix: separate context from new messages so prior-cycle chat doesn't inflate scores
The conversation analysis was re-scoring old messages alongside new ones,
causing users to get penalized repeatedly for already-scored messages.
A "--- NEW MESSAGES ---" separator now marks which messages are new, and
the prompt instructs the LLM to score only those. Also fixes bot-mention
detection to require an explicit @mention in message text rather than
treating reply-pings as scans (so toxic replies to bot warnings aren't
silently skipped).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 15:48:02 -05:00
8734f1883b fix: persist last_offense_time and reset offenses after 24h
last_offense_time was in-memory only — lost on restart, so the
offense_reset_minutes check never fired after a reboot. Now persisted
as LastOffenseAt FLOAT in UserState. On startup hydration, stale
offenses (and warned flag) are auto-cleared if the reset window has
passed. Bumped offense_reset_minutes from 2h to 24h.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 11:24:38 -05:00
71c7b45e9a feat: require warning before mute + sustained toxicity escalation
Gate mutes behind a prior warning — first offense always gets a warning,
mute only fires if warned_since_reset is True. Warned flag is persisted
to DB (new Warned column on UserState) and survives restarts.

Add post-warning escalation boost to drama_score: each high-scoring
message after a warning adds +0.04 (configurable) so sustained bad
behavior ramps toward the mute threshold instead of plateauing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 11:07:57 -05:00
f02a4ab49d Add content fallback for conversation analysis + debug logging
When the LLM returns text instead of a tool call for conversation
analysis, try parsing the content as JSON before giving up. Also
log what the model actually returns on failure for debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 10:16:15 -05:00
90b70cad69 feat: channel-level conversation analysis with compact formatting
Switch from per-user message batching to per-channel conversation
analysis. The LLM now sees the full interleaved conversation with
relative timestamps, reply chains, and consecutive message collapsing
instead of isolated flat text per user.

Key changes:
- Fix gpt-5-nano temperature incompatibility (conditional temp param)
- Add mention-triggered scan: users @mention bot to analyze recent chat
- Refactor debounce buffer from (channel_id, user_id) to channel_id
- Replace per-message analyze_message() with analyze_conversation()
  returning per-user findings from a single LLM call
- Add CONVERSATION_TOOL schema with coherence, topic, and game fields
- Compact message format: relative timestamps, reply arrows (→),
  consecutive same-user message collapsing
- Separate mention scan tasks from debounce tasks
- Remove _store_context/_get_context (conversation block IS the context)
- Escalation timeout config: [30, 60, 120, 240] minutes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 23:13:07 -05:00
943c67cc87 Add Wordle scoring context so LLM knows lower is better
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 18:05:41 -05:00
f457240e62 Add Wordle commentary: bot reacts to Wordle results with mode-appropriate comments
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 17:56:05 -05:00
01b7a6b240 Bump health check max_completion_tokens to 16
gpt-5-nano can't produce output with max_completion_tokens=1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 17:08:32 -05:00
a0edf90ebd Switch to max_completion_tokens for newer OpenAI models
gpt-5-nano and other newer models require max_completion_tokens
instead of max_tokens. The new parameter is backwards compatible
with older models.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 17:07:44 -05:00
dd0d18b0f5 Disable topic drift monitoring in general channel
Add ignored_channels config to topic_drift section, supporting
channel names or IDs. General channel excluded from off-topic
warnings while still receiving full moderation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 14:47:03 -05:00
b79d1897f9 Add drunk mode: happy drunk commentating on everything
Lovable hammered friend with typos, strong nonsensical opinions,
random tangents, and overwhelming affection for everyone in chat.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 20:05:03 -05:00
ac4057b906 Add hype mode: positive/supportive teammate personality
New mode that gasses people up for their plays and takes using
gaming hype terminology, but reads the room and dials back to
genuine encouragement when someone's tilted or frustrated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 20:02:39 -05:00
8b2091ac38 Tone down roast bot: more positive, less frequent
- Add guidance for ~25% genuinely positive/hype responses
- Lean toward playful ribbing over pure negativity
- Reduce reply_chance from 35% to 20%
- Increase proactive_cooldown_messages from 5 to 8

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 19:55:17 -05:00
7db7a4b026 Tell roast prompt not to fabricate leaderboards or stats
The model was inventing rankings and scoreboards from the drama score
metadata. Explicitly tell it not to make up stats it doesn't have.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:43:36 -05:00
c8e7c8c1cf Trim prompts for gpt-4o-mini, remove disagreement detection
Slim down chat_roast.txt — remove anti-repetition rules that were
compensating for the local model (gpt-4o-mini handles this natively).
Remove disagreement detection from analysis prompt, tool schema, and
sentiment handler. Saves ~200 tokens per analysis call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:26:44 -05:00
c258994a2e Use gpt-4o-mini for chat/roasts via dedicated LLM_CHAT_MODEL
Add a separate llm_chat client so chat responses use a smarter model
(gpt-4o-mini) while analysis stays on the cheap local Qwen3-8B.
Falls back to llm_heavy if LLM_CHAT_MODEL is not set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:04:55 -05:00
e4239b25c3 Keep only the last segment after bracketed metadata in LLM responses
The model dumps paraphrased context and style labels in [brackets]
before its actual roast. Instead of just removing bracket lines
(which leaves the preamble text), split on them and keep only the
last non-empty segment — the real answer is always last.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:31:09 -05:00
02b2870f2b Strip all standalone bracketed text from LLM responses
The model paraphrases injected metadata in unpredictable ways, so
targeted regexes can't keep up. Replace them with a single rule: any
[bracketed block] on its own line gets removed, since real roasts
never use standalone brackets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:24:18 -05:00
942f5ddce7 Fix repetitive roast responses with anti-repetition mechanisms
Add frequency_penalty (0.8) and presence_penalty (0.6) to LLM chat
calls to discourage repeated tokens. Inject the bot's last 5 responses
into the system prompt so the model knows what to avoid. Strengthen
the roast prompt with explicit anti-repetition rules and remove example
lines the model was copying verbatim ("Real ___ energy", etc.).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:15:11 -05:00
534aac5cd7 Enable thinking for chat, diversify roast styles
- Remove /no_think override from chat() so Qwen3 reasons before
  generating responses (fixes incoherent word-salad replies)
- Analysis and image calls keep /no_think for speed
- Add varied roast style guidance (deadpan, sarcastic, blunt, etc.)
- Explicitly ban metaphors/similes in roast prompt
- Replace metaphor examples with direct roast examples

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:59:16 -05:00
66031cd9f9 Add user notes and recent message history to chat context
When the bot replies (proactive or mentioned), it now fetches the
user's drama tracker notes and their last ~10 messages in the channel.
Gives the LLM real context for personalized replies instead of
generic roasts on bare pings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:44:04 -05:00
3261cdd21c Fix proactive replies appearing before the triggering message
Proactive replies used channel.send() which posted standalone messages
with no visual link to what triggered them. Now all replies use
message.reply() so the response is always attached to the source message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:35:40 -05:00
3f9dfb1e74 Fix reaction clap-backs replying to the bot's own message
Send as a channel message instead of message.reply() so it doesn't
look like the bot is talking to itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:32:08 -05:00
86b23c2b7f Let users @ the bot on a message to make it respond
Reply to any message + @bot to have the bot read and respond to it.
Also picks up image attachments from referenced messages so users
can reply to a photo with "@bot roast this".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:24:26 -05:00
8a06ddbd6e Support hybrid LLM: local Qwen triage + OpenAI escalation
Triage analysis runs on Qwen 8B (athena.lan) for free first-pass.
Escalation, chat, image roasts, and commands use GPT-4o via OpenAI.

Each tier gets its own base URL, API key, and concurrency settings.
Local models get /no_think and serialized requests automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:20:07 -05:00
b5e401f036 Generalize image roast to handle selfies, memes, and any image
The prompt was scoreboard-only, so selfies got nonsensical stat-based
roasts. Now the LLM identifies what's in the image and roasts accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:15:22 -05:00
28fb66d5f9 Switch LLM backend from llama.cpp/Qwen to OpenAI
- Default models: gpt-4o-mini (triage), gpt-4o (escalation)
- Remove Qwen-specific /no_think hacks
- Reduce timeout from 600s to 120s, increase concurrency semaphore to 4
- Support empty LLM_BASE_URL to use OpenAI directly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:07:53 -05:00
a9bc24e48e Tune english teacher to catch more errors, bump roast reply chance
- Raised sentence limit from 3 to 5 for english teacher mode
- Added instruction to list multiple corrections rapid-fire
- Roast mode reply chance: 10% -> 35%

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:03:03 -05:00
431d63da72 Fix metadata leaking and skip sentiment for bot-directed messages
1. Broader regex to strip leaked metadata even when the LLM drops
   the "Server context:" prefix but keeps the content.

2. Skip sentiment analysis for messages that mention or reply to
   the bot. Users interacting with the bot in roast/chat modes
   shouldn't have those messages inflate their drama score.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:52:33 -05:00
7743b22795 Add reaction clap-back replies (50% chance)
When someone reacts to the bot's message, there's a 50% chance it
fires back with a reply commenting on their emoji choice, in
character for the current mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:48:13 -05:00
86aacfb84f Add 120s timeout to image analysis streaming
The vision model request was hanging indefinitely, freezing the bot.
The streaming loop had no timeout so if the model never returned
chunks, the bot would wait forever. Now times out after 2 minutes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:37:37 -05:00
e1dea84d08 Strip leaked metadata from LLM responses
The local LLM was echoing back [Server context: ...] metadata lines
in its responses despite prompt instructions not to. Now stripped
via regex before sending to Discord.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:23:49 -05:00
c3274dc702 Add announce script for posting to Discord channels
Usage: ./scripts/announce.sh "message" [channel_name]
Fetches the bot token from barge, resolves channel by name,
and posts via the Discord API. Defaults to #general.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:11:27 -05:00
4283078e23 Add english teacher mode
Insufferable grammar nerd that corrects spelling, translates slang
into proper English, and overanalyzes messages like literary essays.
20% proactive reply chance with relaxed moderation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:06:31 -05:00
b6cdea7329 Include replied-to message text in LLM context
When a user replies to the bot's message, the original bot message
text is now included in the context sent to the LLM. This prevents
the LLM from misinterpreting follow-up questions like "what does
this even mean?" since it can see what message is being referenced.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:59:51 -05:00
66ca97760b Add context format explanation to chat prompts
LLM was misinterpreting usernames as channel names because
the [Server context: ...] metadata format was never explained
in the system prompts. This caused nonsensical replies like
treating username "thelimitations" as "the limitations channel".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:54:08 -05:00
0feef708ea Set bot status from active mode on startup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:27:34 -05:00
b050c6f844 Set default startup mode to roast
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:26:49 -05:00
6e1a73847d Persist bot mode across restarts via database
Adds a BotSettings key-value table. The active mode is saved
when changed via /bcs-mode and restored on startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:26:00 -05:00
622f0a325b Add auto-polls to settle disagreements between users
LLM analysis now detects when two users are in a genuine
disagreement. When detected, the bot creates a native Discord
poll with each user's position as an option.

- Disagreement detection added to LLM analysis tool schema
- Polls last 4 hours with 1 hour per-channel cooldown
- LLM extracts topic, both positions, and usernames
- Configurable via polls section in config.yaml

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:22:32 -05:00
13a2030021 Add switchable bot modes: default, chatty, and roast
Adds a server-wide mode system with /bcs-mode command.
- Default: current hall-monitor behavior unchanged
- Chatty: friendly chat participant with proactive replies (~10% chance)
- Roast: savage roast mode with proactive replies
- Chatty/roast use relaxed moderation thresholds
- 5-message cooldown between proactive replies per channel
- Bot status updates to reflect active mode
- /bcs-status shows current mode and effective thresholds

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 08:59:51 -05:00
3f56982a83 Simplify user notes trimming to keep last 10 lines
Replace character-based truncation loop with a simple line count cap.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 23:43:36 -05:00
d41873230d Reduce repetitive drama score mentions in chat replies
Only inject drama score/offense context when values are noteworthy
(score >= 0.2 or offenses > 0). Update personality prompt to avoid
harping on zero scores and vary responses more.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 22:57:25 -05:00