Skip to content

Commit

Permalink
feat: privacy command
Browse files Browse the repository at this point in the history
  • Loading branch information
GenericNerd committed May 28, 2024
1 parent c09df4d commit fd62ab9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
2 changes: 2 additions & 0 deletions migrations/20240528214317_privacy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add migration script here
INSERT INTO global_kills (feature) VALUES ('commands.privacy');
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ pub mod global;
pub mod info;
pub mod moderation;
pub mod permissions;
pub mod privacy;

pub fn get_command_list() -> Vec<Box<dyn Command>> {
let mut commands = moderation::get_moderation_commands();
commands.push(Box::new(permissions::PermissionsCommand));
commands.push(Box::new(giveaway::GiveawayCommand));
commands.push(Box::new(config::ConfigCommand));
commands.push(Box::new(info::InfoCommand));
commands.push(Box::new(privacy::PrivacyCommand));

commands
}
40 changes: 40 additions & 0 deletions src/commands/privacy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use serenity::all::{CommandInteraction, CreateCommand, CreateEmbed};

use crate::models::{
command::{Command, CommandContext, CommandContextReply},
handler::Handler,
response::{Response, ResponseResult},
};

pub struct PrivacyCommand;

#[async_trait::async_trait]
impl Command for PrivacyCommand {
fn name(&self) -> &'static str {
"privacy"
}

fn register(&self) -> CreateCommand {
CreateCommand::new("privacy").description("Get Reaper's Privacy Policy")
}

async fn router(
&self,
_handler: &Handler,
ctx: &CommandContext,
cmd: &CommandInteraction,
) -> ResponseResult {
ctx.reply(
cmd,
Response::new()
.embed(
CreateEmbed::new()
.title("Privacy Policy")
.description(
format!("You can view Reaper's Privacy Policy [here](https://github.com/GenericNerd/reaper/blob/development/PRIVACY.md).")
)
.color(0xeb966d)
).ephemeral(true)
).await
}
}
39 changes: 22 additions & 17 deletions src/events/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ impl Handler {

let command_context = CommandContext {
ctx,
has_responsed: Arc::new(AtomicBool::new(true)),
has_responsed: Arc::new(AtomicBool::new(false)),
user_permissions,
highest_role,
guild,
};

debug!("Context generated in {:?}", start.elapsed());

if command.data.name != "global"
if (command.data.name != "global")
&& !sqlx::query!(
"SELECT active FROM global_kills WHERE feature = $1",
format!("commands.{}", command.data.name)
Expand Down Expand Up @@ -232,21 +232,26 @@ impl Handler {

for existing_command in existing_commands {
if existing_command.name() == command.data.name {
if let Err(err) = command
.create_response(
&command_context.ctx,
CreateInteractionResponse::Defer(
CreateInteractionResponseMessage::default(),
),
)
.await
{
error!(
"Failed to acknowledge command, took {:?}: {err:?}",
start.elapsed(),
);
return;
};
if command.data.name != "privacy" {
if let Err(err) = command
.create_response(
&command_context.ctx,
CreateInteractionResponse::Defer(
CreateInteractionResponseMessage::default(),
),
)
.await
{
error!(
"Failed to acknowledge command, took {:?}: {err:?}",
start.elapsed(),
);
return;
};
command_context
.has_responsed
.store(true, std::sync::atomic::Ordering::Relaxed);
}

if let Err(err) = existing_command
.router(self, &command_context, &command)
Expand Down

0 comments on commit fd62ab9

Please sign in to comment.