Skip to content

Commit

Permalink
add /reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruthenic committed Feb 4, 2024
1 parent c1135b3 commit 68729b1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 7 deletions.
98 changes: 96 additions & 2 deletions src/commands/misc.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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::<DBMate>("mates");
let collectives_collection = database.collection::<DBCollective>("collectives");
let settings_collection = database.collection::<DBUserSettings>("settings");
let messages_collection = database.collection::<DBMessage>("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(())
}
3 changes: 1 addition & 2 deletions src/events/on_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 } => {
Expand Down

0 comments on commit 68729b1

Please sign in to comment.