feat(voice): Pas 7 — discord_voice.py slash group + discord_bot wiring (CONVERGENCE)

src/adapters/discord_voice.py (NEW, ~280 linii):
- /voice slash group cu subcommands: join, leave, doctor, mirror on|off,
  record on|off
- warmup_models() async — eager faster-whisper + silero-vad load la
  on_ready pe background task
- _voice_load_error guard — /voice join responds ephemeral graceful
  dacă models load fail
- _voice_sessions: dict[int, VoiceSession] keyed pe guild_id
- _get_whitelist() re-reads config la fiecare apel — runtime edits la
  voice.allowed_user_ids fără bot restart
- Double-join guard, try/except graceful pe connect/listen/play/presence
- /voice doctor surfaces _voice_load_error + libopus state ephemeral
- await interaction.response.defer(ephemeral=True) în orice voice
  command (Discord 3s timeout pattern din CLAUDE.md)

src/adapters/discord_bot.py — 3 surgical edits:
- Linia 115: intents.voice_states = True (după intents.message_content)
- Liniile 963-966: import + register_voice(tree, client) +
  tree.add_command(voice_group), după /audio body
- Liniile 1126-1130: discord_voice._models_warmup_future =
  asyncio.create_task(discord_voice.warmup_models()) la end of on_ready

Adapted la pipeline.py API actual (channel_id int nu str, kw-only args
după *, EchoVoiceSink(session, bot_user_id) signature, loop kwarg
mandatory pentru cross-thread bot.change_presence).

Smoke import OK. test_discord.py 61 pass / 4 fail (pre-existing pe
master, verificat via git stash). test_voice_session_cleanup 5/5 +
test_voice_adapter_contract 22/22.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 14:55:57 +00:00
parent 23666f7910
commit 13931db953
2 changed files with 307 additions and 0 deletions

View File

@@ -112,6 +112,7 @@ def create_bot(config: Config) -> discord.Client:
intents = discord.Intents.default()
intents.message_content = True
intents.voice_states = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
@@ -958,6 +959,11 @@ def create_bot(config: Config) -> discord.Client:
else:
await interaction.followup.send(result or "Eroare TTS.")
# Voice slash group (Pas 7)
from src.adapters.discord_voice import register as register_voice
voice_group = register_voice(tree, client)
tree.add_command(voice_group)
# --- Ralph commands (autonomous project execution) ---
async def _autocomplete_by_status(
@@ -1118,6 +1124,11 @@ def create_bot(config: Config) -> discord.Client:
from datetime import datetime, timezone
client._ready_at = datetime.now(timezone.utc)
logger.info("Echo Core online as %s", client.user)
# Voice models eager warmup (Pas 7)
from src.adapters import discord_voice
discord_voice._models_warmup_future = asyncio.create_task(
discord_voice.warmup_models()
)
async def _handle_chat(message: discord.Message) -> None:
"""Process a chat message through the router and send the response."""