mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-20 23:43:07 +00:00
Compare commits
1 Commits
kenneth/te
...
add-plugin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8abd6b19b |
@@ -25,7 +25,7 @@ import {
|
|||||||
type Attachment,
|
type Attachment,
|
||||||
} from 'discord.js'
|
} from 'discord.js'
|
||||||
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 } from 'fs'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { join, sep } from 'path'
|
import { join, sep } from 'path'
|
||||||
|
|
||||||
@@ -37,8 +37,6 @@ const ENV_FILE = join(STATE_DIR, '.env')
|
|||||||
// Load ~/.claude/channels/discord/.env into process.env. Real env wins.
|
// Load ~/.claude/channels/discord/.env into process.env. Real env wins.
|
||||||
// Plugin-spawned servers don't get an env block — this is where the token lives.
|
// Plugin-spawned servers don't get an env block — this is where the token lives.
|
||||||
try {
|
try {
|
||||||
// Token is a credential — lock to owner. No-op on Windows (would need ACLs).
|
|
||||||
chmodSync(ENV_FILE, 0o600)
|
|
||||||
for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
|
for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
|
||||||
const m = line.match(/^(\w+)=(.*)$/)
|
const m = line.match(/^(\w+)=(.*)$/)
|
||||||
if (m && process.env[m[1]] === undefined) process.env[m[1]] = m[2]
|
if (m && process.env[m[1]] === undefined) process.env[m[1]] = m[2]
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ as the correct long-term choice. Don't skip the lockdown offer.
|
|||||||
2. `mkdir -p ~/.claude/channels/discord`
|
2. `mkdir -p ~/.claude/channels/discord`
|
||||||
3. Read existing `.env` if present; update/add the `DISCORD_BOT_TOKEN=` line,
|
3. Read existing `.env` if present; update/add the `DISCORD_BOT_TOKEN=` line,
|
||||||
preserve other keys. Write back, no quotes around the value.
|
preserve other keys. Write back, no quotes around the value.
|
||||||
4. `chmod 600 ~/.claude/channels/discord/.env` — the token is a credential.
|
4. Confirm, then show the no-args status so the user sees where they stand.
|
||||||
5. Confirm, then show the no-args status so the user sees where they stand.
|
|
||||||
|
|
||||||
### `clear` — remove the token
|
### `clear` — remove the token
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
import { Bot, InputFile, type Context } from 'grammy'
|
import { Bot, 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 } from 'fs'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { join, extname, sep } from 'path'
|
import { join, extname, sep } from 'path'
|
||||||
|
|
||||||
@@ -30,8 +30,6 @@ const ENV_FILE = join(STATE_DIR, '.env')
|
|||||||
// Load ~/.claude/channels/telegram/.env into process.env. Real env wins.
|
// Load ~/.claude/channels/telegram/.env into process.env. Real env wins.
|
||||||
// Plugin-spawned servers don't get an env block — this is where the token lives.
|
// Plugin-spawned servers don't get an env block — this is where the token lives.
|
||||||
try {
|
try {
|
||||||
// Token is a credential — lock to owner. No-op on Windows (would need ACLs).
|
|
||||||
chmodSync(ENV_FILE, 0o600)
|
|
||||||
for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
|
for (const line of readFileSync(ENV_FILE, 'utf8').split('\n')) {
|
||||||
const m = line.match(/^(\w+)=(.*)$/)
|
const m = line.match(/^(\w+)=(.*)$/)
|
||||||
if (m && process.env[m[1]] === undefined) process.env[m[1]] = m[2]
|
if (m && process.env[m[1]] === undefined) process.env[m[1]] = m[2]
|
||||||
@@ -304,7 +302,7 @@ function checkApprovals(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!STATIC) setInterval(checkApprovals, 5000).unref()
|
if (!STATIC) setInterval(checkApprovals, 5000)
|
||||||
|
|
||||||
// Telegram caps messages at 4096 chars. Split long replies, preferring
|
// Telegram caps messages at 4096 chars. Split long replies, preferring
|
||||||
// paragraph boundaries when chunkMode is 'newline'.
|
// paragraph boundaries when chunkMode is 'newline'.
|
||||||
@@ -507,24 +505,6 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
|
|
||||||
await mcp.connect(new StdioServerTransport())
|
await mcp.connect(new StdioServerTransport())
|
||||||
|
|
||||||
// When Claude Code closes the MCP connection, stdin gets EOF. Without this
|
|
||||||
// the bot keeps polling forever as a zombie, holding the token and blocking
|
|
||||||
// the next session with 409 Conflict.
|
|
||||||
let shuttingDown = false
|
|
||||||
function shutdown(): void {
|
|
||||||
if (shuttingDown) return
|
|
||||||
shuttingDown = true
|
|
||||||
process.stderr.write('telegram channel: shutting down\n')
|
|
||||||
// bot.stop() signals the poll loop to end; the current getUpdates request
|
|
||||||
// may take up to its long-poll timeout to return. Force-exit after 2s.
|
|
||||||
setTimeout(() => process.exit(0), 2000)
|
|
||||||
void Promise.resolve(bot.stop()).finally(() => process.exit(0))
|
|
||||||
}
|
|
||||||
process.stdin.on('end', shutdown)
|
|
||||||
process.stdin.on('close', shutdown)
|
|
||||||
process.on('SIGTERM', shutdown)
|
|
||||||
process.on('SIGINT', shutdown)
|
|
||||||
|
|
||||||
bot.on('message:text', async ctx => {
|
bot.on('message:text', async ctx => {
|
||||||
await handleInbound(ctx, ctx.message.text, undefined)
|
await handleInbound(ctx, ctx.message.text, undefined)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ offer.
|
|||||||
2. `mkdir -p ~/.claude/channels/telegram`
|
2. `mkdir -p ~/.claude/channels/telegram`
|
||||||
3. Read existing `.env` if present; update/add the `TELEGRAM_BOT_TOKEN=` line,
|
3. Read existing `.env` if present; update/add the `TELEGRAM_BOT_TOKEN=` line,
|
||||||
preserve other keys. Write back, no quotes around the value.
|
preserve other keys. Write back, no quotes around the value.
|
||||||
4. `chmod 600 ~/.claude/channels/telegram/.env` — the token is a credential.
|
4. Confirm, then show the no-args status so the user sees where they stand.
|
||||||
5. Confirm, then show the no-args status so the user sees where they stand.
|
|
||||||
|
|
||||||
### `clear` — remove the token
|
### `clear` — remove the token
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user