@gonzih/cc-discord 0.1.0

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 ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Discord bot that routes messages to/from a Claude Code subprocess.
3
+ * One ClaudeProcess per channel (or channel:thread) — sessions are isolated per channel.
4
+ */
5
+ import { Redis } from "ioredis";
6
+ /** Prepend [MM-DD HH:mm] so Claude knows when the message was received. */
7
+ export declare function stampPrompt(text: string, now?: Date): string;
8
+ export interface DiscordBotOptions {
9
+ discordToken: string;
10
+ claudeToken?: string;
11
+ cwd?: string;
12
+ allowedUserIds?: string[];
13
+ redis?: Redis;
14
+ namespace?: string;
15
+ guildIds?: string[];
16
+ /** Called when a message is routed to a non-default namespace so the notifier
17
+ * can forward the response back to the originating Discord channel. */
18
+ registerRoutedChannelId?: (namespace: string, channelId: string) => void;
19
+ }
20
+ /** MCP tool call result — returned from callCcAgentTool */
21
+ export type CallToolFn = (toolName: string, args?: Record<string, unknown>) => Promise<string | null>;
22
+ export declare class CcDiscordBot {
23
+ private client;
24
+ private sessions;
25
+ private costs;
26
+ private opts;
27
+ private redis?;
28
+ private namespace;
29
+ private lastActiveChannelId?;
30
+ private cron;
31
+ /** ClaudeProcess running the MCP tool bridge (for callCcAgentTool) */
32
+ private mcpSession?;
33
+ constructor(opts: DiscordBotOptions);
34
+ /** Reverse-lookup: find the channelId string for a cron-stored integer */
35
+ private snowflakeMap;
36
+ private storeSnowflake;
37
+ private reverseSnowflakeLookup;
38
+ /** Session key: "channelId" or "channelId:threadId" for threads */
39
+ private sessionKey;
40
+ /** Get the channel/thread for sending messages */
41
+ private getChannel;
42
+ /** Send text to a channel, splitting at 2000 chars, sending file attachments if detected. */
43
+ private sendToChannel;
44
+ /** Send to a channel by ID — used by notifier callbacks. */
45
+ sendToChannelById(channelId: string, text: string): Promise<void>;
46
+ private isAllowed;
47
+ private handleMessage;
48
+ private handleVoice;
49
+ private handleImage;
50
+ private getOrCreateSession;
51
+ private onClaudeMessage;
52
+ private flushSession;
53
+ private startTyping;
54
+ private killSession;
55
+ private getCost;
56
+ private addUsage;
57
+ private buildCostEmbed;
58
+ private registerSlashCommands;
59
+ private handleSlashCommand;
60
+ private handleCronsCommand;
61
+ /**
62
+ * Call a cc-agent MCP tool via a dedicated ClaudeProcess.
63
+ * Returns the tool result as a string, or null on failure.
64
+ */
65
+ callCcAgentTool(toolName: string, args?: Record<string, unknown>): Promise<string | null>;
66
+ private runCronTask;
67
+ /** Write a message to the Redis chat log. Fire-and-forget. */
68
+ private writeChatMessage;
69
+ /** Returns the last channelId that sent a message. */
70
+ getLastActiveChannelId(): string | undefined;
71
+ /**
72
+ * Feed a text message into the active Claude session for the given channel.
73
+ * Called by the notifier when a UI message arrives via Redis pub/sub.
74
+ */
75
+ handleUserMessage(channelId: string, text: string): Promise<void>;
76
+ /**
77
+ * Forward a cc-agent job notification into an existing Claude session.
78
+ * Unlike handleUserMessage, this never creates a new session.
79
+ */
80
+ forwardNotification(channelId: string, text: string): void;
81
+ stop(): void;
82
+ }