forked from serenity-rs/poise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.rs
45 lines (37 loc) · 1.3 KB
/
collector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::{Context, Error};
use poise::{serenity_prelude as serenity, CreateReply};
/// Boop the bot!
#[poise::command(prefix_command, track_edits, slash_command)]
pub async fn boop(ctx: Context<'_>) -> Result<(), Error> {
let uuid_boop = ctx.id();
let reply = {
let components = vec![serenity::CreateActionRow::Buttons(vec![
serenity::CreateButton::new(format!("{uuid_boop}"))
.style(serenity::ButtonStyle::Primary)
.label("Boop me!"),
])];
CreateReply::default()
.content("I want some boops!")
.components(components)
};
ctx.send(reply).await?;
let mut boop_count = 0;
while let Some(mci) = serenity::ComponentInteractionCollector::new(ctx)
.author_id(ctx.author().id)
.channel_id(ctx.channel_id())
.timeout(std::time::Duration::from_secs(120))
.filter(move |mci| mci.data.custom_id == uuid_boop.to_string())
.await
{
boop_count += 1;
let mut msg = mci.message.clone();
msg.edit(
ctx,
serenity::EditMessage::new().content(format!("Boop count: {boop_count}")),
)
.await?;
mci.create_response(ctx, serenity::CreateInteractionResponse::Acknowledge)
.await?;
}
Ok(())
}