Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl RegistrableCommand for AddReminderCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

let _ = defer_response(&ctx, &command).await;
let _ = defer_response(&ctx, &command, &config).await;

let mut time: Option<String> = None;
let mut content: Option<String> = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl RegistrableCommand for AddStaffCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if !thread_exists_by_channel(command.channel_id, pool).await {
return Err(ModmailError::Thread(ThreadError::NotAThreadChannel));
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/alert/slash_command/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl RegistrableCommand for AlertCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let user_id = get_thread_user_id_from_command(&ctx, &command, &config, pool).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl RegistrableCommand for BaninfoCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut query: Option<String> = None;
for option in &command.data.options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl RegistrableCommand for CategoryCommand {
.db_pool
.as_ref()
.ok_or_else(database_connection_failed)?;
defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let subcommand = match command.data.options.first() {
Some(s) => s,
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/close/slash_command/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl RegistrableCommand for CloseCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut time_before_close: Option<String> = None;
let mut silent: bool = false;
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/edit/slash_command/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl RegistrableCommand for EditCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut msg_id: i64 = 0;
let mut new_content: String = String::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RegistrableCommand for ForceCloseCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if !is_a_ticket_channel(command.channel_id, db_pool).await {
match command.channel_id.to_channel(&ctx.http).await {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/help/slash_command/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl RegistrableCommand for HelpCommand {
let config = config.clone();

Box::pin(async move {
defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut command_name: Option<String> = None;

Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/id/slash_command/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl RegistrableCommand for IdCommand {
}
};

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if !is_a_ticket_channel(command.channel_id, pool).await {
return Err(ModmailError::Thread(ThreadError::NotAThreadChannel));
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/logs/slash_command/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl RegistrableCommand for LogsCommand {
None => return Err(ModmailError::Database(DatabaseError::ConnectionFailed)),
};

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut user_id: Option<UserId> = None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl RegistrableCommand for MoveCommand {
}
};

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if get_user_id_from_channel_id(&command.channel_id.to_string(), pool)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl RegistrableCommand for NewThreadCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let user_id = match command
.data
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/ping/slash_command/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl RegistrableCommand for PingCommand {
let config = config.clone();

Box::pin(async move {
defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let response = MessageBuilder::system_message(&ctx, &config)
.content("...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RegistrableCommand for RecoverCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut params = HashMap::new();
params.insert("user".to_string(), command.user.name.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RegistrableCommand for ReleaseCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if is_a_ticket_channel(command.channel_id, db_pool).await {
let thread = match get_thread_by_channel_id(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl RegistrableCommand for ReminderSubscriptionCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

let _ = defer_response(&ctx, &command).await;
let _ = defer_response(&ctx, &command, &config).await;

let mut action: Option<String> = None;
let mut role_id: Option<RoleId> = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl RegistrableCommand for RemoveReminderCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

let _ = defer_response(&ctx, &command).await;
let _ = defer_response(&ctx, &command, &config).await;

let mut reminder_id: Option<i64> = None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl RegistrableCommand for RemoveStaffCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if !thread_exists_by_channel(command.channel_id, pool).await {
return Err(ModmailError::Thread(ThreadError::NotAThreadChannel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl RegistrableCommand for RenameCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if !is_a_ticket_channel(command.channel_id, db_pool).await {
return Err(ModmailError::Thread(ThreadError::NotAThreadChannel));
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/reply/slash_command/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl RegistrableCommand for ReplyCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mut content: Option<String> = None;
let mut snippet_key: Option<String> = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl RegistrableCommand for SnippetCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let subcommand = &command.data.options[0];
let subcommand_name = &subcommand.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl RegistrableCommand for StatusCommand {
let config = config.clone();

Box::pin(async move {
defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let mode = command.data.options.iter().find_map(|opt| {
if opt.name == "mode"
Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/commands/take/slash_command/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RegistrableCommand for TakeCommand {
.as_ref()
.ok_or_else(database_connection_failed)?;

defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

if is_a_ticket_channel(command.channel_id, db_pool).await {
let thread = match get_thread_by_channel_id(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RegistrableCommand for VersionCommand {
let config = config.clone();

Box::pin(async move {
defer_response(&ctx, &command).await?;
defer_response(&ctx, &command, &config).await?;

let content = build_version_content(&config).await;

Expand Down
2 changes: 1 addition & 1 deletion crates/rustmail/src/handlers/guild_interaction_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl EventHandler for InteractionHandler {
)
.await
{
defer_response(&ctx, &command).await.ok();
defer_response(&ctx, &command, &self.config).await.ok();

let _ = MessageBuilder::system_message(&ctx, &self.config)
.translated_content(
Expand Down
16 changes: 15 additions & 1 deletion crates/rustmail/src/utils/command/defer_response.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
use crate::prelude::config::*;
use crate::prelude::errors::*;
use serenity::all::{
CommandInteraction, Context, CreateInteractionResponse, CreateInteractionResponseMessage,
};

pub async fn defer_response(ctx: &Context, command: &CommandInteraction) -> ModmailResult<()> {
/// Defers a slash command. Outside the staff guild (community guild in dual mode) the response is
/// ephemeral, so only the invoking staff member sees the bot's answer (and any error).
pub async fn defer_response(
ctx: &Context,
command: &CommandInteraction,
config: &Config,
) -> ModmailResult<()> {
let outside_staff_guild = command
.guild_id
.is_some_and(|id| id.get() != config.bot.get_staff_guild_id());
if outside_staff_guild {
return defer_response_ephemeral(ctx, command).await;
}

command
.create_response(
&ctx.http,
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Commands (text and slash) are reserved to staff:
- **Dual-server mode**: commands only work in the staff server. Slash commands are not registered in the community
server, and text commands sent there are ignored. The one exception is the *New Thread* user context menu
(right-click a member → Apps), which is available in the community server too, but only for members of the staff
server.
server. Its reply there is ephemeral ("Only you can see this"), so community members see nothing of it.
- **Single-server mode**: staff are the members who can see the inbox category (`inbox_category_id`), which is also
who can see the tickets. Other members are ignored by text commands and get a "permission denied" reply to slash
commands. To also hide slash commands from them, restrict the bot's commands in *Server Settings → Integrations*.
Expand Down