@gonzih/cc-discord 0.1.6 → 0.1.7

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.
@@ -26,11 +26,12 @@ export interface ParsedNotification {
26
26
  }
27
27
  /**
28
28
  * Parse a notification payload.
29
- * Returns the display text plus an optional chatId for per-channel routing.
29
+ * Returns the display text plus an optional chatId for per-channel routing,
30
+ * or null when the routing array excludes "discord".
30
31
  * Appends a [driver] or [driver:model] badge when present.
31
32
  * Appends " cost: $X.XXX" if a numeric cost field is present.
32
33
  */
33
- export declare function parseNotification(raw: string): ParsedNotification;
34
+ export declare function parseNotification(raw: string): ParsedNotification | null;
34
35
  /**
35
36
  * Write a message to the chat log in Redis.
36
37
  * Fire-and-forget — errors are logged but not thrown.
package/dist/notifier.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * cca:chat:log:{namespace} — LPUSH + LTRIM 0 499 (last 500 messages)
11
11
  * cca:chat:outgoing:{namespace} — PUBLISH for web UI to consume
12
12
  */
13
- import { chatLogKey, chatOutgoingChannel, chatIncomingChannel, notifyChannel, metaAgentStatusKey, metaInputKey, } from "@gonzih/cc-wire";
13
+ import { chatLogKey, chatOutgoingChannel, chatIncomingChannel, notifyChannel, notifyListKey, metaAgentStatusKey, metaInputKey, } from "@gonzih/cc-wire";
14
14
  import { splitLongMessage, stripAnsi } from "./formatter.js";
15
15
  function log(level, ...args) {
16
16
  const fn = level === "error" ? console.error : level === "warn" ? console.warn : console.log;
@@ -32,7 +32,8 @@ function shortenModelName(model, driver) {
32
32
  }
33
33
  /**
34
34
  * Parse a notification payload.
35
- * Returns the display text plus an optional chatId for per-channel routing.
35
+ * Returns the display text plus an optional chatId for per-channel routing,
36
+ * or null when the routing array excludes "discord".
36
37
  * Appends a [driver] or [driver:model] badge when present.
37
38
  * Appends " cost: $X.XXX" if a numeric cost field is present.
38
39
  */
@@ -44,6 +45,10 @@ export function parseNotification(raw) {
44
45
  let chatId;
45
46
  try {
46
47
  const parsed = JSON.parse(raw);
48
+ // routing: absent/empty → all transports; non-empty → only listed transports
49
+ if (parsed.routing && parsed.routing.length > 0 && !parsed.routing.includes("discord")) {
50
+ return null;
51
+ }
47
52
  if (parsed.text)
48
53
  text = parsed.text;
49
54
  driver = parsed.driver;
@@ -196,8 +201,8 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
196
201
  clearTimeout(buf.timer);
197
202
  buf.timer = setTimeout(() => flushMetaAgentBuffer(ns, targetChannelId), META_AGENT_FLUSH_DELAY_MS);
198
203
  });
199
- // Poll the notifyChannel(namespace) LIST every 5 seconds
200
- const notifyListKey = notifyChannel(namespace);
204
+ // Poll the notifyListKey(namespace) LIST every 5 seconds
205
+ const notifyListRedisKey = notifyListKey(namespace);
201
206
  const MAX_PER_CYCLE = 20;
202
207
  const pollNotifyList = async () => {
203
208
  const targetId = notifyChannelId ?? getActiveChannelId?.();
@@ -206,7 +211,7 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
206
211
  const items = [];
207
212
  try {
208
213
  for (let i = 0; i < MAX_PER_CYCLE; i++) {
209
- const item = await redis.rpop(notifyListKey);
214
+ const item = await redis.rpop(notifyListRedisKey);
210
215
  if (item === null)
211
216
  break;
212
217
  items.push(item);
@@ -221,7 +226,7 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
221
226
  let remaining = 0;
222
227
  if (items.length === MAX_PER_CYCLE) {
223
228
  try {
224
- remaining = await redis.llen(notifyListKey);
229
+ remaining = await redis.llen(notifyListRedisKey);
225
230
  }
226
231
  catch (err) {
227
232
  log("warn", "notify list llen failed:", err.message);
@@ -229,6 +234,8 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
229
234
  }
230
235
  for (const raw of items) {
231
236
  const notification = parseNotification(raw);
237
+ if (notification === null)
238
+ continue; // routing excludes discord
232
239
  const destChannelId = resolveNotifyChannel(notification.chatId, notifyChannelId, getActiveChannelId, reverseSnowflakeLookup) ?? targetId;
233
240
  bot.sendToChannelById(destChannelId, notification.text).catch((err) => {
234
241
  log("warn", "notify list send failed:", err.message);
@@ -251,6 +258,8 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
251
258
  const incomingCh = chatIncomingChannel(namespace);
252
259
  if (channel === notifyCh) {
253
260
  const notification = parseNotification(message);
261
+ if (notification === null)
262
+ return; // routing excludes discord
254
263
  const targetId = resolveNotifyChannel(notification.chatId, notifyChannelId, getActiveChannelId, reverseSnowflakeLookup);
255
264
  if (targetId != null) {
256
265
  bot.sendToChannelById(targetId, notification.text).catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-discord",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Claude Code Discord bot — chat with Claude Code via Discord",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  "dist/"
19
19
  ],
20
20
  "dependencies": {
21
- "@gonzih/cc-wire": "^0.1.4",
21
+ "@gonzih/cc-wire": "^0.1.6",
22
22
  "discord.js": "^14.0.0",
23
23
  "ioredis": "^5.0.0"
24
24
  },