mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(discord): honor wildcard '*' in DISCORD_ALLOWED_CHANNELS
allowed_channels: "*" in config (or DISCORD_ALLOWED_CHANNELS="*" env var)
is meant to allow all channels, but the check was comparing numeric channel
IDs against the literal string set {"*"} via set intersection — always empty,
so every message was silently dropped.
Add a "*" short-circuit before the set intersection, consistent with every
other platform's allowlist handling (Signal, Slack, Telegram all do this).
Fixes #14920
This commit is contained in:
parent
f58a16f520
commit
8598746e86
2 changed files with 49 additions and 1 deletions
48
tests/gateway/test_discord_allowed_channels.py
Normal file
48
tests/gateway/test_discord_allowed_channels.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
"""Regression guard for #14920: DISCORD_ALLOWED_CHANNELS="*" should allow all channels.
|
||||
|
||||
Setting allowed_channels: "*" in config (or DISCORD_ALLOWED_CHANNELS="*" as env var)
|
||||
must behave as a wildcard — i.e. the bot responds in every channel. Previously the
|
||||
literal string "*" was placed into the set and compared against numeric channel IDs via
|
||||
set-intersection, which always produced an empty set, causing every message to be
|
||||
silently dropped.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
def _channel_is_allowed(channel_id: str, allowed_channels_raw: str) -> bool:
|
||||
"""Replicate the channel-allow-list check from discord.py on_message."""
|
||||
if not allowed_channels_raw:
|
||||
return True
|
||||
allowed_channels = {ch.strip() for ch in allowed_channels_raw.split(",") if ch.strip()}
|
||||
if "*" in allowed_channels:
|
||||
return True
|
||||
return bool({channel_id} & allowed_channels)
|
||||
|
||||
|
||||
class TestDiscordAllowedChannelsWildcard(unittest.TestCase):
|
||||
"""Wildcard and channel-list behaviour for DISCORD_ALLOWED_CHANNELS."""
|
||||
|
||||
def test_wildcard_allows_any_channel(self):
|
||||
"""'*' should allow messages from any channel ID."""
|
||||
self.assertTrue(_channel_is_allowed("1234567890", "*"))
|
||||
|
||||
def test_wildcard_in_list_allows_any_channel(self):
|
||||
"""'*' mixed with other entries still allows any channel."""
|
||||
self.assertTrue(_channel_is_allowed("9999999999", "111,*,222"))
|
||||
|
||||
def test_exact_match_allowed(self):
|
||||
"""Channel ID present in the explicit list is allowed."""
|
||||
self.assertTrue(_channel_is_allowed("1234567890", "1234567890,9876543210"))
|
||||
|
||||
def test_non_matching_channel_blocked(self):
|
||||
"""Channel ID absent from the explicit list is blocked."""
|
||||
self.assertFalse(_channel_is_allowed("5555555555", "1234567890,9876543210"))
|
||||
|
||||
def test_empty_allowlist_allows_all(self):
|
||||
"""Empty DISCORD_ALLOWED_CHANNELS means no restriction."""
|
||||
self.assertTrue(_channel_is_allowed("1234567890", ""))
|
||||
|
||||
def test_whitespace_only_entry_ignored(self):
|
||||
"""Entries that are only whitespace are stripped and ignored."""
|
||||
self.assertFalse(_channel_is_allowed("1234567890", " , "))
|
||||
Loading…
Add table
Add a link
Reference in a new issue