fix: Improve channel validation logic in BaseCommand

- Added checks for empty channels and normalized channel names for case-insensitive comparison.
- Updated allowed channels validation to ensure consistent handling of channel names, enhancing command execution accuracy.
This commit is contained in:
agessaman committed 2026-01-27 15:47:56 -08:00
1 parent ffdc906b22
commit 9423178b33
1 file changed
+13 -3
+13 -3
View File
@@ -316,16 +316,26 @@ class BaseCommand(ABC):
if message.is_dm:
return True
if not message.channel:
return False
# Normalize channel name for comparison (case-insensitive, preserve # prefix)
message_channel_normalized = message.channel.lower().strip()
# If no channel override, use global monitor_channels
if self.allowed_channels is None:
return message.channel in self.bot.command_manager.monitor_channels
monitor_normalized = {ch.lower().strip() for ch in self.bot.command_manager.monitor_channels}
return message_channel_normalized in monitor_normalized
# If empty list, command is disabled for channels (DM only)
if self.allowed_channels == []:
return False
# Check if channel is in allowed list
return message.channel in self.allowed_channels
# Normalize allowed channels for comparison (case-insensitive, preserve # prefix)
allowed_normalized = {ch.lower().strip() for ch in self.allowed_channels}
# Check if channel matches allowed list
return message_channel_normalized in allowed_normalized
def can_execute(self, message: MeshMessage) -> bool:
"""Check if this command can be executed with the given message.