Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions book/src/chapter_1_crates/section_6_standby.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@ Wait for a message in channel 123 by user 456 with the content "test":
# #[allow(unused_variables)]
# #[tokio::main]
# async fn main() -> Result<(), Box<dyn std::error::Error>> {
use twilight_model::{
gateway::payload::incoming::MessageCreate,
id::Id,
};
use twilight_model::id::Id;
use twilight_standby::Standby;

let standby = Standby::new();

// Later on in the application...
let message = standby
.wait_for_message(
Id::new(123),
|event: &MessageCreate| {
event.author.id == Id::new(456) && event.content == "test"
},
)
.wait_for_message(Id::new(123), |event| {
event.author.id == Id::new(456) && event.content == "test"
})
.await?;
# Ok(())
# }
Expand Down
24 changes: 6 additions & 18 deletions examples/lavalink-basic-bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ async fn equalize(

let band_message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;
let band = band_message.content.parse::<i64>()?;

Expand All @@ -202,9 +200,7 @@ async fn equalize(

let gain_message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;
let gain = gain_message.content.parse::<f64>()?;

Expand Down Expand Up @@ -237,9 +233,7 @@ async fn join(

let message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;
let join_channel = message.content.parse()?;

Expand Down Expand Up @@ -313,9 +307,7 @@ async fn play(

let message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;

tracing::debug!(%guild, url = message.content, %user, "playing");
Expand Down Expand Up @@ -369,9 +361,7 @@ async fn seek(

let message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;
let position = message.content.parse::<i64>()?;

Expand Down Expand Up @@ -420,9 +410,7 @@ async fn volume(

let message = CONTEXT
.standby
.wait_for_message(channel, move |message: &MessageCreate| {
message.author.id == user
})
.wait_for_message(channel, move |message| message.author.id == user)
.await?;
let volume = message.content.parse::<i64>()?;

Expand Down
2 changes: 1 addition & 1 deletion twilight-standby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ version = "0.17.0"
dashmap = { default-features = false, version = ">= 5.3, < 7" }
futures-core = { default-features = false, features = ["std"], version = "0.3" }
tokio = { default-features = false, features = ["sync"], version = "1.0" }
tracing = { default-features = false, features = ["std", "attributes"], version = "0.1" }
twilight-model = { default-features = false, path = "../twilight-model", version = "0.17.0" }

[dev-dependencies]
anyhow = { default-features = false, features = ["std"], version = "1" }
static_assertions = { default-features = false, version = "1" }
tokio = { default-features = false, features = ["macros", "rt-multi-thread"], version = "1.0" }
tokio-stream = { default-features = false, version = "0.1" }
tracing = { default-features = false, features = ["std"], version = "0.1" }
twilight-gateway = { default-features = false, features = ["rustls-native-roots"], path = "../twilight-gateway" }
24 changes: 10 additions & 14 deletions twilight-standby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ detailed on the [`Standby`] type.
Wait for a message in channel 123 by user 456 with the content "test":

```rust,no_run
use twilight_model::{
gateway::payload::incoming::MessageCreate,
id::Id,
};
use twilight_model::id::Id;
use twilight_standby::Standby;

#[tokio::main]
Expand All @@ -59,9 +56,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let channel_id = Id::new(123);

let message = standby.wait_for_message(channel_id, |event: &MessageCreate| {
event.author.id.get() == 456 && event.content == "test"
}).await?;
let message = standby
.wait_for_message(channel_id, |event| {
event.author.id.get() == 456 && event.content == "test"
})
.await?;

Ok(())
}
Expand All @@ -75,10 +74,7 @@ including a handler to wait for reactions:
```rust,no_run
use std::{env, sync::Arc};
use twilight_gateway::{Event, EventTypeFlags, Intents, Shard, ShardId, StreamExt as _};
use twilight_model::{
channel::Message,
gateway::payload::incoming::ReactionAdd,
};
use twilight_model::channel::Message;
use twilight_standby::Standby;

#[tokio::main]
Expand Down Expand Up @@ -118,9 +114,9 @@ async fn main() -> anyhow::Result<()> {
async fn react(msg: Message, standby: Arc<Standby>) -> anyhow::Result<()> {
let author_id = msg.author.id;

let reaction = standby.wait_for_reaction(msg.id, move |event: &ReactionAdd| {
event.user_id == author_id
}).await?;
let reaction = standby
.wait_for_reaction(msg.id, move |event| event.user_id == author_id)
.await?;

println!("user reacted with {:?}", reaction.emoji);

Expand Down
Loading