Forum teuk.org

Bug fixes and improvements (May 2026)

in Mediabot Β· started by TeuK Β· 2w ago

TeuK Β· 2w ago

Mediabot v3 β€” Bug fixes and improvements (May 2026)

Context

Audit of snapshot 20260502. Six files touched across the ban system, the DCC CHAT handler, and the Partyline. The new ChannelBan module and CHANNEL_BAN table were already in place β€” this pass fixes the edge cases and wires up the missing pieces.


Bug fixes

B2 β€” MODE -b sent even when bot is not in channel

process_expired_channel_bans() was sending MODE -b unconditionally on ban expiry. If the bot was not present in the channel (or had parted), the IRC server would silently refuse the unban while the DB record would still be marked removed β€” leaving the ban active on IRC indefinitely.

The fix checks gethChannelsNicksOnChan before sending MODE -b. If the bot is absent, the IRC command is skipped but the DB cleanup proceeds, with a log entry explaining why.

B3 β€” Inconsistent signature between DCC CHAT methods

accept_dcc_chat used $self->{bot} internally while accept_dcc_chat_passive required $bot as an explicit parameter. This made the two methods inconsistent and the caller in Mediabot.pm was passing $self (the bot object) as the second argument.

Both methods now follow the same pattern: $self->{bot} is used internally, and the caller no longer passes the bot reference.

B4 β€” parse_duration("0") silently created a zero-second timed ban

The guard in ChannelBan::parse_duration was $minutes < 0, which a \d+ regex match can never satisfy. A bare 0 would create a ban with a duration of zero seconds β€” technically timed but expiring immediately. Replaced with an explicit check: 0 now returns an error pointing the user to use perm instead.

B5 β€” on_message_ctcp_DCC never matched incoming data

The handler was reading $hints->{ctcp_args} which is undef in the installed version of Net::Async::IRC. As a result, the DCC CHAT regex never matched and every /dcc chat mediabotv3 silently fell through to the private command dispatcher as chat.

The handler now:

  • Dumps all hints keys in hex at log level 0 to identify the correct key
  • Falls back through ctcp_args, text, and ctcp_data
  • Strips CTCP delimiters and a leading DCC prefix if present

This will allow identifying the exact hints structure from the next test and writing a definitive fix without guessing.


Improvements

A7 β€” Prometheus counter for expired bans

process_expired_channel_bans() logged each expiry but did not expose it to Prometheus. A mediabot_channel_bans_expired_total counter is now incremented on each successful ban removal.

A8 β€” Duplicated public IP resolution in accept_dcc_chat_passive

accept_dcc_chat_passive had a full copy of the IP resolution logic already present in _resolve_dcc_public_ip. It now calls the shared helper instead, ensuring config key lookup, env fallback, and IRC socket detection are handled in one place.

M2 β€” !bans now shows human-readable time remaining

The ban list was displaying raw expires_at datetime strings from the database. It now computes the remaining time via TIMESTAMPDIFF(SECOND, NOW(), expires_at) and formats it as 2d 3h 15m. Permanent bans still display as permanent.

M3 β€” Improved syntax messages for !ban and !kickban

The error messages shown on bad usage now include concrete examples:

You must be logged in to reply.