aboutsummaryrefslogtreecommitdiff
path: root/src/ext/voice/threading.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-29 11:22:33 -0800
committerAustin Hellyer <[email protected]>2016-11-29 11:22:09 -0800
commitb7f70c6252125a1739066b531ea9e5dff07592a1 (patch)
tree9845d27a7c978d5488bf5bd8ffc04cfbcd184448 /src/ext/voice/threading.rs
parentRemove duplicated gateway logic (diff)
downloadserenity-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/ext/voice/threading.rs')
-rw-r--r--src/ext/voice/threading.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ext/voice/threading.rs b/src/ext/voice/threading.rs
index 113c23d..bbbffd1 100644
--- a/src/ext/voice/threading.rs
+++ b/src/ext/voice/threading.rs
@@ -13,7 +13,7 @@ pub fn start(target_id: Target, rx: MpscReceiver<Status>) {
ThreadBuilder::new()
.name(name)
.spawn(move || runner(rx))
- .expect("Error starting voice");
+ .expect(&format!("[Voice] Error starting target: {:?}", target_id));
}
fn runner(rx: MpscReceiver<Status>) {
@@ -27,9 +27,11 @@ fn runner(rx: MpscReceiver<Status>) {
match rx.try_recv() {
Ok(Status::Connect(info)) => {
connection = match Connection::new(info) {
- Ok(connection) => Some(connection),
+ Ok(connection) => {
+ Some(connection)
+ },
Err(why) => {
- error!("Error connecting via voice: {:?}", why);
+ warn!("[Voice] Error connecting: {:?}", why);
None
},
@@ -71,7 +73,7 @@ fn runner(rx: MpscReceiver<Status>) {
match update {
Ok(()) => false,
Err(why) => {
- error!("Error updating voice connection: {:?}", why);
+ error!("[Voice] Error updating connection: {:?}", why);
true
},