mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-20 23:43:07 +00:00
Compare commits
2 Commits
kenneth/ch
...
kenneth/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d8042f259 | ||
|
|
1daff5f224 |
@@ -55,9 +55,7 @@ Install the plugin:
|
|||||||
/discord:configure MTIz...
|
/discord:configure MTIz...
|
||||||
```
|
```
|
||||||
|
|
||||||
Writes `DISCORD_BOT_TOKEN=...` to `~/.claude/channels/discord/.env`. You can also write that file by hand, or set the variable in your shell environment — shell takes precedence.
|
Writes `DISCORD_BOT_TOKEN=...` to `.claude/channels/discord/.env` in your project. You can also write that file by hand, or set the variable in your shell environment — shell takes precedence.
|
||||||
|
|
||||||
> To run multiple bots on one machine (different tokens, separate allowlists), point `DISCORD_STATE_DIR` at a different directory per instance.
|
|
||||||
|
|
||||||
**6. Relaunch with the channel flag.**
|
**6. Relaunch with the channel flag.**
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync, statSync,
|
|||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { join, sep } from 'path'
|
import { join, sep } from 'path'
|
||||||
|
|
||||||
const STATE_DIR = process.env.DISCORD_STATE_DIR ?? join(homedir(), '.claude', 'channels', 'discord')
|
const STATE_DIR = join(homedir(), '.claude', 'channels', 'discord')
|
||||||
const ACCESS_FILE = join(STATE_DIR, 'access.json')
|
const ACCESS_FILE = join(STATE_DIR, 'access.json')
|
||||||
const APPROVED_DIR = join(STATE_DIR, 'approved')
|
const APPROVED_DIR = join(STATE_DIR, 'approved')
|
||||||
const ENV_FILE = join(STATE_DIR, '.env')
|
const ENV_FILE = join(STATE_DIR, '.env')
|
||||||
|
|||||||
@@ -35,9 +35,7 @@ Install the plugin:
|
|||||||
/telegram:configure 123456789:AAHfiqksKZ8...
|
/telegram:configure 123456789:AAHfiqksKZ8...
|
||||||
```
|
```
|
||||||
|
|
||||||
Writes `TELEGRAM_BOT_TOKEN=...` to `~/.claude/channels/telegram/.env`. You can also write that file by hand, or set the variable in your shell environment — shell takes precedence.
|
Writes `TELEGRAM_BOT_TOKEN=...` to `.claude/channels/telegram/.env` in your project. You can also write that file by hand, or set the variable in your shell environment — shell takes precedence.
|
||||||
|
|
||||||
> To run multiple bots on one machine (different tokens, separate allowlists), point `TELEGRAM_STATE_DIR` at a different directory per instance.
|
|
||||||
|
|
||||||
**4. Relaunch with the channel flag.**
|
**4. Relaunch with the channel flag.**
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ import {
|
|||||||
ListToolsRequestSchema,
|
ListToolsRequestSchema,
|
||||||
CallToolRequestSchema,
|
CallToolRequestSchema,
|
||||||
} from '@modelcontextprotocol/sdk/types.js'
|
} from '@modelcontextprotocol/sdk/types.js'
|
||||||
import { Bot, InputFile, type Context } from 'grammy'
|
import { Bot, GrammyError, InputFile, type Context } from 'grammy'
|
||||||
import type { ReactionTypeEmoji } from 'grammy/types'
|
import type { ReactionTypeEmoji } from 'grammy/types'
|
||||||
import { randomBytes } from 'crypto'
|
import { randomBytes } from 'crypto'
|
||||||
import { readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync, statSync, renameSync, realpathSync, chmodSync } from 'fs'
|
import { readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync, statSync, renameSync, realpathSync, chmodSync } from 'fs'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { join, extname, sep } from 'path'
|
import { join, extname, sep } from 'path'
|
||||||
|
|
||||||
const STATE_DIR = process.env.TELEGRAM_STATE_DIR ?? join(homedir(), '.claude', 'channels', 'telegram')
|
const STATE_DIR = join(homedir(), '.claude', 'channels', 'telegram')
|
||||||
const ACCESS_FILE = join(STATE_DIR, 'access.json')
|
const ACCESS_FILE = join(STATE_DIR, 'access.json')
|
||||||
const APPROVED_DIR = join(STATE_DIR, 'approved')
|
const APPROVED_DIR = join(STATE_DIR, 'approved')
|
||||||
const ENV_FILE = join(STATE_DIR, '.env')
|
const ENV_FILE = join(STATE_DIR, '.env')
|
||||||
@@ -593,9 +593,35 @@ async function handleInbound(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
void bot.start({
|
// 409 Conflict = another getUpdates consumer is still active (zombie from a
|
||||||
onStart: info => {
|
// previous session, or a second Claude Code instance). Retry with backoff
|
||||||
botUsername = info.username
|
// until the slot frees up instead of crashing on the first rejection.
|
||||||
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
void (async () => {
|
||||||
},
|
for (let attempt = 1; ; attempt++) {
|
||||||
})
|
try {
|
||||||
|
await bot.start({
|
||||||
|
onStart: info => {
|
||||||
|
botUsername = info.username
|
||||||
|
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return // bot.stop() was called — clean exit from the loop
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof GrammyError && err.error_code === 409) {
|
||||||
|
const delay = Math.min(1000 * attempt, 15000)
|
||||||
|
const detail = attempt === 1
|
||||||
|
? ' — another instance is polling (zombie session, or a second Claude Code running?)'
|
||||||
|
: ''
|
||||||
|
process.stderr.write(
|
||||||
|
`telegram channel: 409 Conflict${detail}, retrying in ${delay / 1000}s\n`,
|
||||||
|
)
|
||||||
|
await new Promise(r => setTimeout(r, delay))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// bot.stop() mid-setup rejects with grammy's "Aborted delay" — expected, not an error.
|
||||||
|
if (err instanceof Error && err.message === 'Aborted delay') return
|
||||||
|
process.stderr.write(`telegram channel: polling failed: ${err}\n`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|||||||
Reference in New Issue
Block a user