zaun_bot/voice/position.rs
1//! Position, length, seeking and volume (WIT 0.2.0).
2
3use super::{Voice, wit};
4use crate::types::HostError;
5
6impl Voice {
7 /// Jumps to `ms` into the current track; past the end, the track ends.
8 ///
9 /// # Errors
10 /// `UNSUPPORTED` for live streams and pushed audio, and on hosts that cannot seek;
11 /// `CONFLICT` when nothing plays.
12 pub fn seek(ms: u64) -> Result<(), HostError> {
13 wit::seek(ms)
14 }
15
16 /// Sets the playback volume, 0–200 % (100 when the bot joins).
17 ///
18 /// # Errors
19 /// `BAD_REQUEST` (detail `percent`) above 200, checked before the call; `UNSUPPORTED` on
20 /// hosts without an Opus encoder, which is most of them for now: tell the member and go on.
21 pub fn set_volume(percent: u16) -> Result<(), HostError> {
22 if percent > 200 {
23 return Err(HostError {
24 code: "BAD_REQUEST".to_owned(),
25 detail: Some("percent".to_owned()),
26 retry_after_ms: None,
27 });
28 }
29 wit::set_volume(percent)
30 }
31}