fix
This commit is contained in:
parent
99dc2c3448
commit
6cdf433197
4 changed files with 1272 additions and 787 deletions
1989
Cargo.lock
generated
1989
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
@ -7,10 +7,10 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
toml = "0.5"
|
toml = "0.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
||||||
# pushing [f32] to [u8] and vice verca
|
# pushing [f32] to [u8] and vice verca
|
||||||
|
@ -18,7 +18,7 @@ byte-slice-cast = "1"
|
||||||
|
|
||||||
# tokio tracing from songbird
|
# tokio tracing from songbird
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.2"
|
tracing-subscriber = "0.3"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
|
|
||||||
### TS stuff
|
### TS stuff
|
||||||
|
@ -49,15 +49,18 @@ version = "0.2"
|
||||||
## discord specific
|
## discord specific
|
||||||
|
|
||||||
[dependencies.songbird]
|
[dependencies.songbird]
|
||||||
version = "0.2"
|
version = "0.3"
|
||||||
features = ["driver","gateway"]
|
features = ["driver","gateway"]
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.10"
|
version = "0.11"
|
||||||
features = ["client", "standard_framework", "voice","native_tls_backend"]
|
features = ["client", "standard_framework", "voice","native_tls_backend"]
|
||||||
|
|
||||||
## tokio
|
## tokio
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "1.0"
|
version = "1.27"
|
||||||
features = ["macros", "rt-multi-thread","signal", "sync"]
|
features = ["macros", "rt-multi-thread","signal", "sync"]
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
songbird = { git = "https://github.com/serenity-rs/songbird", branch="current" }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! Discord handler
|
//! Discord handler
|
||||||
|
|
||||||
|
use std::result::Result::Ok;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serenity::prelude::Mentionable;
|
use serenity::prelude::Mentionable;
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ use serenity::{
|
||||||
use songbird::packet::PacketSize;
|
use songbird::packet::PacketSize;
|
||||||
use songbird::packet::rtp::RtpExtensionPacket;
|
use songbird::packet::rtp::RtpExtensionPacket;
|
||||||
use songbird::{
|
use songbird::{
|
||||||
model::payload::{ClientConnect, ClientDisconnect, Speaking},
|
model::payload::{ClientDisconnect, Speaking},
|
||||||
CoreEvent,
|
CoreEvent,
|
||||||
Event,
|
Event,
|
||||||
EventContext,
|
EventContext,
|
||||||
|
@ -59,7 +60,7 @@ struct Config {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -92,7 +93,9 @@ async fn deafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
check_msg(msg.channel_id.say(&ctx.http, "Joining!").await);
|
||||||
|
|
||||||
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let channel_id = guild
|
let channel_id = guild
|
||||||
|
@ -146,11 +149,6 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
Receiver::new(channel.clone()),
|
Receiver::new(channel.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
handler.add_global_event(
|
|
||||||
CoreEvent::ClientConnect.into(),
|
|
||||||
Receiver::new(channel.clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
handler.add_global_event(
|
handler.add_global_event(
|
||||||
CoreEvent::ClientDisconnect.into(),
|
CoreEvent::ClientDisconnect.into(),
|
||||||
Receiver::new(channel),
|
Receiver::new(channel),
|
||||||
|
@ -158,7 +156,7 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
|
||||||
check_msg(msg.channel_id.say(&ctx.http, &format!("Joined {}", connect_to.mention())).await);
|
check_msg(msg.channel_id.say(&ctx.http, &format!("Joined {}", connect_to.mention())).await);
|
||||||
} else {
|
} else {
|
||||||
check_msg(msg.channel_id.say(&ctx.http, "Error joining the channel").await);
|
check_msg(msg.channel_id.say(&ctx.http, &format!("Error joining the channel, {:?}", conn_result)).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -167,7 +165,7 @@ async fn join(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -190,7 +188,7 @@ async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn mute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -245,7 +243,7 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -278,7 +276,7 @@ async fn play(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -301,7 +299,7 @@ async fn undeafen(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
#[command]
|
#[command]
|
||||||
#[only_in(guilds)]
|
#[only_in(guilds)]
|
||||||
async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn unmute(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
let guild = msg.guild(&ctx.cache).unwrap();
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let manager = songbird::get(ctx).await
|
let manager = songbird::get(ctx).await
|
||||||
|
@ -417,19 +415,6 @@ impl VoiceEventHandler for Receiver {
|
||||||
// containing the call statistics and reporting information.
|
// containing the call statistics and reporting information.
|
||||||
//println!("RTCP packet received: {:?}", packet);
|
//println!("RTCP packet received: {:?}", packet);
|
||||||
},
|
},
|
||||||
Ctx::ClientConnect(
|
|
||||||
ClientConnect {audio_ssrc, video_ssrc, user_id, ..}
|
|
||||||
) => {
|
|
||||||
// You can implement your own logic here to handle a user who has joined the
|
|
||||||
// voice channel e.g., allocate structures, map their SSRC to User ID.
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"Client connected: user {:?} has audio SSRC {:?}, video SSRC {:?}",
|
|
||||||
user_id,
|
|
||||||
audio_ssrc,
|
|
||||||
video_ssrc,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
Ctx::ClientDisconnect(
|
Ctx::ClientDisconnect(
|
||||||
ClientDisconnect {user_id, ..}
|
ClientDisconnect {user_id, ..}
|
||||||
) => {
|
) => {
|
||||||
|
@ -448,4 +433,4 @@ impl VoiceEventHandler for Receiver {
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,5 +1,6 @@
|
||||||
use std::io::Seek;
|
use std::io::Seek;
|
||||||
use std::{io::Read, mem::size_of, sync::Arc, time::Duration};
|
use std::{io::Read, mem::size_of, sync::Arc, time::Duration};
|
||||||
|
use std::result::Result::Ok;
|
||||||
use byte_slice_cast::AsByteSlice;
|
use byte_slice_cast::AsByteSlice;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use songbird::input::reader::MediaSource;
|
use songbird::input::reader::MediaSource;
|
||||||
|
@ -33,6 +34,7 @@ use serenity::{
|
||||||
framework::{
|
framework::{
|
||||||
StandardFramework,
|
StandardFramework,
|
||||||
},
|
},
|
||||||
|
prelude::GatewayIntents,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ impl MediaSource for TsToDiscordPipeline {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn len(&self) -> Option<u64> {
|
fn byte_len(&self) -> Option<u64> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +163,9 @@ async fn main() -> Result<()> {
|
||||||
);
|
);
|
||||||
|
|
||||||
// init discord client
|
// init discord client
|
||||||
let mut client = Client::builder(&config.discord_token)
|
let intents = GatewayIntents::non_privileged()
|
||||||
|
| GatewayIntents::MESSAGE_CONTENT;
|
||||||
|
let mut client = Client::builder(&config.discord_token, intents)
|
||||||
.event_handler(discord::Handler)
|
.event_handler(discord::Handler)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
.register_songbird_with(songbird.into())
|
.register_songbird_with(songbird.into())
|
||||||
|
@ -272,7 +276,7 @@ async fn main() -> Result<()> {
|
||||||
con.send_audio(processed)?;
|
con.send_audio(processed)?;
|
||||||
let dur = start.elapsed();
|
let dur = start.elapsed();
|
||||||
if dur >= Duration::from_millis(1) {
|
if dur >= Duration::from_millis(1) {
|
||||||
eprintln!("Audio pipeline took {}ms",dur.as_millis());
|
debug!(logger, "Audio pipeline took {}ms",dur.as_millis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,4 +333,4 @@ async fn process_discord_audio(voice_buffer: &AudioBufferDiscord, encoder: &Arc<
|
||||||
Some(OutAudio::new(&AudioData::C2S { id: 0, codec: CodecType::OpusMusic, data: &encoded[..length] }))
|
Some(OutAudio::new(&AudioData::C2S { id: 0, codec: CodecType::OpusMusic, data: &encoded[..length] }))
|
||||||
}).await.expect("Join error for audio processing thread!");
|
}).await.expect("Join error for audio processing thread!");
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue