mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-13 09:01:54 +00:00
fix(discord_tool): coerce limit parameter to int before min() call
_search_members() and _fetch_messages() call min(limit, 100) assuming limit is int. Models can pass limit as a string (e.g. "10"), causing TypeError: '<' not supported between instances of 'str' and 'int'. Add try/except int() coercion with safe defaults at the top of both functions, matching the pattern used in session_search fix (#10522).
This commit is contained in:
parent
e19854d893
commit
b288934dff
1 changed files with 8 additions and 0 deletions
|
|
@ -328,6 +328,10 @@ def _member_info(token: str, guild_id: str, user_id: str, **_kwargs: Any) -> str
|
|||
|
||||
def _search_members(token: str, guild_id: str, query: str, limit: int = 20, **_kwargs: Any) -> str:
|
||||
"""Search for guild members by name."""
|
||||
try:
|
||||
limit = int(limit)
|
||||
except (TypeError, ValueError):
|
||||
limit = 20
|
||||
params = {"query": query, "limit": str(min(limit, 100))}
|
||||
members = _discord_request("GET", f"/guilds/{guild_id}/members/search", token, params=params)
|
||||
result = []
|
||||
|
|
@ -350,6 +354,10 @@ def _fetch_messages(
|
|||
**_kwargs: Any,
|
||||
) -> str:
|
||||
"""Fetch recent messages from a channel."""
|
||||
try:
|
||||
limit = int(limit)
|
||||
except (TypeError, ValueError):
|
||||
limit = 50
|
||||
params: Dict[str, str] = {"limit": str(min(limit, 100))}
|
||||
if before:
|
||||
params["before"] = before
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue