feat: initial discord meeting bot
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from discord.ext import voice_recv
|
||||
|
||||
|
||||
class MeetingRecorder:
|
||||
"""Wrapper around discord-ext-voice-recv's listen/stop_listening API."""
|
||||
|
||||
def __init__(self, voice_client: voice_recv.VoiceRecvClient, output_path: str):
|
||||
self.vc = voice_client
|
||||
self.output_path = output_path
|
||||
self.recording = False
|
||||
self.sink: voice_recv.WaveSink | None = None
|
||||
|
||||
async def start(self, after_callback: Callable[[Exception | None], None]) -> None:
|
||||
if self.vc.is_listening():
|
||||
raise RuntimeError("Voice client is already listening")
|
||||
|
||||
Path(self.output_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
self.sink = voice_recv.WaveSink(self.output_path)
|
||||
self.vc.listen(self.sink, after=after_callback)
|
||||
self.recording = True
|
||||
|
||||
async def stop(self) -> None:
|
||||
if not self.recording:
|
||||
return
|
||||
|
||||
if self.vc.is_listening():
|
||||
self.vc.stop_listening()
|
||||
self.recording = False
|
||||
Reference in New Issue
Block a user