Forum teuk.org

πŸ§™β€β™‚οΈ Mediabot v3: Messages Find People, Facts Learn Their Names, and Units Stop Arguing β€” MB474 to MB481

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

TeuK Β· 1mo ago

The previous chapter left Mediabot with stronger authentication, safer deployment checks, a real security audit, and a cleaner release path toward 3.3.

This new pass is different.

It adds features that users will actually feel on IRC: delayed messages that arrive when someone joins, typo suggestions, persistent channel factoids, a quick ?keyword recall, factoid rankings, offline unit conversion, and richer stats.

Then a final independent pre-commit audit closed three small but real release-quality gaps before the commit.

The project remains on the 3.2dev line.

This is still not the 3.3 release.


πŸ“¨ MB474 β€” !tell messages now arrive when someone joins

Mediabot already had a useful reminder path:

!remind nick message

But the delivery happened only when the target later spoke on the channel.

That meant someone could join, read quietly, and never receive the message.

MB474 fixes that by also checking pending reminders on JOIN.

A new alias makes the behavior clearer:

!tell Bob remember to check the patch

When Bob joins the channel, the message is delivered even if he says nothing.

The delivery remains safe because the reminder is marked as delivered before the bot sends it. Calling the same delivery path again when the user later speaks does not duplicate the message.


πŸͺ„ MB475 β€” Unknown commands now get a useful suggestion

A typo such as:

!raodm

can now produce:

unknown command '!raodm'. Did you mean !random?

The suggestion engine is deliberately conservative:

  • it runs only on public channel command misses;
  • it ignores very short tokens;
  • it uses Damerau-Levenshtein distance, so adjacent transpositions such as hlep β†’ help are handled well;
  • it suggests only one command;
  • it has a per-channel cooldown;
  • it can be disabled with the DidYouMean chanset.

This keeps it helpful without turning random IRC chatter into a correction machine.


πŸ“š MB476 β€” Persistent channel factoids

Mediabot now has classic infobot-style factoids:

!learn coffee = black gold of the morning
!whatis coffee
!forget coffee
!factoids

Unlike personal notes, factoids are shared by channel and stored in MariaDB.

This round adds the FACTOID table and a Factoids chanset. Each factoid is scoped to a channel, has a normalized keyword, stores the value, remembers its creator, tracks creation and update timestamps, and counts hits.

Guardrails are in place:

  • channel-only;
  • keyword limited to safe characters;
  • value length capped;
  • CR/LF/NUL cleaned;
  • one fact per keyword per channel;
  • forget allowed for the original author or a channel operator;
  • chanset -Factoids can disable the feature per channel.

This is the only structural database addition in this chapter.


❓ MB477 β€” Quick factoid recall with ?keyword

Factoids become much more natural with the shortcut:

?coffee

If the factoid exists, Mediabot answers.

If it does not exist, Mediabot stays silent.

That silence is intentional. A random ?word in conversation should not spam the channel. The explicit command still teaches the user what to do:

!whatis unknown

The shortcut reuses the same factoid lookup path, so it keeps the same gating, same channel scope, and same hit counter.


πŸ† MB478 β€” Factoid metadata finally becomes visible

The FACTOID table stores useful information: author, dates and hit count.

MB478 exposes it:

!factoids top
!factoid coffee

!factoids top ranks the most recalled facts on the channel.

!factoid <keyword> shows who created the factoid, when it was created, when it was updated if different, how many times it was recalled, and its value.

The data already existed. This round simply opens the ledger.


πŸ“ MB479 β€” Offline unit conversion

Mediabot now has a built-in converter:

!convert 100 km mi
!convert 100 c f
!convert 1 kg in lb
!convert 1 gb mib

It is fully offline: no network, no external API, no code evaluation.

Supported families include:

length
mass
temperature
volume
speed
data

Linear units use a base-unit factor. Temperature uses explicit affine formulas. Decimal and binary data units are both supported, so GB and GiB no longer pretend to be the same thing.

Invalid conversions are rejected cleanly:

convert: cannot convert km to kg

A practical little command, and exactly the kind of thing people use on IRC.


πŸ… MB480 β€” !stats now shows achievements

!stats already reported activity, share, first/last seen, karma and rank.

MB480 adds an achievement count when the user has unlocked at least one achievement on the current channel:

achievements: 7

It stays quiet when the count is zero, so the output does not become noisy for new users.

The implementation reads the existing Achievements subsystem and does not add storage or commands.


πŸ” MB481 β€” Final pre-commit audit

The fresh snapshot was not committed blindly.

The audit found and fixed three concrete issues.

SQL quoting in the installer

install/db_install.sh safely handled the generated alphanumeric password, but a manually entered password containing an apostrophe could break the CREATE USER / ALTER USER SQL.

MB481 adds explicit SQL string literal quoting for the database user, host and password.

The default install path was not in danger, but release installers should not depend on users choosing easy characters.

IRC channel prefix consistency

The new factoid and DidYouMean paths initially treated only #channel as a channel.

Mediabot already supports standard IRC channel prefixes:

#  &  !  +

MB481 aligns the new code with the shared channel-target predicate, so these features follow the same channel rules as the rest of the bot.

UTF-8-safe factoid value cap

The factoid value cap used a raw byte substr.

That could cut an accented UTF-8 character in half at the limit.

MB481 switches it to the shared UTF-8-safe truncation helper. This keeps French text clean and prevents the return of a bug class already hunted down in earlier rounds.


πŸ§ͺ Validation ledger

Claude reported the following progression during the pass:

MB474 baseline: 9365/9365
MB475 baseline: 9401/9401
MB476 baseline: 9442/9442
MB477 baseline: 9448/9448
MB478 baseline: 9465/9465
MB479 baseline: 9494/9494
MB480 baseline: 9504/9504

The MB481 audit adds the focused regression test:

692_mb481_precommit_audit_fixes.t

Before publishing this chapter, the expected local release check is:

targeted MB474–MB481 tests green
full suite green
security audit GO
startup integrity OK
git diff --check clean

🧱 Database and release impact

This chapter introduces real database release work:

+1 table:
  FACTOID

+2 chansets:
  DidYouMean
  Factoids

+migrations:
  20260707_didyoumean_chanset.sql
  20260707_factoid.sql
  20260707_factoids_chanset.sql

No release tag is created.

Mediabot remains:

3.2dev-*

The 3.3 release will happen only after the final install, upgrade, rollback and live validation steps are satisfactory.


✨ What this chapter leaves behind

Mediabot now:

  • delivers tell/reminder messages when the target joins;
  • suggests likely commands after a typo;
  • stores channel factoids persistently;
  • recalls factoids quickly with ?keyword;
  • shows factoid rankings and metadata;
  • converts common units offline;
  • shows achievement counts in !stats;
  • quotes installer SQL literals safely;
  • keeps new channel features compatible with all standard IRC channel prefixes;
  • avoids cutting factoid values through a UTF-8 character.

This pass adds something important: not just safety, but daily usefulness.

The castle is no longer merely harder to break.

It is getting nicer to live in.

You must be logged in to reply.