Add Discord-native hybrid front-end for Jarvis (bot + bridge)
Some checks failed
Release / semantic-release (push) Successful in 59s
tests / Unit tests (Linux, Python 3.11) (push) Successful in 13m45s
Release / build-linux (push) Failing after 7m47s
Release / build-windows (push) Has been cancelled
Release / build-macos (arm64, macos-latest) (push) Has been cancelled
Release / build-macos (x64, macos-15-intel) (push) Has been cancelled
Release / release-main (push) Has been cancelled
Release / release-develop (push) Has been cancelled

Transform isair/jarvis into a Discord-controlled voice assistant running on
the Ubuntu VNC desktop, keeping the mature ~39k-line Python brain intact.

- bot/ (Node + bun, discord.js): /자비스 slash commands (ephemeral),
  voice channel join + voice receive/playback, pluggable VNC screen broadcast
  (selfbot live / noVNC / screenshot)
- bridge/ (Python, Flask): wraps jarvis STT + run_reply_engine + Piper TTS
  behind a thin localhost HTTP API
- .env.example, scripts/ (start_bridge/start_bot/dev), README rewrite,
  docs/language-comparison.md and docs/vnc-xfce-setup.md

Language decision: hybrid (Python brain + Node/bun Discord layer) because
Discord blocks bot video; native screen broadcast only works via a Node
selfbot library.
This commit is contained in:
javis-bot
2026-06-09 14:51:05 +09:00
parent a5bf8d1826
commit c4abf63f38
308 changed files with 94135 additions and 1 deletions

148
bot/src/index.ts Normal file
View File

@@ -0,0 +1,148 @@
/**
* Javis bot entry point.
*
* A normal Discord bot that:
* - exposes /자비스 (join / leave / ask / stream / stop / status)
* - replies to every slash command EPHEMERALLY (only the invoker sees it)
* - joins the caller's voice channel for live voice conversation (brain in bridge/)
* - broadcasts the VNC screen via a pluggable backend (selfbot / novnc / screenshot)
*/
import {
Client,
GatewayIntentBits,
MessageFlags,
type ChatInputCommandInteraction,
type GuildMember,
type TextBasedChannel,
} from "discord.js";
import { AttachmentBuilder } from "discord.js";
import { config } from "./config.ts";
import { ask, health } from "./bridge.ts";
import { joinChannel, leaveGuild, getSession } from "./voice.ts";
import { createStreamer, type ScreenStreamer, type StreamContext } from "./stream/index.ts";
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
});
const streamers = new Map<string, ScreenStreamer>();
async function getStreamer(guildId: string): Promise<ScreenStreamer> {
let s = streamers.get(guildId);
if (!s) {
s = await createStreamer(config);
streamers.set(guildId, s);
}
return s;
}
const eph = { flags: MessageFlags.Ephemeral } as const;
client.once("clientReady", () => {
console.log(`✓ 로그인: ${client.user?.tag} | stream backend: ${config.streamBackend}`);
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName !== "자비스") return;
const i = interaction as ChatInputCommandInteraction;
const sub = i.options.getSubcommand();
try {
switch (sub) {
case "join":
return void (await handleJoin(i));
case "leave":
return void (await handleLeave(i));
case "ask":
return void (await handleAsk(i));
case "stream":
return void (await handleStream(i));
case "stop":
return void (await handleStop(i));
case "status":
return void (await handleStatus(i));
}
} catch (err) {
console.error(`[/자비스 ${sub}]`, err);
const msg = `오류: ${(err as Error).message}`;
if (i.deferred || i.replied) await i.editReply(msg);
else await i.reply({ content: msg, ...eph });
}
});
async function handleJoin(i: ChatInputCommandInteraction) {
const member = i.member as GuildMember;
const channel = member?.voice?.channel;
if (!channel) {
return i.reply({ content: "먼저 음성 채널에 들어간 뒤 다시 호출해주세요.", ...eph });
}
await i.deferReply(eph);
const session = await joinChannel(channel);
session.onTurn = ({ transcript, reply }) =>
console.log(`🗣️ ${transcript}\n🤖 ${reply}`);
await i.editReply(`🎙️ '${channel.name}' 채널에 접속했습니다. 말씀하세요.`);
}
async function handleLeave(i: ChatInputCommandInteraction) {
const left = leaveGuild(i.guildId!);
await i.reply({ content: left ? "음성 채널에서 나갔습니다." : "접속 중인 세션이 없습니다.", ...eph });
}
async function handleAsk(i: ChatInputCommandInteraction) {
const q = i.options.getString("질문", true);
await i.deferReply(eph);
const res = await ask(q);
const reply = res.reply || res.error || "(응답 없음)";
await i.editReply(reply.slice(0, 1900));
}
async function handleStream(i: ChatInputCommandInteraction) {
const member = i.member as GuildMember;
await i.deferReply(eph);
const streamer = await getStreamer(i.guildId!);
const ctx: StreamContext = {
guildId: i.guildId!,
voiceChannelId: member?.voice?.channelId ?? "",
postImage: async (png, name) => {
const ch = i.channel as TextBasedChannel | null;
if (ch && "send" in ch) {
await (ch as any).send({ files: [new AttachmentBuilder(png, { name })] });
}
},
};
if (config.streamBackend === "selfbot" && !ctx.voiceChannelId) {
return i.editReply("셀프봇 송출은 음성 채널 안에서 호출해야 합니다. 음성 채널에 들어간 뒤 다시 시도하세요.");
}
const msg = await streamer.start(ctx);
await i.editReply(msg);
}
async function handleStop(i: ChatInputCommandInteraction) {
const streamer = streamers.get(i.guildId!);
if (!streamer) return i.reply({ content: "송출 중이 아닙니다.", ...eph });
await streamer.stop();
await i.reply({ content: "송출을 중단했습니다.", ...eph });
}
async function handleStatus(i: ChatInputCommandInteraction) {
await i.deferReply(eph);
let brain = "unreachable";
try {
const h = await health();
brain = h.brain_ready ? "ready" : `not-ready${h.brain_error ? " (" + h.brain_error + ")" : ""}`;
} catch {
/* keep unreachable */
}
const session = getSession(i.guildId!);
const streamer = streamers.get(i.guildId!);
await i.editReply(
[
`브릿지 두뇌: ${brain}`,
`음성 세션: ${session ? "접속 중" : "없음"}`,
`송출 백엔드: ${config.streamBackend} (${streamer?.isActive() ? "활성" : "대기"})`,
].join("\n"),
);
}
client.login(config.botToken);