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
@@ -103,12 +103,12 @@ default-features = false
|
|||||||
|
|
||||||
[dependencies.twilight-gateway]
|
[dependencies.twilight-gateway]
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.5"
|
version = ">=0.5, <0.7"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.twilight-model]
|
[dependencies.twilight-model]
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.5"
|
version = ">=0.5, <0.7"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
[dependencies.typemap_rev]
|
[dependencies.typemap_rev]
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ edition = "2018"
|
|||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.2"
|
tracing-subscriber = "0.2"
|
||||||
serde_json = { version = "1" }
|
|
||||||
tokio = { features = ["macros", "rt-multi-thread", "sync"], version = "1" }
|
tokio = { features = ["macros", "rt-multi-thread", "sync"], version = "1" }
|
||||||
twilight-gateway = "0.5"
|
twilight-gateway = "0.6"
|
||||||
twilight-http = "0.5"
|
twilight-http = "0.6"
|
||||||
twilight-model = "0.5"
|
twilight-model = "0.6"
|
||||||
twilight-standby = "0.5"
|
twilight-standby = "0.6"
|
||||||
|
|
||||||
[dependencies.songbird]
|
[dependencies.songbird]
|
||||||
path = "../.."
|
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["twilight-rustls", "gateway", "driver", "zlib-stock"]
|
path = "../.."
|
||||||
|
features = ["driver", "twilight-rustls", "zlib-stock"]
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//! THIS SOFTWARE.
|
//! 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 futures::StreamExt;
|
||||||
use songbird::{
|
use songbird::{
|
||||||
@@ -33,12 +33,14 @@ use twilight_http::Client as HttpClient;
|
|||||||
use twilight_model::{channel::Message, gateway::payload::MessageCreate, id::GuildId};
|
use twilight_model::{channel::Message, gateway::payload::MessageCreate, id::GuildId};
|
||||||
use twilight_standby::Standby;
|
use twilight_standby::Standby;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
type State = Arc<StateRef>;
|
||||||
struct State {
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct StateRef {
|
||||||
cluster: Cluster,
|
cluster: Cluster,
|
||||||
http: HttpClient,
|
http: HttpClient,
|
||||||
trackdata: Arc<RwLock<HashMap<GuildId, TrackHandle>>>,
|
trackdata: RwLock<HashMap<GuildId, TrackHandle>>,
|
||||||
songbird: Arc<Songbird>,
|
songbird: Songbird,
|
||||||
standby: Standby,
|
standby: Standby,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,47 +59,47 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|||||||
// Initialize the tracing subscriber.
|
// Initialize the tracing subscriber.
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
let (mut events, state) = {
|
||||||
let token = env::var("DISCORD_TOKEN")?;
|
let token = env::var("DISCORD_TOKEN")?;
|
||||||
|
|
||||||
let http = HttpClient::new(&token);
|
let http = HttpClient::new(token.clone());
|
||||||
|
let user_id = http.current_user().exec().await?.model().await?.id;
|
||||||
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 intents = Intents::GUILD_MESSAGES | Intents::GUILD_VOICE_STATES;
|
||||||
|
let (cluster, events) = Cluster::new(token, intents).await?;
|
||||||
cluster.up().await;
|
cluster.up().await;
|
||||||
|
|
||||||
State {
|
let songbird = Songbird::twilight(cluster.clone(), user_id);
|
||||||
|
|
||||||
|
(
|
||||||
|
events,
|
||||||
|
Arc::new(StateRef {
|
||||||
cluster,
|
cluster,
|
||||||
http,
|
http,
|
||||||
trackdata: Default::default(),
|
trackdata: Default::default(),
|
||||||
songbird,
|
songbird,
|
||||||
standby: Standby::new(),
|
standby: Standby::new(),
|
||||||
}
|
},
|
||||||
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
while let Some(event) = events.next().await {
|
while let Some((_, event)) = events.next().await {
|
||||||
state.standby.process(&event.1);
|
state.standby.process(&event);
|
||||||
state.songbird.process(&event.1).await;
|
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('!') {
|
if msg.guild_id.is_none() || !msg.content.starts_with('!') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match msg.content.splitn(2, ' ').next() {
|
match msg.content.splitn(2, ' ').next() {
|
||||||
Some("!join") => spawn(join(msg.0, state.clone())),
|
Some("!join") => spawn(join(msg.0, Arc::clone(&state))),
|
||||||
Some("!leave") => spawn(leave(msg.0, state.clone())),
|
Some("!leave") => spawn(leave(msg.0, Arc::clone(&state))),
|
||||||
Some("!pause") => spawn(pause(msg.0, state.clone())),
|
Some("!pause") => spawn(pause(msg.0, Arc::clone(&state))),
|
||||||
Some("!play") => spawn(play(msg.0, state.clone())),
|
Some("!play") => spawn(play(msg.0, Arc::clone(&state))),
|
||||||
Some("!seek") => spawn(seek(msg.0, state.clone())),
|
Some("!seek") => spawn(seek(msg.0, Arc::clone(&state))),
|
||||||
Some("!stop") => spawn(stop(msg.0, state.clone())),
|
Some("!stop") => spawn(stop(msg.0, Arc::clone(&state))),
|
||||||
Some("!volume") => spawn(volume(msg.0, state.clone())),
|
Some("!volume") => spawn(volume(msg.0, Arc::clone(&state))),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +113,7 @@ async fn join(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("What's the channel ID you want me to join?")?
|
.content("What's the channel ID you want me to join?")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let author_id = msg.author.id;
|
let author_id = msg.author.id;
|
||||||
@@ -134,7 +137,8 @@ async fn join(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content(content)?
|
.content(&content)?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -155,6 +159,7 @@ async fn leave(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("Left the channel")?
|
.content("Left the channel")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -170,6 +175,7 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("What's the URL of the audio to play?")?
|
.content("What's the URL of the audio to play?")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let author_id = msg.author.id;
|
let author_id = msg.author.id;
|
||||||
@@ -202,7 +208,8 @@ async fn play(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content(content)?
|
.content(&content)?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
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
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("Didn't find any results")?
|
.content("Didn't find any results")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,11 +249,11 @@ async fn pause(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
PlayMode::Play => {
|
PlayMode::Play => {
|
||||||
let _success = handle.pause();
|
let _success = handle.pause();
|
||||||
false
|
false
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let _success = handle.play();
|
let _success = handle.play();
|
||||||
true
|
true
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let action = if paused { "Unpaused" } else { "Paused" };
|
let action = if paused { "Unpaused" } else { "Paused" };
|
||||||
@@ -258,7 +266,8 @@ async fn pause(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content(content)?
|
.content(&content)?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -274,6 +283,7 @@ async fn seek(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("Where in the track do you want to seek to (in seconds)?")?
|
.content("Where in the track do you want to seek to (in seconds)?")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let author_id = msg.author.id;
|
let author_id = msg.author.id;
|
||||||
@@ -302,7 +312,8 @@ async fn seek(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content(content)?
|
.content(&content)?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -326,6 +337,7 @@ async fn stop(msg: Message, state: State) -> Result<(), Box<dyn Error + Send + S
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("Stopped the track")?
|
.content("Stopped the track")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -341,6 +353,7 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("What's the volume you want to set (0.0-10.0, 1.0 being the default)?")?
|
.content("What's the volume you want to set (0.0-10.0, 1.0 being the default)?")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let author_id = msg.author.id;
|
let author_id = msg.author.id;
|
||||||
@@ -358,6 +371,7 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content("Invalid volume!")?
|
.content("Invalid volume!")?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -375,7 +389,8 @@ async fn volume(msg: Message, state: State) -> Result<(), Box<dyn Error + Send +
|
|||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.create_message(msg.channel_id)
|
.create_message(msg.channel_id)
|
||||||
.content(content)?
|
.content(&content)?
|
||||||
|
.exec()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ impl Songbird {
|
|||||||
/// [`process`].
|
/// [`process`].
|
||||||
///
|
///
|
||||||
/// [`process`]: Songbird::process
|
/// [`process`]: Songbird::process
|
||||||
pub fn twilight<U>(cluster: Cluster, shard_count: u64, user_id: U) -> Arc<Self>
|
pub fn twilight<U>(cluster: Cluster, user_id: U) -> Self
|
||||||
where
|
where
|
||||||
U: Into<UserId>,
|
U: Into<UserId>,
|
||||||
{
|
{
|
||||||
Self::twilight_from_config(cluster, shard_count, user_id, Default::default())
|
Self::twilight_from_config(cluster, user_id, Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "twilight")]
|
#[cfg(feature = "twilight")]
|
||||||
@@ -102,25 +102,24 @@ impl Songbird {
|
|||||||
/// [`process`].
|
/// [`process`].
|
||||||
///
|
///
|
||||||
/// [`process`]: Songbird::process
|
/// [`process`]: Songbird::process
|
||||||
pub fn twilight_from_config<U>(
|
pub fn twilight_from_config<U>(cluster: Cluster, user_id: U, config: Config) -> Self
|
||||||
cluster: Cluster,
|
|
||||||
shard_count: u64,
|
|
||||||
user_id: U,
|
|
||||||
config: Config,
|
|
||||||
) -> Arc<Self>
|
|
||||||
where
|
where
|
||||||
U: Into<UserId>,
|
U: Into<UserId>,
|
||||||
{
|
{
|
||||||
Arc::new(Self {
|
Self {
|
||||||
client_data: PRwLock::new(ClientData {
|
client_data: PRwLock::new(ClientData {
|
||||||
shard_count,
|
shard_count: cluster
|
||||||
|
.config()
|
||||||
|
.shard_scheme()
|
||||||
|
.total()
|
||||||
|
.unwrap_or_else(|| cluster.shards().len() as u64),
|
||||||
initialised: true,
|
initialised: true,
|
||||||
user_id: user_id.into(),
|
user_id: user_id.into(),
|
||||||
}),
|
}),
|
||||||
calls: Default::default(),
|
calls: Default::default(),
|
||||||
sharder: Sharder::Twilight(cluster),
|
sharder: Sharder::Twilight(cluster),
|
||||||
config: Some(config).into(),
|
config: Some(config).into(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the bot's user, and the number of shards in use.
|
/// Set the bot's user, and the number of shards in use.
|
||||||
|
|||||||
Reference in New Issue
Block a user