Skip to content

Commit ec6da6a

Browse files
committed
feat(commands): add complete slash command for help command
1 parent a8c2e1d commit ec6da6a

10 files changed

Lines changed: 75 additions & 3 deletions

File tree

src/commands/help/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod slash_command;
2+
pub mod text_command;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use crate::config::Config;
2+
use crate::errors::ModmailResult;
3+
use crate::i18n::get_translated_message;
4+
use crate::utils::command::defer_response::defer_response;
5+
use crate::utils::message::message_builder::MessageBuilder;
6+
use serenity::all::{CommandInteraction, Context, CreateCommand, ResolvedOption};
7+
8+
pub async fn register(config: &Config) -> CreateCommand {
9+
let cmd_desc = get_translated_message(
10+
config,
11+
"slash_command.help_command_description",
12+
None,
13+
None,
14+
None,
15+
None,
16+
)
17+
.await;
18+
19+
CreateCommand::new("help").description(cmd_desc)
20+
}
21+
22+
pub async fn run(
23+
ctx: &Context,
24+
command: &CommandInteraction,
25+
_options: &[ResolvedOption<'_>],
26+
config: &Config,
27+
) -> ModmailResult<()> {
28+
let help_message = "# Available commands:\n\n\
29+
**!add_staff <staff_id>** - Add a staff to an hidden ticket\n\
30+
**!remove_staff <staff_id>** - Remove a staff from a ticket\n\
31+
**!alert** - Alert staff in the current thread when a new user answer arrives \n\
32+
**!help** - Show this help message\n\
33+
**!reply <message>** - Reply to a ticket\n\
34+
**!annonreply <message>** - Reply anonymously to a ticket\n\
35+
**!close [reason]** - Close the current thread with an optional reason\n\
36+
**!delete [reason]** - Delete the current thread with an optional reason\n\
37+
**!hide** - Make the current thread hidden to non-staff members\n\
38+
**!new_thread <user_id>** - Create a new ticket with a specific user\n\
39+
**!alert [cancel]** - Set or cancel an alert for staff in the current thread\n\
40+
**!force_close** - Force close the current thread if it's orphaned\n\
41+
**!id** - Show the user ID associated with the current thread";
42+
43+
defer_response(&ctx, &command).await?;
44+
45+
let response = MessageBuilder::system_message(ctx, config)
46+
.content(help_message)
47+
.to_channel(command.channel_id)
48+
.build_interaction_message_followup()
49+
.await;
50+
51+
let _ = command.create_followup(&ctx.http, response).await;
52+
53+
Ok(())
54+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod help;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use serenity::all::{Context, Message};
21
use crate::config::Config;
32
use crate::errors::ModmailResult;
43
use crate::utils::message::message_builder::MessageBuilder;
4+
use serenity::all::{Context, Message};
55

66
pub async fn help(ctx: &Context, msg: &Message, config: &Config) -> ModmailResult<()> {
77
let help_message = "# Available commands:\n\n\
@@ -26,4 +26,4 @@ pub async fn help(ctx: &Context, msg: &Message, config: &Config) -> ModmailResul
2626
.await?;
2727

2828
Ok(())
29-
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod help;

src/handlers/guild_interaction_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::commands::close::slash_command::close;
44
use crate::commands::delete::slash_command::delete;
55
use crate::commands::edit::slash_command::edit;
66
use crate::commands::force_close::slash_command::force_close;
7+
use crate::commands::help::slash_command::help;
78
use crate::commands::id::slash_command::id;
89
use crate::commands::move_thread::slash_command::move_thread;
910
use crate::commands::new_thread::slash_command::new_thread;
@@ -94,6 +95,9 @@ impl EventHandler for InteractionHandler {
9495
"recover" => {
9596
recover::run(&ctx, &command, &command.data.options(), &self.config).await
9697
}
98+
"help" => {
99+
help::run(&ctx, &command, &command.data.options(), &self.config).await
100+
}
97101
_ => Err(ModmailError::Command(CommandError::UnknownSlashCommand(
98102
command.data.name.clone(),
99103
))),

src/handlers/guild_messages_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::commands::delete::text_command::delete::delete;
66
use crate::commands::edit::message_ops::edit_inbox_message;
77
use crate::commands::edit::text_command::edit::edit;
88
use crate::commands::force_close::text_command::force_close::force_close;
9+
use crate::commands::help::text_command::help::help;
910
use crate::commands::id::text_command::id::id;
1011
use crate::commands::move_thread::text_command::move_thread::move_thread;
1112
use crate::commands::new_thread::text_command::new_thread::new_thread;
@@ -34,7 +35,6 @@ use serenity::{
3435
use std::collections::HashSet;
3536
use std::sync::{LazyLock, Mutex};
3637
use std::{collections::HashMap, future::Future, pin::Pin, sync::Arc};
37-
use crate::commands::help::help;
3838

3939
static SUPPRESSED_DELETES: LazyLock<Mutex<HashSet<u64>>> =
4040
LazyLock::new(|| Mutex::new(HashSet::new()));

src/handlers/ready_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::commands::close::slash_command::close;
44
use crate::commands::delete::slash_command::delete;
55
use crate::commands::edit::slash_command::edit;
66
use crate::commands::force_close::slash_command::force_close;
7+
use crate::commands::help::slash_command::help;
78
use crate::commands::id::slash_command::id;
89
use crate::commands::move_thread::slash_command::move_thread;
910
use crate::commands::new_thread::slash_command::new_thread;
@@ -68,6 +69,7 @@ impl EventHandler for ReadyHandler {
6869
reply::register(&self.config).await,
6970
delete::register(&self.config).await,
7071
recover::register(&self.config).await,
72+
help::register(&self.config).await,
7173
],
7274
)
7375
.await;

src/i18n/language/en.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,8 @@ pub fn load_english_messages(dict: &mut ErrorDictionary) {
715715
"Retrieve messages missed during the bot's downtime (This process is automatic).",
716716
),
717717
);
718+
dict.messages.insert(
719+
"slash_command.help_command_description".to_string(),
720+
DictionaryMessage::new("Show the help message"),
721+
);
718722
}

src/i18n/language/fr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,8 @@ pub fn load_french_messages(dict: &mut ErrorDictionary) {
726726
"slash_command.recover_command_description".to_string(),
727727
DictionaryMessage::new("Récupérer les messages manqués pendant la période d'indisponibilité du bot (Ce processus est automatique)"),
728728
);
729+
dict.messages.insert(
730+
"slash_command.help_command_description".to_string(),
731+
DictionaryMessage::new("Afficher le message d'aide"),
732+
);
729733
}

0 commit comments

Comments
 (0)