Discord: gate username lookups
This commit is contained in:
parent
14e4b88bf0
commit
b01612c262
@ -78,6 +78,7 @@ Status: beta.
|
|||||||
- Web UI: auto-expand the chat compose textarea while typing (with sensible max height). (#2950) Thanks @shivamraut101.
|
- Web UI: auto-expand the chat compose textarea while typing (with sensible max height). (#2950) Thanks @shivamraut101.
|
||||||
- Gateway: prevent crashes on transient network errors (fetch failures, timeouts, DNS). Added fatal error detection to only exit on truly critical errors. Fixes #2895, #2879, #2873. (#2980) Thanks @elliotsecops.
|
- Gateway: prevent crashes on transient network errors (fetch failures, timeouts, DNS). Added fatal error detection to only exit on truly critical errors. Fixes #2895, #2879, #2873. (#2980) Thanks @elliotsecops.
|
||||||
- Agents: guard channel tool listActions to avoid plugin crashes. (#2859) Thanks @mbelinky.
|
- Agents: guard channel tool listActions to avoid plugin crashes. (#2859) Thanks @mbelinky.
|
||||||
|
- Discord: avoid resolving bare channel names to user DMs when a username matches. Thanks @thewilloftheshadow.
|
||||||
- Providers: update MiniMax API endpoint and compatibility mode. (#3064) Thanks @hlbbbbbbb.
|
- Providers: update MiniMax API endpoint and compatibility mode. (#3064) Thanks @hlbbbbbbb.
|
||||||
- Telegram: treat more network errors as recoverable in polling. (#3013) Thanks @ryancontent.
|
- Telegram: treat more network errors as recoverable in polling. (#3013) Thanks @ryancontent.
|
||||||
- Discord: resolve usernames to user IDs for outbound messages. (#2649) Thanks @nonggialiang.
|
- Discord: resolve usernames to user IDs for outbound messages. (#2649) Thanks @nonggialiang.
|
||||||
|
|||||||
@ -81,11 +81,14 @@ export async function resolveDiscordTarget(
|
|||||||
const trimmed = raw.trim();
|
const trimmed = raw.trim();
|
||||||
if (!trimmed) return undefined;
|
if (!trimmed) return undefined;
|
||||||
|
|
||||||
// If already a known format, parse directly
|
const shouldLookup = isExplicitUserLookup(trimmed, options);
|
||||||
const directParse = parseDiscordTarget(trimmed, options);
|
const directParse = safeParseDiscordTarget(trimmed, options);
|
||||||
if (directParse && directParse.kind !== "channel" && !isLikelyUsername(trimmed)) {
|
if (directParse && directParse.kind !== "channel") {
|
||||||
return directParse;
|
return directParse;
|
||||||
}
|
}
|
||||||
|
if (!shouldLookup) {
|
||||||
|
return directParse ?? parseDiscordTarget(trimmed, options);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to resolve as a username via directory lookup
|
// Try to resolve as a username via directory lookup
|
||||||
try {
|
try {
|
||||||
@ -110,15 +113,29 @@ export async function resolveDiscordTarget(
|
|||||||
return parseDiscordTarget(trimmed, options);
|
return parseDiscordTarget(trimmed, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function safeParseDiscordTarget(
|
||||||
* Check if a string looks like a Discord username (not a mention, prefix, or ID).
|
input: string,
|
||||||
* Usernames typically don't start with special characters except underscore.
|
options: DiscordTargetParseOptions,
|
||||||
*/
|
): MessagingTarget | undefined {
|
||||||
function isLikelyUsername(input: string): boolean {
|
try {
|
||||||
// Skip if it's already a known format
|
return parseDiscordTarget(input, options);
|
||||||
if (/^(user:|channel:|discord:|@|<@!?)|[\d]+$/.test(input)) {
|
} catch {
|
||||||
return false;
|
return undefined;
|
||||||
}
|
}
|
||||||
// Likely a username if it doesn't match known patterns
|
}
|
||||||
return true;
|
|
||||||
|
function isExplicitUserLookup(input: string, options: DiscordTargetParseOptions): boolean {
|
||||||
|
if (/^<@!?(\d+)>$/.test(input)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (/^(user:|discord:)/.test(input)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (input.startsWith("@")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (/^\d+$/.test(input)) {
|
||||||
|
return options.defaultKind === "user";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user