mirror of
https://github.com/anthropics/claude-plugins-official.git
synced 2026-03-21 11:53:08 +00:00
Compare commits
6 Commits
add-plugin
...
kenneth/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea382ec6a4 | ||
|
|
9a101ba34c | ||
|
|
521f858e11 | ||
|
|
90accf6fd2 | ||
|
|
562a27feec | ||
|
|
8140fbad22 |
@@ -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 } from 'fs'
|
import { readFileSync, writeFileSync, mkdirSync, readdirSync, rmSync, statSync, renameSync, realpathSync, chmodSync } from 'fs'
|
||||||
import { homedir } from 'os'
|
import { homedir } from 'os'
|
||||||
import { join, sep } from 'path'
|
import { join, sep } from 'path'
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ 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,7 +80,8 @@ 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. Confirm, then show the no-args status so the user sees where they stand.
|
4. `chmod 600 ~/.claude/channels/discord/.env` — the token is a credential.
|
||||||
|
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 } 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'
|
||||||
|
|
||||||
@@ -30,6 +30,8 @@ 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]
|
||||||
@@ -505,6 +507,62 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
|
|||||||
|
|
||||||
await mcp.connect(new StdioServerTransport())
|
await mcp.connect(new StdioServerTransport())
|
||||||
|
|
||||||
|
// Commands are DM-only. Responding in groups would: (1) leak pairing codes via
|
||||||
|
// /status to other group members, (2) confirm bot presence in non-allowlisted
|
||||||
|
// groups, (3) spam channels the operator never approved. Silent drop matches
|
||||||
|
// the gate's behavior for unrecognized groups.
|
||||||
|
|
||||||
|
bot.command('start', async ctx => {
|
||||||
|
if (ctx.chat?.type !== 'private') return
|
||||||
|
const access = loadAccess()
|
||||||
|
if (access.dmPolicy === 'disabled') {
|
||||||
|
await ctx.reply(`This bot isn't accepting new connections.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await ctx.reply(
|
||||||
|
`This bot bridges Telegram to a Claude Code session.\n\n` +
|
||||||
|
`To pair:\n` +
|
||||||
|
`1. DM me anything — you'll get a 6-char code\n` +
|
||||||
|
`2. In Claude Code: /telegram:access pair <code>\n\n` +
|
||||||
|
`After that, DMs here reach that session.`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
bot.command('help', async ctx => {
|
||||||
|
if (ctx.chat?.type !== 'private') return
|
||||||
|
await ctx.reply(
|
||||||
|
`Messages you send here route to a paired Claude Code session. ` +
|
||||||
|
`Text and photos are forwarded; replies and reactions come back.\n\n` +
|
||||||
|
`/start — pairing instructions\n` +
|
||||||
|
`/status — check your pairing state`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
bot.command('status', async ctx => {
|
||||||
|
if (ctx.chat?.type !== 'private') return
|
||||||
|
const from = ctx.from
|
||||||
|
if (!from) return
|
||||||
|
const senderId = String(from.id)
|
||||||
|
const access = loadAccess()
|
||||||
|
|
||||||
|
if (access.allowFrom.includes(senderId)) {
|
||||||
|
const name = from.username ? `@${from.username}` : senderId
|
||||||
|
await ctx.reply(`Paired as ${name}.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [code, p] of Object.entries(access.pending)) {
|
||||||
|
if (p.senderId === senderId) {
|
||||||
|
await ctx.reply(
|
||||||
|
`Pending pairing — run in Claude Code:\n\n/telegram:access pair ${code}`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.reply(`Not paired. Send me a message to get a pairing code.`)
|
||||||
|
})
|
||||||
|
|
||||||
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)
|
||||||
})
|
})
|
||||||
@@ -595,5 +653,13 @@ void bot.start({
|
|||||||
onStart: info => {
|
onStart: info => {
|
||||||
botUsername = info.username
|
botUsername = info.username
|
||||||
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
process.stderr.write(`telegram channel: polling as @${info.username}\n`)
|
||||||
|
void bot.api.setMyCommands(
|
||||||
|
[
|
||||||
|
{ command: 'start', description: 'Welcome and setup guide' },
|
||||||
|
{ command: 'help', description: 'What this bot can do' },
|
||||||
|
{ command: 'status', description: 'Check your pairing status' },
|
||||||
|
],
|
||||||
|
{ scope: { type: 'all_private_chats' } },
|
||||||
|
).catch(() => {})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ 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. Confirm, then show the no-args status so the user sees where they stand.
|
4. `chmod 600 ~/.claude/channels/telegram/.env` — the token is a credential.
|
||||||
|
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