@gonzih/cc-discord 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bot.d.ts +2 -2
- package/dist/bot.js +14 -9
- package/package.json +1 -1
package/dist/bot.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* One ClaudeProcess per channel (or channel:thread) — sessions are isolated per channel.
|
|
4
4
|
*/
|
|
5
5
|
import { Redis } from "ioredis";
|
|
6
|
-
/** Prepend [
|
|
7
|
-
export declare function stampPrompt(text: string, now?: Date): string;
|
|
6
|
+
/** Prepend [DayOfWeek HH:MM] username: so Claude knows when the message was received and from whom. */
|
|
7
|
+
export declare function stampPrompt(text: string, username?: string, now?: Date): string;
|
|
8
8
|
export interface DiscordBotOptions {
|
|
9
9
|
discordToken: string;
|
|
10
10
|
claudeToken?: string;
|
package/dist/bot.js
CHANGED
|
@@ -37,13 +37,14 @@ function computeCostUsd(usage) {
|
|
|
37
37
|
const FLUSH_DELAY_MS = 800;
|
|
38
38
|
// Discord typing indicator: re-send every 9s (indicator expires after ~10s)
|
|
39
39
|
const TYPING_INTERVAL_MS = 9000;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
40
|
+
const DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
41
|
+
/** Prepend [DayOfWeek HH:MM] username: so Claude knows when the message was received and from whom. */
|
|
42
|
+
export function stampPrompt(text, username, now = new Date()) {
|
|
43
|
+
const day = DAYS[now.getDay()];
|
|
44
44
|
const hh = String(now.getHours()).padStart(2, "0");
|
|
45
45
|
const min = String(now.getMinutes()).padStart(2, "0");
|
|
46
|
-
|
|
46
|
+
const header = username ? `[${day} ${hh}:${min}] ${username}: ` : `[${day} ${hh}:${min}] `;
|
|
47
|
+
return header + text;
|
|
47
48
|
}
|
|
48
49
|
function formatTokens(n) {
|
|
49
50
|
if (n >= 1000)
|
|
@@ -285,8 +286,9 @@ export class CcDiscordBot {
|
|
|
285
286
|
if (mappedNs && this.redis) {
|
|
286
287
|
this.writeChatMessage("user", "discord", text, effectiveChannelId);
|
|
287
288
|
this.opts.registerRoutedChannelId?.(mappedNs.namespace, effectiveChannelId);
|
|
289
|
+
const username = msg.member?.displayName ?? msg.author.username;
|
|
288
290
|
try {
|
|
289
|
-
await routeToMetaAgent(mappedNs.namespace, text, this.redis);
|
|
291
|
+
await routeToMetaAgent(mappedNs.namespace, stampPrompt(text, username, msg.createdAt), this.redis);
|
|
290
292
|
}
|
|
291
293
|
catch (err) {
|
|
292
294
|
await msg.channel.send(`Failed to route to ${mappedNs.namespace}: ${err.message}`).catch(() => { });
|
|
@@ -295,9 +297,10 @@ export class CcDiscordBot {
|
|
|
295
297
|
}
|
|
296
298
|
// Local Claude session
|
|
297
299
|
const session = this.getOrCreateSession(effectiveChannelId, msg.channel);
|
|
300
|
+
const username = msg.member?.displayName ?? msg.author.username;
|
|
298
301
|
try {
|
|
299
302
|
session.currentPrompt = text;
|
|
300
|
-
session.claude.sendPrompt(stampPrompt(text));
|
|
303
|
+
session.claude.sendPrompt(stampPrompt(text, username, msg.createdAt));
|
|
301
304
|
this.startTyping(effectiveChannelId, msg.channel, session);
|
|
302
305
|
this.writeChatMessage("user", "discord", text, effectiveChannelId);
|
|
303
306
|
}
|
|
@@ -317,7 +320,8 @@ export class CcDiscordBot {
|
|
|
317
320
|
}
|
|
318
321
|
const session = this.getOrCreateSession(channelId, channel);
|
|
319
322
|
session.currentPrompt = transcript;
|
|
320
|
-
|
|
323
|
+
const voiceUsername = msg.member?.displayName ?? msg.author.username;
|
|
324
|
+
session.claude.sendPrompt(stampPrompt(transcript, voiceUsername, msg.createdAt));
|
|
321
325
|
this.startTyping(channelId, channel, session);
|
|
322
326
|
this.writeChatMessage("user", "discord", transcript, channelId);
|
|
323
327
|
}
|
|
@@ -342,8 +346,9 @@ export class CcDiscordBot {
|
|
|
342
346
|
try {
|
|
343
347
|
const base64Data = await fetchAsBase64(imageUrl);
|
|
344
348
|
const caption = msg.content.trim() || "";
|
|
349
|
+
const imgUsername = msg.member?.displayName ?? msg.author.username;
|
|
345
350
|
const session = this.getOrCreateSession(channelId, channel);
|
|
346
|
-
session.claude.sendImage(base64Data, contentType, stampPrompt(caption));
|
|
351
|
+
session.claude.sendImage(base64Data, contentType, stampPrompt(caption, imgUsername, msg.createdAt));
|
|
347
352
|
this.startTyping(channelId, channel, session);
|
|
348
353
|
}
|
|
349
354
|
catch (err) {
|