feat: add sound listener hook to MumbleBot
Allow plugins to register callbacks for incoming voice PCM via bot._sound_listeners. Empty list by default = zero overhead.
This commit is contained in:
@@ -158,6 +158,7 @@ class MumbleBot:
|
||||
self._loop: asyncio.AbstractEventLoop | None = None
|
||||
self._last_voice_ts: float = 0.0
|
||||
self._connect_count: int = 0
|
||||
self._sound_listeners: list = []
|
||||
|
||||
rate_cfg = config.get("bot", {})
|
||||
self._bucket = _TokenBucket(
|
||||
@@ -235,6 +236,11 @@ class MumbleBot:
|
||||
if prev == 0.0:
|
||||
name = user["name"] if isinstance(user, dict) else "?"
|
||||
log.info("mumble: first voice packet from %s", name)
|
||||
for fn in self._sound_listeners:
|
||||
try:
|
||||
fn(user, sound_chunk)
|
||||
except Exception:
|
||||
log.exception("mumble: sound listener error")
|
||||
|
||||
def _on_text_message(self, message) -> None:
|
||||
"""Callback from pymumble thread: text message received.
|
||||
|
||||
Reference in New Issue
Block a user