refactor: prune legacy group prefixes
This commit is contained in:
@@ -6,6 +6,26 @@ import { isInternalMessageChannel } from "../../utils/message-channel.js";
|
||||
import { normalizeGroupActivation } from "../group-activation.js";
|
||||
import type { TemplateContext } from "../templating.js";
|
||||
|
||||
function extractGroupId(raw: string | undefined | null): string | undefined {
|
||||
const trimmed = (raw ?? "").trim();
|
||||
if (!trimmed) return undefined;
|
||||
const parts = trimmed.split(":").filter(Boolean);
|
||||
if (parts.length >= 3 && (parts[1] === "group" || parts[1] === "channel")) {
|
||||
return parts.slice(2).join(":") || undefined;
|
||||
}
|
||||
if (
|
||||
parts.length >= 2 &&
|
||||
parts[0]?.toLowerCase() === "whatsapp" &&
|
||||
trimmed.toLowerCase().includes("@g.us")
|
||||
) {
|
||||
return parts.slice(1).join(":") || undefined;
|
||||
}
|
||||
if (parts.length >= 2 && (parts[0] === "group" || parts[0] === "channel")) {
|
||||
return parts.slice(1).join(":") || undefined;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function resolveGroupRequireMention(params: {
|
||||
cfg: ClawdbotConfig;
|
||||
ctx: TemplateContext;
|
||||
@@ -15,7 +35,7 @@ export function resolveGroupRequireMention(params: {
|
||||
const rawChannel = groupResolution?.channel ?? ctx.Provider?.trim();
|
||||
const channel = normalizeChannelId(rawChannel);
|
||||
if (!channel) return true;
|
||||
const groupId = groupResolution?.id ?? ctx.From?.replace(/^group:/, "");
|
||||
const groupId = groupResolution?.id ?? extractGroupId(ctx.From);
|
||||
const groupChannel = ctx.GroupChannel?.trim() ?? ctx.GroupSubject?.trim();
|
||||
const groupSpace = ctx.GroupSpace?.trim();
|
||||
const requireMention = getChannelDock(channel)?.groups?.resolveRequireMention?.({
|
||||
@@ -61,7 +81,7 @@ export function buildGroupIntro(params: {
|
||||
activation === "always"
|
||||
? "Activation: always-on (you receive every group message)."
|
||||
: "Activation: trigger-only (you are invoked only when explicitly mentioned; recent context may be included).";
|
||||
const groupId = params.sessionCtx.From?.replace(/^group:/, "");
|
||||
const groupId = params.sessionEntry?.groupId ?? extractGroupId(params.sessionCtx.From);
|
||||
const groupChannel = params.sessionCtx.GroupChannel?.trim() ?? subject;
|
||||
const groupSpace = params.sessionCtx.GroupSpace?.trim();
|
||||
const providerIdsLine = providerId
|
||||
|
||||
Reference in New Issue
Block a user