Deps: Bump twilight versions -> [0.5, 0.7) (#87)
Includes two more small changes too small to warrant PRs. 1. Removes the `shard_count` parameter from `Songbird::twilight` & `Songbird::twilight_from_config` since the cluster contains it. 2. Drops the `Arc` wrapper around `Songbird` to match against an upcoming twilight 0.7 change
This commit is contained in:
committed by
Kyle Simpson
parent
54e75bdc28
commit
1b0bcbb5f6
@@ -8,14 +8,13 @@ edition = "2018"
|
||||
futures = "0.3"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.2"
|
||||
serde_json = { version = "1" }
|
||||
tokio = { features = ["macros", "rt-multi-thread", "sync"], version = "1" }
|
||||
twilight-gateway = "0.5"
|
||||
twilight-http = "0.5"
|
||||
twilight-model = "0.5"
|
||||
twilight-standby = "0.5"
|
||||
twilight-gateway = "0.6"
|
||||
twilight-http = "0.6"
|
||||
twilight-model = "0.6"
|
||||
twilight-standby = "0.6"
|
||||
|
||||
[dependencies.songbird]
|
||||
path = "../.."
|
||||
default-features = false
|
||||
features = ["twilight-rustls", "gateway", "driver", "zlib-stock"]
|
||||
path = "../.."
|
||||
features = ["driver", "twilight-rustls", "zlib-stock"]
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! THIS SOFTWARE.
|
||||
//!
|
||||
//!
|
||||
//! [basic lavalink bot]: https://github.com/twilight-rs/twilight/tree/trunk/lavalink/examples/basic-lavalink-bot
|
||||
//! [basic lavalink bot]: https://github.com/twilight-rs/twilight/tree/main/lavalink/examples/basic-lavalink-bot
|
||||
|
||||
use futures::StreamExt;
|
||||
use songbird::{
|
||||
@@ -33,12 +33,14 @@ use twilight_http::Client as HttpClient;
|
||||
use twilight_model::{channel::Message, gateway::payload::MessageCreate, id::GuildId};
|
||||
use twilight_standby::Standby;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct State {
|
||||
type State = Arc<StateRef>;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct StateRef {
|
||||
cluster: Cluster,
|
||||
http: HttpClient,
|
||||
trackdata: Arc<RwLock<HashMap<GuildId, TrackHandle>>>,
|
||||
songbird: Arc<Songbird>,
|
||||
trackdata: RwLock<HashMap<GuildId, TrackHandle>>,
|
||||
songbird: Songbird,
|
||||
standby: Standby,
|
||||
}
|
||||
|
||||
@@ -57,47 +59,47 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
// Initialize the tracing subscriber.
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let token = env::var("DISCORD_TOKEN")?;
|
||||
let (mut events, state) = {
|
||||
let token = env::var("DISCORD_TOKEN")?;
|
||||
|
||||
let http = HttpClient::new(&token);
|
||||
|
||||
let (cluster, mut events) =
|
||||
Cluster::new(token, Intents::GUILD_MESSAGES | Intents::GUILD_VOICE_STATES).await?;
|
||||
|
||||
let state = {
|
||||
let user_id = http.current_user().await?.id;
|
||||
|
||||
let shard_count = cluster.shards().len();
|
||||
let songbird = Songbird::twilight(cluster.clone(), shard_count as u64, user_id);
|
||||
let http = HttpClient::new(token.clone());
|
||||
let user_id = http.current_user().exec().await?.model().await?.id;
|
||||
|
||||
let intents = Intents::GUILD_MESSAGES | Intents::GUILD_VOICE_STATES;
|
||||
let (cluster, events) = Cluster::new(token, intents).await?;
|
||||
cluster.up().await;
|
||||
|
||||
State {
|
||||
cluster,
|
||||
http,
|
||||
trackdata: Default::default(),
|
||||
songbird,
|
||||
standby: Standby::new(),
|
||||
}
|
||||
let songbird = Songbird::twilight(cluster.clone(), user_id);
|
||||
|
||||
(
|
||||
events,
|
||||
Arc::new(StateRef {
|
||||
cluster,
|
||||
http,
|
||||
trackdata: Default::default(),
|
||||
songbird,
|
||||
standby: Standby::new(),
|
||||
},
|
||||
))
|
||||
};
|
||||
|
||||
while let Some(event) = events.next().await {
|
||||
state.standby.process(&event.1);
|
||||
state.songbird.process(&event.1).await;
|
||||
while let Some((_, event)) = events.next().await {
|
||||
state.standby.process(&event);
|
||||
state.songbird.process(&event).await;
|
||||
|
||||
if let Event::MessageCreate(msg) = event.1 {
|
||||
if let Event::MessageCreate(msg) = event {
|
||||
if msg.guild_id.is_none() || !msg.content.starts_with('!') {
|
||||
continue;
|
||||
}
|
||||
|
||||
match msg.content.splitn(2, ' ').next() {
|
||||
Some("!join") => spawn(join(msg.0, state.clone())),
|
||||
Some("!leave") => spawn(leave(msg.0, state.clone())),
|
||||
Some("!pause") => spawn(pause(msg.0, state.clone())),
|
||||
Some("!play") => spawn(play(msg.0, state.clone())),
|
||||
Some("!seek") => spawn(seek(msg.0, state.clone())),
|
||||
Some("!stop") => spawn(stop(msg.0, state.clone())),
|
||||
Some("!volume") => spawn(volume(msg.0, state.clone())),
|
||||
Some("!join") => spawn(join(msg.0, Arc::clone(&state))),
|
||||
Some("!leave") => spawn(leave(msg.0, Arc::clone(&state))),
|
||||
Some("!pause") => spawn(pause(msg.0, Arc::clone(&state))),
|
||||
Some("!play") => spawn(play(msg.0, Arc::clone(&state))),
|
||||
Some("!seek") => spawn(seek(msg.0, Arc::clone(&state))),
|
||||
Some("!stop") => spawn(stop(msg.0, Arc::clone(&state))),
|
||||
Some("!volume") => spawn(volume(msg.0, Arc::clone(&state))),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
@@ -111,6 +113,7 @@ async fn join(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("What's the channel ID you want me to join?")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
let author_id = msg.author.id;
|
||||
@@ -134,7 +137,8 @@ async fn join(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
state
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content(content)?
|
||||
.content(&content)?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -155,6 +159,7 @@ async fn leave(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("Left the channel")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -170,6 +175,7 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("What's the URL of the audio to play?")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
let author_id = msg.author.id;
|
||||
@@ -202,7 +208,8 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
state
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content(content)?
|
||||
.content(&content)?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||
@@ -217,6 +224,7 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("Didn't find any results")?
|
||||
.exec()
|
||||
.await?;
|
||||
}
|
||||
|
||||
@@ -241,11 +249,11 @@ async fn pause(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
PlayMode::Play => {
|
||||
let _success = handle.pause();
|
||||
false
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
let _success = handle.play();
|
||||
true
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let action = if paused { "Unpaused" } else { "Paused" };
|
||||
@@ -258,7 +266,8 @@ async fn pause(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
state
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content(content)?
|
||||
.content(&content)?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -274,6 +283,7 @@ async fn seek(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("Where in the track do you want to seek to (in seconds)?")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
let author_id = msg.author.id;
|
||||
@@ -302,7 +312,8 @@ async fn seek(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
state
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content(content)?
|
||||
.content(&content)?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -326,6 +337,7 @@ async fn stop(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("Stopped the track")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -341,6 +353,7 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("What's the volume you want to set (0.0-10.0, 1.0 being the default)?")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
let author_id = msg.author.id;
|
||||
@@ -358,6 +371,7 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content("Invalid volume!")?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
return Ok(());
|
||||
@@ -375,7 +389,8 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
||||
state
|
||||
.http
|
||||
.create_message(msg.channel_id)
|
||||
.content(content)?
|
||||
.content(&content)?
|
||||
.exec()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user