Skip to content

Commit 8451b08

Browse files
committed
fix(discord): plumb RawBody for commands
1 parent 3a32cde commit 8451b08

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/auto-reply/reply.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ import {
6060
defaultGroupActivation,
6161
resolveGroupRequireMention,
6262
} from "./reply/groups.js";
63-
import { stripMentions, stripStructuralPrefixes } from "./reply/mentions.js";
63+
import {
64+
CURRENT_MESSAGE_MARKER,
65+
stripMentions,
66+
stripStructuralPrefixes,
67+
} from "./reply/mentions.js";
6468
import {
6569
createModelSelectionState,
6670
resolveContextTokens,
@@ -429,7 +433,6 @@ export async function getReplyFromConfig(
429433
hasQueueDirective: false,
430434
queueReset: false,
431435
};
432-
const marker = "[Current message - respond to this]";
433436
const existingBody = sessionCtx.BodyStripped ?? sessionCtx.Body ?? "";
434437
const cleanedBody = (() => {
435438
if (!existingBody) return parsedDirectives.cleaned;
@@ -439,15 +442,20 @@ export async function getReplyFromConfig(
439442
}).cleaned;
440443
}
441444

442-
const markerIndex = existingBody.indexOf(marker);
445+
const markerIndex = existingBody.indexOf(CURRENT_MESSAGE_MARKER);
443446
if (markerIndex < 0) {
444447
return parseInlineDirectives(existingBody, {
445448
modelAliases: configuredAliases,
446449
}).cleaned;
447450
}
448451

449-
const head = existingBody.slice(0, markerIndex + marker.length);
450-
const tail = existingBody.slice(markerIndex + marker.length);
452+
const head = existingBody.slice(
453+
0,
454+
markerIndex + CURRENT_MESSAGE_MARKER.length,
455+
);
456+
const tail = existingBody.slice(
457+
markerIndex + CURRENT_MESSAGE_MARKER.length,
458+
);
451459
const cleanedTail = parseInlineDirectives(tail, {
452460
modelAliases: configuredAliases,
453461
}).cleaned;

src/auto-reply/reply/mentions.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function deriveMentionPatterns(identity?: { name?: string; emoji?: string }) {
2323

2424
const BACKSPACE_CHAR = "\u0008";
2525

26+
export const CURRENT_MESSAGE_MARKER = "[Current message - respond to this]";
27+
2628
function normalizeMentionPattern(pattern: string): string {
2729
if (!pattern.includes(BACKSPACE_CHAR)) return pattern;
2830
return pattern.split(BACKSPACE_CHAR).join("\\b");
@@ -87,9 +89,12 @@ export function matchesMentionPatterns(
8789
export function stripStructuralPrefixes(text: string): string {
8890
// Ignore wrapper labels, timestamps, and sender prefixes so directive-only
8991
// detection still works in group batches that include history/context.
90-
const marker = "[Current message - respond to this]";
91-
const afterMarker = text.includes(marker)
92-
? text.slice(text.indexOf(marker) + marker.length).trimStart()
92+
const afterMarker = text.includes(CURRENT_MESSAGE_MARKER)
93+
? text
94+
.slice(
95+
text.indexOf(CURRENT_MESSAGE_MARKER) + CURRENT_MESSAGE_MARKER.length,
96+
)
97+
.trimStart()
9398
: text;
9499

95100
return afterMarker

src/discord/monitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ export function createDiscordMessageHandler(params: {
10881088
});
10891089
const ctxPayload = {
10901090
Body: combinedBody,
1091+
RawBody: baseText,
10911092
From: isDirectMessage
10921093
? `discord:${author.id}`
10931094
: `group:${message.channelId}`,

0 commit comments

Comments
 (0)