mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:51:23 +00:00
refactor(channels): share target parsing helpers
This commit is contained in:
@@ -2,6 +2,8 @@ import type { DirectoryConfigParams } from "../channels/plugins/directory-config
|
||||
import {
|
||||
buildMessagingTarget,
|
||||
ensureTargetId,
|
||||
parseTargetMention,
|
||||
parseTargetPrefix,
|
||||
requireTargetKind,
|
||||
type MessagingTarget,
|
||||
type MessagingTargetKind,
|
||||
@@ -23,21 +25,32 @@ export function parseDiscordTarget(
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const mentionMatch = trimmed.match(/^<@!?(\d+)>$/);
|
||||
if (mentionMatch) {
|
||||
return buildMessagingTarget("user", mentionMatch[1], trimmed);
|
||||
const mentionTarget = parseTargetMention({
|
||||
raw: trimmed,
|
||||
mentionPattern: /^<@!?(\d+)>$/,
|
||||
kind: "user",
|
||||
});
|
||||
if (mentionTarget) {
|
||||
return mentionTarget;
|
||||
}
|
||||
if (trimmed.startsWith("user:")) {
|
||||
const id = trimmed.slice("user:".length).trim();
|
||||
return id ? buildMessagingTarget("user", id, trimmed) : undefined;
|
||||
}
|
||||
if (trimmed.startsWith("channel:")) {
|
||||
const id = trimmed.slice("channel:".length).trim();
|
||||
return id ? buildMessagingTarget("channel", id, trimmed) : undefined;
|
||||
}
|
||||
if (trimmed.startsWith("discord:")) {
|
||||
const id = trimmed.slice("discord:".length).trim();
|
||||
return id ? buildMessagingTarget("user", id, trimmed) : undefined;
|
||||
const prefixedTarget =
|
||||
parseTargetPrefix({
|
||||
raw: trimmed,
|
||||
prefix: "user:",
|
||||
kind: "user",
|
||||
}) ??
|
||||
parseTargetPrefix({
|
||||
raw: trimmed,
|
||||
prefix: "channel:",
|
||||
kind: "channel",
|
||||
}) ??
|
||||
parseTargetPrefix({
|
||||
raw: trimmed,
|
||||
prefix: "discord:",
|
||||
kind: "user",
|
||||
});
|
||||
if (prefixedTarget) {
|
||||
return prefixedTarget;
|
||||
}
|
||||
if (trimmed.startsWith("@")) {
|
||||
const candidate = trimmed.slice(1).trim();
|
||||
|
||||
Reference in New Issue
Block a user