pikadick/
commands.rs

1pub mod cache_stats;
2pub mod chat;
3pub mod cmd;
4pub mod deviantart;
5pub mod fml;
6pub mod insta_dl;
7pub mod invite;
8pub mod iqdb;
9pub mod latency;
10pub mod leave;
11pub mod nekos;
12pub mod ping;
13pub mod quizizz;
14pub mod r6stats;
15pub mod r6tracker;
16pub mod reddit;
17pub mod reddit_embed;
18pub mod rule34;
19pub mod sauce_nao;
20pub mod shift;
21pub mod stop;
22pub mod system;
23pub mod tic_tac_toe;
24pub mod tiktok_embed;
25pub mod urban;
26pub mod uwuify;
27pub mod vaporwave;
28pub mod xkcd;
29pub mod yodaspeak;
30pub mod zalgo;
31
32pub use crate::commands::{
33    cache_stats::CACHE_STATS_COMMAND,
34    cmd::CMD_COMMAND,
35    deviantart::DEVIANTART_COMMAND,
36    fml::FML_COMMAND,
37    insta_dl::INSTA_DL_COMMAND,
38    invite::INVITE_COMMAND,
39    iqdb::IQDB_COMMAND,
40    latency::LATENCY_COMMAND,
41    leave::LEAVE_COMMAND,
42    quizizz::QUIZIZZ_COMMAND,
43    reddit::REDDIT_COMMAND,
44    reddit_embed::REDDIT_EMBED_COMMAND,
45    sauce_nao::SAUCE_NAO_COMMAND,
46    shift::SHIFT_COMMAND,
47    stop::STOP_COMMAND,
48    system::SYSTEM_COMMAND,
49    tic_tac_toe::TIC_TAC_TOE_COMMAND,
50    urban::URBAN_COMMAND,
51    uwuify::UWUIFY_COMMAND,
52    vaporwave::VAPORWAVE_COMMAND,
53    xkcd::XKCD_COMMAND,
54    zalgo::ZALGO_COMMAND,
55};
56use anyhow::Context;
57use pikadick_slash_framework::FromOptions;
58use serenity::builder::{
59    CreateEmbed,
60    CreateInteractionResponse,
61    CreateInteractionResponseMessage,
62};
63
64/// Help Options
65#[derive(Debug, FromOptions)]
66pub struct HelpCommandOptions {
67    /// The command
68    pub command: Option<String>,
69}
70
71/// Create a slash help command
72pub fn create_slash_help_command() -> anyhow::Result<pikadick_slash_framework::HelpCommand> {
73    pikadick_slash_framework::HelpCommandBuilder::new()
74        .description("Get information about commands and their use")
75        .argument(
76            pikadick_slash_framework::ArgumentParamBuilder::new()
77                .name("command")
78                .description("The command you need help for")
79                .kind(pikadick_slash_framework::ArgumentKind::String)
80                .build()?,
81        )
82        .on_process(
83            |ctx, interaction, map, args: HelpCommandOptions| async move {
84                let mut embed_builder = CreateEmbed::new().color(0xF4D665_u32);
85                if let Some(command) = args.command {
86                    let maybe_command = map.get(command.as_str());
87
88                    match maybe_command {
89                        Some(command) => {
90                            embed_builder = embed_builder
91                                .title(command.name())
92                                .description(command.description());
93
94                            if !command.arguments().is_empty() {
95                                let mut arguments = String::with_capacity(256);
96                                for argument in command.arguments().iter() {
97                                    arguments.push_str("**");
98                                    arguments.push_str(argument.name());
99                                    arguments.push_str("**");
100
101                                    arguments.push_str(": ");
102                                    arguments.push_str(argument.description());
103                                }
104                                embed_builder = embed_builder.field("Arguments", &arguments, false);
105                            }
106                        }
107                        None => {
108                            embed_builder = embed_builder
109                                .title("Unknown Command")
110                                .description(format!("Command \"{command}\" was not found."));
111                        }
112                    }
113                } else {
114                    embed_builder = embed_builder.title("Help");
115
116                    let mut description = String::with_capacity(256);
117                    for name in map.keys() {
118                        description.push('`');
119                        description.push_str(name);
120                        description.push('`');
121                        description.push('\n');
122                    }
123
124                    embed_builder = embed_builder.description(description);
125                }
126
127                let message_builder = CreateInteractionResponseMessage::new().embed(embed_builder);
128                let response_builder = CreateInteractionResponse::Message(message_builder);
129                interaction
130                    .create_response(&ctx.http, response_builder)
131                    .await?;
132
133                Ok(())
134            },
135        )
136        .build()
137        .context("failed to build help command")
138}