diff --git a/src/commands/misc.rs b/src/commands/misc.rs index 4c3bf8f..fc8089f 100644 --- a/src/commands/misc.rs +++ b/src/commands/misc.rs @@ -1,10 +1,21 @@ +use std::time::Duration; + use anyhow::Result; use chrono::Utc; use mongodb::bson::doc; -use poise::{serenity_prelude::CreateEmbed, CreateReply}; +use poise::{ + serenity_prelude::{ + futures::StreamExt, ComponentInteractionCollector, CreateActionRow, CreateButton, + CreateEmbed, CreateInteractionResponse, CreateInteractionResponseMessage, + }, + CreateReply, +}; use super::CommandContext; -use crate::{models::DBMate, utils::misc::envvar}; +use crate::{ + models::{DBCollective, DBMate, DBMessage, DBUserSettings}, + utils::misc::envvar, +}; /// Get the statistics of the bot #[poise::command(slash_command, ephemeral)] @@ -75,3 +86,86 @@ pub async fn explain(ctx: CommandContext<'_>) -> Result<()> { ctx.send(CreateReply::default().embed(embed)).await?; Ok(()) } + +/// Resets your entire collective. THIS DELETES EVERYTHING. THIS CANNOT BE UNDONE. YOU HAVE BEEN WARNED. +#[poise::command(slash_command, ephemeral)] +pub async fn reset(ctx: CommandContext<'_>) -> Result<()> { + let reply = CreateReply::default() + .content( + "Are you sure you want to do this? Are you ***sure*** you want to ***delete \ + everything***? If not, please do not press yes and ignore this command.", + ) + .components(vec![CreateActionRow::Buttons(vec![CreateButton::new( + format!("{}reset", ctx.id()), + ) + .label("Yes")])]); + + ctx.send(reply).await?; + + let ctx_id = ctx.id(); + let mut collector = ComponentInteractionCollector::new(&ctx.serenity_context().shard) + .timeout(Duration::from_secs(60)) + .filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string())) + .stream(); + + while let Some(press) = collector.next().await { + if press.data.custom_id == format!("{}reset", ctx.id()) { + let database = &ctx.data().database; + let mates_collection = database.collection::("mates"); + let collectives_collection = database.collection::("collectives"); + let settings_collection = database.collection::("settings"); + let messages_collection = database.collection::("messages"); + + mates_collection + .delete_many( + doc! { + "user_id": ctx.author().id.get() as i64 + }, + None, + ) + .await?; + + collectives_collection + .delete_many( + doc! { + "user_id": ctx.author().id.get() as i64 + }, + None, + ) + .await?; + + settings_collection + .delete_many( + doc! { + "user_id": ctx.author().id.get() as i64 + }, + None, + ) + .await?; + + messages_collection + .delete_many( + doc! { + "user_id": ctx.author().id.get() as i64 + }, + None, + ) + .await?; + + press + .create_response( + &ctx.http(), + CreateInteractionResponse::UpdateMessage( + CreateInteractionResponseMessage::default() + .content("Your collective has been completely deleted.") + .components(vec![]), + ), + ) + .await?; + + break; + } + } + + Ok(()) +} diff --git a/src/events/on_message.rs b/src/events/on_message.rs index 4cf1e1f..769ec77 100644 --- a/src/events/on_message.rs +++ b/src/events/on_message.rs @@ -13,8 +13,7 @@ use crate::{ }; pub async fn run(ctx: &SerenityContext, data: &Data, message: &Message) -> Result<()> { - // FIXME: make this configurable later but immediately drop voice messages because someone asked for it - // and, as mr krabs would say: "we shall never deny a guest even the most ridiculous request" + // FIXME: just drop voice messages until we can be bothered to actually implement proxying them if message .flags .context("how the FUCK does this message not have flags")? diff --git a/src/main.rs b/src/main.rs index 295b81d..bfffd01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,7 @@ async fn main() { commands::misc::ping(), commands::misc::support(), commands::misc::stats(), + commands::misc::reset(), commands::mate::create(), commands::delete::delete(), commands::mate::switch(), @@ -76,9 +77,7 @@ async fn main() { event_handler: |ctx, event, _framework, data| { Box::pin(async move { match event { - FullEvent::Ready { - data_about_bot: _, - } => { + FullEvent::Ready { data_about_bot: _ } => { tracing::info!("Bot is ready!") } FullEvent::Message { new_message } => {