Add send-file directive and Discord/CLI file support (#319)

Co-authored-by: Jason Carreira <jason@visotrust.com>
Co-authored-by: Cameron <cameron@pfiffer.org>
Co-authored-by: Charles Packer <packercharles@gmail.com>
Co-authored-by: Sarah Wooders <sarahwooders@gmail.com>
Co-authored-by: Letta <noreply@letta.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jason Carreira
2026-02-23 18:44:34 -05:00
committed by GitHub
parent ad4c22ba54
commit 1fbd6d5a2e
14 changed files with 364 additions and 22 deletions

View File

@@ -12,6 +12,7 @@ import { isUserAllowed, upsertPairingRequest } from '../pairing/store.js';
import { buildAttachmentPath, downloadToFile } from './attachments.js';
import { HELP_TEXT } from '../core/commands.js';
import { isGroupAllowed, isGroupUserAllowed, resolveGroupMode, resolveReceiveBotMessages, type GroupModeConfig } from './group-mode.js';
import { basename } from 'node:path';
// Dynamic import to avoid requiring Discord deps if not used
let Client: typeof import('discord.js').Client;
@@ -346,6 +347,23 @@ Ask the bot owner to approve with:
return { messageId: result.id };
}
async sendFile(file: OutboundFile): Promise<{ messageId: string }> {
if (!this.client) throw new Error('Discord not started');
const channel = await this.client.channels.fetch(file.chatId);
if (!channel || !channel.isTextBased() || !('send' in channel)) {
throw new Error(`Discord channel not found or not text-based: ${file.chatId}`);
}
const payload = {
content: file.caption || undefined,
files: [
{ attachment: file.filePath, name: basename(file.filePath) },
],
};
const result = await (channel as { send: (options: typeof payload) => Promise<{ id: string }> }).send(payload);
return { messageId: result.id };
}
async editMessage(chatId: string, messageId: string, text: string): Promise<void> {
if (!this.client) throw new Error('Discord not started');
const channel = await this.client.channels.fetch(chatId);
@@ -510,6 +528,7 @@ const DISCORD_EMOJI_ALIAS_TO_UNICODE: Record<string, string> = {
tada: '\u{1F389}',
clap: '\u{1F44F}',
ok_hand: '\u{1F44C}',
white_check_mark: '\u2705',
};
function resolveDiscordEmoji(input: string): string {