Add magic fix command

This commit is contained in:
Tom 2022-03-28 16:07:33 +02:00
parent 3bf88e3c10
commit e04f37651e

View file

@ -68,6 +68,49 @@ pub async fn boop(ctx: Context<'_>) -> Result<(), Error> {
Ok(())
}
#[poise::command(track_edits, slash_command)]
pub async fn fix(ctx: Context<'_>) -> Result<(), Error> {
let uuid_fix = ctx.id();
ctx.send(|m| {
m.content("You want to fix things? Just press the magic fix button.").components(|c| {
c.create_action_row(|ar| {
ar.create_button(|b| {
b.style(serenity::ButtonStyle::Success)
.label("Fix")
.custom_id(uuid_fix)
})
})
})
})
.await?;
let mut fix_count: i32 = 0;
while let Some(mci) = serenity::CollectComponentInteraction::new(ctx.discord())
.channel_id(ctx.channel_id())
// .timeout(std::time::Duration::from_secs(1200))
.filter(move |mci| mci.data.custom_id == uuid_fix.to_string())
.await
{
fix_count += 1;
let mut msg = mci.message.clone();
msg.edit(ctx.discord(), |m| {
m.content(format!("Fixing failed try again. Attempt {}", fix_count))
})
.await?;
mci.create_interaction_response(ctx.discord(), |ir| {
ir.kind(serenity::InteractionResponseType::DeferredUpdateMessage)
})
.await?;
}
Ok(())
}
pub fn get_links(
) -> poise::Command<super::Data, Box<(dyn std::error::Error + Sync + std::marker::Send + 'static)>>
{