Forum teuk.org

πŸͺ„ Lumos Maxima II β€” Context, External & YouTube Reforged (May 2026)

in Mediabot Β· started by TeuK Β· 6d ago

TeuK Β· 6d ago

Overview

A fresh round of deep auditing across snapshots mb45 and mb46, covering the brand-new Context.pm and Command.pm modules, a major YouTube display overhaul in External.pm, and a series of defensive fixes across LoginCommands, ChannelBan, and the Partyline. The Dark Lord of silent failures has been expelled once more.


πŸ”΄ Bugs Fixed

🧩 Context.pm β€” New Module, New Bugs

reply() and reply_channel() crash silently in private context

Both methods called $bot->botPrivmsg($self->{channel}, $msg) unconditionally. When a command is issued via /msg (private, no channel), $self->{channel} is undef. The PRIVMSG was sent to nowhere. Both methods now detect is_private() and fall back to botNotice($self->{nick}, $msg).

deny() called with undef nick

deny() routes error messages to the caller via botNotice($self->{nick}, $msg). In timer-triggered or system contexts, $self->{nick} can be undef. Now uses $self->{nick} // '' to avoid sending a NOTICE without a target.

require_auth failed silently when user is unknown

return unless $user;   # ← silent

If the calling nick is not known to the bot, require_auth returned undef without any message. The caller had no way to distinguish β€œunauthenticated” from β€œuser not found”. Now calls deny("You must be identified to use this command.") explicitly.

user() called get_user_from_message repeatedly

The negative result (user not found) was never cached β€” every call to $ctx->user() triggered a DB lookup. A _user_fetched flag now stores the negative result so subsequent calls return undef immediately without hitting the DB again.

πŸ” Auth β€” conf => Missing in Two Places

Auth::new() accepts a conf => parameter to allow future access to bot configuration, but it was missing from both LoginCommands::init_auth() and User::maybe_autologin(). Both now pass conf => $self->{conf} / conf => $bot->{conf} for consistency.

🎨 External.pm β€” _yt_text White on White

sub _yt_text { return _irc_color($_[0], 0); }  # color 0 = white

mIRC color 0 is white β€” invisible on light-theme IRC clients. The text body of YouTube notifications was completely invisible for most users. Changed to color 14 (grey), readable on both light and dark backgrounds.

_irc_color color code not clamped

The $fg parameter was passed directly to sprintf("\x03%02d", $fg) without validation. Values outside [0-15] produce undefined rendering behavior in IRC clients. Now clamped to int($fg) % 16.


🟠 Improvements

🧩 Context.pm

  • log_info() level 0 β†’ 2 β€” log_info previously called $logger->log(0, ...) which is always displayed in production. Changed to level 2 (DEBUG2) to avoid flooding prod logs with contextual informational messages. log_error remains at level 1.
  • user() negative cache β€” avoids repeated get_user_from_message DB calls when the user is not found.

🎬 External.pm β€” YouTube Overhaul

  • _BLOCKED_TITLE_PATTERNS array β€” the 14 Cloudflare/bot-wall title patterns ("Just a moment", "Access Denied", "403 Forbidden", etc.) were a chain of return undef if $title =~ .../i statements. Centralised in a named array @_BLOCKED_TITLE_PATTERNS β€” easy to extend without hunting down the function.
  • getYoutubeDetails duplicate log β€” two consecutive log(4, ...) lines for sDuration (one combined, one raw). Merged into a single combined entry.
  • displayYoutubeDetails log verbosity β€” four separate log(4, ...) calls for sDuration, sViewCount, sTitle, schannelTitle merged into one formatted line.

πŸ” LoginCommands

  • init_auth() now passes conf => β€” LoginCommands::init_auth() and User::maybe_autologin() both instantiate Mediabot::Auth. Both now pass the full set of constructor args (dbh, logger, bot, conf) for consistency.

πŸ“¦ Files Changed

Module Changes
Context.pm reply() / reply_channel() private fallback; deny() nick guard; require_auth deny on unknown user; user() negative cache; log_info level 0β†’2
External.pm _yt_text color 14; _irc_color clamp; @_BLOCKED_TITLE_PATTERNS; log deduplication in 2 functions
LoginCommands.pm init_auth() passes conf => to Auth::new
ChannelBan.pm list_active_bans($id, $limit) β€” callers now pass 11 to detect overflow
ChannelCommands.pm .bans uses limit=11
Partyline.pm .bans uses limit=11

β€œLumos Maxima β€” the light now reaches the dark corners of every module.” πŸ•―οΈβœ¨

You must be logged in to reply.