fix: strip user: prefix from Discord allowed user IDs in onboarding
Users sometimes paste Discord IDs with prefixes like 'user:123456', '<@123456>', or '<@!123456>' from Discord's UI or third-party tools. This caused auth failures since the allowlist contained 'user:123' but the actual user_id from messages was just '123'. Fixes: - Added _clean_discord_id() helper in discord.py to strip common prefixes - Applied sanitization at runtime when parsing DISCORD_ALLOWED_USERS env var - Applied sanitization in hermes setup and hermes gateway setup input flows - Handles user:, <@>, and <@!> prefix formats
This commit is contained in:
parent
e8c9bcea2b
commit
153ccbfd61
3 changed files with 53 additions and 3 deletions
|
|
@ -1935,7 +1935,17 @@ def setup_gateway(config: dict):
|
|||
"Allowed user IDs or usernames (comma-separated, leave empty for open access)"
|
||||
)
|
||||
if allowed_users:
|
||||
save_env_value("DISCORD_ALLOWED_USERS", allowed_users.replace(" ", ""))
|
||||
# Clean up common prefixes (user:123, <@123>, <@!123>)
|
||||
cleaned_ids = []
|
||||
for uid in allowed_users.replace(" ", "").split(","):
|
||||
uid = uid.strip()
|
||||
if uid.startswith("<@") and uid.endswith(">"):
|
||||
uid = uid.lstrip("<@!").rstrip(">")
|
||||
if uid.lower().startswith("user:"):
|
||||
uid = uid[5:]
|
||||
if uid:
|
||||
cleaned_ids.append(uid)
|
||||
save_env_value("DISCORD_ALLOWED_USERS", ",".join(cleaned_ids))
|
||||
print_success("Discord allowlist configured")
|
||||
else:
|
||||
print_info(
|
||||
|
|
@ -1970,8 +1980,18 @@ def setup_gateway(config: dict):
|
|||
)
|
||||
allowed_users = prompt("Allowed user IDs (comma-separated)")
|
||||
if allowed_users:
|
||||
# Clean up common prefixes (user:123, <@123>, <@!123>)
|
||||
cleaned_ids = []
|
||||
for uid in allowed_users.replace(" ", "").split(","):
|
||||
uid = uid.strip()
|
||||
if uid.startswith("<@") and uid.endswith(">"):
|
||||
uid = uid.lstrip("<@!").rstrip(">")
|
||||
if uid.lower().startswith("user:"):
|
||||
uid = uid[5:]
|
||||
if uid:
|
||||
cleaned_ids.append(uid)
|
||||
save_env_value(
|
||||
"DISCORD_ALLOWED_USERS", allowed_users.replace(" ", "")
|
||||
"DISCORD_ALLOWED_USERS", ",".join(cleaned_ids)
|
||||
)
|
||||
print_success("Discord allowlist configured")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue