fix: button despawn

This commit is contained in:
Stachelbeere1248 2025-02-19 00:16:38 +01:00
parent e54833f546
commit 55cdbaf196
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o

View file

@ -10,7 +10,6 @@ use poise::serenity_prelude::CreateButton;
use poise::serenity_prelude::CreateEmbed; use poise::serenity_prelude::CreateEmbed;
use poise::serenity_prelude::CreateInteractionResponse; use poise::serenity_prelude::CreateInteractionResponse;
use poise::serenity_prelude::CreateInteractionResponseMessage; use poise::serenity_prelude::CreateInteractionResponseMessage;
use poise::serenity_prelude::EditMessage;
use poise::CreateReply; use poise::CreateReply;
use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::time::{Duration, SystemTime, UNIX_EPOCH};
@ -21,11 +20,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
ephemeral = "true" ephemeral = "true"
)] )]
// Check for bots available to you. // Check for bots available to you.
pub(crate) async fn helpstart( pub(crate) async fn helpstart(ctx: Context<'_>, user: Option<String>) -> Result<(), Error> {
ctx: Context<'_>, ctx.defer_ephemeral().await?;
user: Option<String>,
) -> Result<(), Error> {
ctx.defer().await?;
let links = super::accountv2::get_link(ctx.author(), &ctx.data().sqlite_pool).await?; let links = super::accountv2::get_link(ctx.author(), &ctx.data().sqlite_pool).await?;
let mc_accounts = match user { let mc_accounts = match user {
None => { None => {
@ -90,35 +86,51 @@ pub(crate) async fn helpstart(
{}", {}",
bots.len() bots.len()
)) ))
.components(components); .components(components)
ctx.send(reply).await?; .ephemeral(true);
let m = ctx.send(reply).await?;
while let Some(mut i) = ComponentInteractionCollector::new(ctx) while let Some(i) = ComponentInteractionCollector::new(ctx)
.author_id(ctx.author().id) .author_id(ctx.author().id)
.channel_id(ctx.channel_id()) .channel_id(ctx.channel_id())
.timeout(std::time::Duration::from_secs(60)) .timeout(std::time::Duration::from_secs(60))
.filter(move |i| i.data.custom_id == bid.to_string()) .filter(move |i| i.data.custom_id == bid.to_string())
.await .await
{ {
let embed = CreateEmbed::new().fields(bots.iter().filter_map(|b| { let embed = CreateEmbed::new()
if b.note().trim().is_empty() || usable.iter().any(|&u| std::ptr::eq(u, b)) { .fields(bots.iter().filter_map(|b| {
None if b.note().trim().is_empty() || usable.iter().any(|&u| std::ptr::eq(u, b)) {
} else { None
Some((b.username(), b.note(), true)) } else {
} Some((b.username(), b.note(), true))
})).title("Notes").description( }
"Below is the note of each bot that you cannot use. It might help you get whitelisted.", }))
); .title("Notes")
.description(
"Below is the note of each bot that you cannot use. It might help you get \
whitelisted.",
);
i.create_response( i.create_response(
ctx, ctx,
CreateInteractionResponse::Message( CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new().embed(embed), CreateInteractionResponseMessage::new()
.embed(embed)
.ephemeral(true),
), ),
) )
.await?; .await?;
i.message
.edit(ctx, EditMessage::default().components(vec![]))
.await?;
} }
m.edit(
ctx,
CreateReply::default()
.content(format!(
"Bots that are ready for use: {ready}\nBots you can use: {s}\nTotal registered \
bots: {}",
bots.len()
))
.ephemeral(true)
.components(vec![]),
)
.await?;
Ok(()) Ok(())
} }