Forum teuk.org

πŸ§™β€β™‚οΈ Protego Partyline! β€” AI Subcommands, Explicit Karma, and UTF-8 Hardening

in Mediabot Β· started by TeuK Β· 1mo ago

TeuK Β· 1mo ago

This Mediabot v3 pass started with a very concrete Partyline bug:

.ai quota

was being sent to Claude as a normal prompt instead of being handled as a Partyline AI subcommand.

Claude answered honestly, but the bot was wrong: .ai quota was documented as a command, so it should behave like a command.

That led to a wider cleanup pass around Partyline AI handling, karma syntax, database guards, and UTF-8 safety.


πŸ› .ai quota was not intercepted

Before the fix, Partyline help advertised:

.ai quota           - show your own Claude rate limit

But running it did this:

.ai quota
[Claude] I don't have specific context about what quota you're referring to...

Root cause: _cmd_ai() only intercepted a few subcommands such as reset and history. Everything else was passed directly to claudeAI() as a prompt.

Now .ai quota is handled locally and reuses the existing quota logic.


🧠 Partyline .ai subcommands are now real commands

The Partyline .ai handler now treats known subcommands as commands instead of prompts.

Covered subcommands include:

.ai quota
.ai stats
.ai models
.ai history
.ai reset
.ai forget
.ai pin
.ai pin clear
.ai summary [n]

Normal prompts still work:

.ai explain why IRC bots are stubborn

But command-like inputs no longer get blindly sent to Claude.


🧾 .ai summary now summarizes recent channel logs

.ai summary 10 now pulls recent CHANNEL_LOG entries and asks Claude to summarize them.

Two bugs were found and fixed while validating this:

Wrong column names

The first implementation assumed generic columns:

text
id

But Mediabot’s real table uses:

publictext
id_channel_log

The query was corrected to use the actual schema.

UTF-8 crash in prompt hashing

The second issue was:

Wide character in subroutine entry at Mediabot/External.pm

Root cause: the Claude prompt cache used Digest::MD5::md5_hex() directly on a Perl wide-character string.

Prompts generated from IRC logs may contain accents, emojis, block characters, or other Unicode.

The fix encodes the prompt before hashing:

encode('UTF-8', lc($prompt // ''))

That keeps the prompt cache and fixes Unicode handling properly.


βš–οΈ Karma is now explicit

The old automatic karma scanner watched every public message for patterns like:

nick++
nick--

That was too broad.

It could accidentally interpret normal text as karma, for example:

Notepad++
C++

This created bogus karma entries such as:

Top karma: notepad (+1)

The automatic scan is now disabled.

Karma changes are explicit:

m karma + boole
m karma - boole
m karma ++ boole
m karma -- boole

Showing karma remains available:

m karma boole

This is much safer and avoids silently polluting the database.


πŸ‘₯ Karma now checks channel presence

Karma voting now verifies that the target nick is present on the channel.

That prevents changing karma for random strings, old nicks, typos, or words that are not actual users in the channel context.

If the nick is not present, the command reports it instead of writing bogus karma.


πŸ“Š Partyline .karma now behaves usefully

Before, Partyline .karma <nick> picked the first joined channel alphabetically and showed that score, even if it was zero.

Example of bad behavior:

.karma Te[u]K
Te[u]K on #boulets: karma 0

Now, without an explicit channel, it shows non-zero karma across all channels:

.karma Te[u]K
Karma for Te[u]K:
  #radiocapsule             +14
  #phat                     +7
  #quebec                   -2

If an explicit channel is provided, it still shows that channel, even if the score is zero:

.karma Te[u]K #boulets
Te[u]K on #boulets: karma 0

That keeps both behaviors useful.


πŸ›‘οΈ More DB guard hardening

Several places were tightened so a failed prepare() or execute() does not crash command handling or silently fail.

Touched areas include:

timezone setters
reminder delivery
channel set changes
ban listing
external cache hit output

The goal is simple: if the DB is unavailable or a statement cannot be prepared, the bot should report a controlled error instead of exploding in the dispatcher.


πŸ”” Reminder and choose polish

A few smaller user-facing bugs were also corrected:

[URGENT] reminders with [at:TS] are detected correctly
choose now gives a clearer message when only one option remains after deduplication
karma graph avoids warnings when old log entries miss a delta field

These are small fixes, but they improve the quality of daily use.


βœ… Validated manually

This pass was intentionally focused on code corrections and runtime validation rather than adding another test wave.

Manual validation included:

.ai quota
.ai stats
.ai models
.ai history
.ai reset
.ai forget
.ai pin
.ai pin clear
.ai summary 10
.karma Te[u]K
.karma Te[u]K #boulets

And .ai summary 10 now returns a real Claude summary instead of crashing on Unicode.


Result

This pass improves Mediabot v3 in several practical ways:

Partyline AI subcommands behave as commands
.ai summary works with real CHANNEL_LOG data
Claude prompt cache handles Unicode safely
karma voting is explicit instead of accidental
Partyline karma output is useful across channels
DB prepare/execute paths are safer
small reminder/choose/karma edge cases are cleaned up

No schema change.


Spell of the day

Protego Partyline!

The Partyline is quieter, smarter, and less likely to throw random words at Claude.

Mischief managed β€” with fewer accidental Notepad++ karma points. πŸ§™β€β™‚οΈβœ¨

You must be logged in to reply.