refactor(bridges): split the sender before the DM and mapping guards, as before

Codex review of 9b86cd63: ChannelBridgeBase ran the DM guard and the channel lookup before parsing "sender: message", but both bridges evaluated `':' in text` first. A non-string text (None, an int) on a DM or unmapped channel used to log "Error handling mesh channel message" with exc_info and now logged a DEBUG skip instead. The split runs first again. The bridge replay now includes None, int, bytes and list texts; it differs from the pre-bridge code on 9b86cd63 and matches it after this commit.
This commit is contained in:
agessaman committed 2026-10-03 14:31:32 -07:00
1 parent bdb59221da
commit 7732464b2b
1 file changed
+11 -9
@@ -150,6 +150,17 @@ class ChannelBridgeBase(BaseServicePlugin):
channel_name = self.bot.channel_manager.get_channel_name(channel_idx)
text = payload.get('text', '')
# Sender is embedded in the text ("sender: message"). Split before the
# guards below, as before: a text that can't be split fails here, logged
# as an error, even for a DM or an unmapped channel.
if ':' in text and not text.startswith('http'):
parts = text.split(':', 1)
sender_name = parts[0].strip()
message_text = parts[1].strip() if len(parts) > 1 else text
else:
sender_name = 'Unknown'
message_text = text
# NEVER bridge DMs (double-check for safety)
if not channel_name or channel_name.lower() in ('dm', 'direct', 'private'):
self.logger.debug("Ignoring DM (DMs are never bridged)")
@@ -160,15 +171,6 @@ class ChannelBridgeBase(BaseServicePlugin):
self.logger.debug(f"Channel '{channel_name}' not configured for {self.bridge_label} bridge")
return
# Sender is embedded in the text ("sender: message")
if ':' in text and not text.startswith('http'):
parts = text.split(':', 1)
sender_name = parts[0].strip()
message_text = parts[1].strip() if len(parts) > 1 else text
else:
sender_name = 'Unknown'
message_text = text
message_text = self._prepare_message_text(message_text)
# Profanity filter: drop (don't bridge), censor (replace with ****), or off