diff options
| author | Austin Hellyer <[email protected]> | 2016-11-29 11:22:33 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-29 11:22:09 -0800 |
| commit | b7f70c6252125a1739066b531ea9e5dff07592a1 (patch) | |
| tree | 9845d27a7c978d5488bf5bd8ffc04cfbcd184448 /src/error.rs | |
| parent | Remove duplicated gateway logic (diff) | |
| download | serenity-b7f70c6252125a1739066b531ea9e5dff07592a1.tar.xz serenity-b7f70c6252125a1739066b531ea9e5dff07592a1.zip | |
Add initial audio support
Audio can be played with support by passing one of the following into
the `Handler::play` method:
`serenity::ext::voice::{ffmpeg, pcm, ytdl}` functions, where
- `ffmpeg` accepts a path (such as a `File`);
- `pcm` accepts a raw reader source;
- `ytdl` accepts a URI, which works with everything youtube-dl supports:
<https://github.com/rg3/youtube-dl/blob/master/docs/supportedsites.md>
The source can be stopped via [`Handler::stop`].
Receive is supported through [`Handler::listen`], which accepts a
`serenity::ext::voice::AudioReceiver` implementation.
An example is provided in the form of the file located at
`./examples/07_voice.rs`, which can be run by cloning the repo and
performing the command `cargo run --example 07_voice`. Prior to running
the command, set a bot token as the value of the env variable
`DISCORD_TOKEN`. The example supports:
- `deafen`: deafens the bot;
- `join`: joins a voice channel by ID. The example is a primitive
implementation, and requires the ID of the channel to be passed to the
bot as a command of `~join 131937933270712320`;
- `leave`: leaves the current voice channel, if in one;
- `mute`: mutes the bot and will continue to play source audio;
- `play`: plays source audio from a URI, through a command like
`~play https://www.youtube.com/watch?v=5KJjBRm0ElA`;
- `ping`: responds with "Pong!" to ensure the bot is working properly;
- `undeafen`: undeafens the bot, if that's actually a word;
- `unmute`: unmutes the bot.
Documentation for audio can be found at:
<https://serenity.zey.moe/serenity/ext/voice/index.html>
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/error.rs b/src/error.rs index 6c534fb..94958fd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,6 +7,8 @@ use serde_json::Value; use websocket::result::WebSocketError; use ::client::gateway::GatewayError; use ::client::ClientError; +#[cfg(feature = "opus")] +use opus::Error as OpusError; #[cfg(feature="voice")] use ::ext::voice::VoiceError; @@ -59,36 +61,46 @@ pub enum Error { Other(&'static str), /// An error from the `url` crate. Url(String), + /// An error from the `rust-websocket` crate. + WebSocket(WebSocketError), + /// An error from the `opus` crate. + #[cfg(feature = "voice")] + Opus(OpusError), /// Indicating an error within the [voice module]. /// /// [voice module]: ext/voice/index.html - #[cfg(feature="voice")] + #[cfg(feature = "voice")] Voice(VoiceError), - /// An error from the `rust-websocket` crate. - WebSocket(WebSocketError), } impl From<IoError> for Error { - fn from(err: IoError) -> Error { - Error::Io(err) + fn from(e: IoError) -> Error { + Error::Io(e) } } impl From<HyperError> for Error { - fn from(err: HyperError) -> Error { - Error::Hyper(err) + fn from(e: HyperError) -> Error { + Error::Hyper(e) } } impl From<JsonError> for Error { - fn from(err: JsonError) -> Error { - Error::Json(err) + fn from(e: JsonError) -> Error { + Error::Json(e) + } +} + +#[cfg(feature = "voice")] +impl From<OpusError> for Error { + fn from(e: OpusError) -> Error { + Error::Opus(e) } } impl From<WebSocketError> for Error { - fn from(err: WebSocketError) -> Error { - Error::WebSocket(err) + fn from(e: WebSocketError) -> Error { + Error::WebSocket(e) } } @@ -96,9 +108,11 @@ impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { Error::Hyper(ref inner) => inner.fmt(f), + Error::Io(ref inner) => inner.fmt(f), Error::Json(ref inner) => inner.fmt(f), Error::WebSocket(ref inner) => inner.fmt(f), - Error::Io(ref inner) => inner.fmt(f), + #[cfg(feature = "voice")] + Error::Opus(ref inner) => inner.fmt(f), _ => f.write_str(self.description()), } } @@ -116,6 +130,8 @@ impl StdError for Error { Error::Url(ref inner) => inner, Error::WebSocket(ref inner) => inner.description(), #[cfg(feature = "voice")] + Error::Opus(ref inner) => inner.description(), + #[cfg(feature = "voice")] Error::Voice(_) => "Voice error", } } |