The world's most clever kitty cat
1use std::sync::{Arc, atomic::Ordering};
2
3use twilight_interactions::command::{CommandModel, CreateCommand};
4use twilight_model::application::interaction::{Interaction, application_command::CommandData};
5
6use crate::{
7 BotContext, cmd::DEFER_INTER_RESP_EPHEMERAL, prelude::*, require_owner, status::update_status,
8};
9
10#[derive(CommandModel, CreateCommand)]
11#[command(
12 name = "forget",
13 desc = "Erase a word from all edges. THIS ACTION IS IRREVERSIBLE!"
14)]
15pub struct ForgetCommand {
16 /// The token to forget
17 token: String,
18}
19
20impl ForgetCommand {
21 pub async fn handle(inter: Interaction, data: CommandData, ctx: Arc<BotContext>) -> Result {
22 let client = ctx.http.interaction(ctx.app_id);
23
24 require_owner!(inter, ctx, client);
25
26 let Self { token } =
27 Self::from_interaction(data.into()).context("Failed to parse command data")?;
28
29 client
30 .create_response(inter.id, &inter.token, &DEFER_INTER_RESP_EPHEMERAL)
31 .await
32 .context("Failed to defer")?;
33
34 {
35 let mut brain = ctx.brain_handle.write().await;
36 brain.forget(token.as_str());
37 ctx.pending_save.store(true, Ordering::Relaxed);
38 update_status(&brain, &ctx.shard_sender).context("Failed to update status")?;
39 }
40
41 client
42 .update_response(&inter.token)
43 .content(Some("Token forgotten"))
44 .await
45 .context("Failed to send brain")?;
46
47 Ok(())
48 }
49}