use async_trait::async_trait; use crate::extras::Extras; use crate::framework::commands::arguments::{Arg, Argument, NeedyString, ParseArguments}; use crate::framework::commands::context::CommandContext; use crate::framework::commands::{Command, CommandError}; use crate::framework::runtime::Runtime; use crate::groups::about::components::{ HelpDonateLinkButton, HelpGoBackButton, HelpSupportLinkButton, HelpWebsiteLinkButton, }; use crate::groups::about::embeds::{ get_all_command_help_embed, get_command_help_embed, get_command_not_found_embed, }; use crate::groups::calls::components::CodeOfConductButton; use crate::state::State; #[derive(Debug)] pub struct HelpCommand; #[async_trait] impl Command for HelpCommand { fn name(&self) -> &'static str { "help" } fn arguments(&self) -> &'static [Argument] { &[Argument { name: "command", is_optional: true, is_greedy: false, }] } fn description(&self) -> &'static str { "Lists all commands and shows information about them individually." } async fn execute( &self, ctx: CommandContext<'_, State, Extras>, args: &str, ) -> Result<(), CommandError> { let command_name = Arg::>::parse(args, &ctx).await.unwrap(); if let Some(command_name) = command_name.0 { if let Some(command) = ctx.rt.get_command(&command_name) { ctx.send() .embed(get_command_help_embed(&command, &ctx)) .component(HelpGoBackButton, 1) .component(HelpSupportLinkButton, 1) .await .inspect_err(|e| log::error!("Failed to send message! {e}"))?; } else { ctx.send() .embed(get_command_not_found_embed(&ctx.rt, command_name.0)) .component(HelpGoBackButton, 1) .component(HelpSupportLinkButton, 1) .await?; } } else { ctx.send() .embed(get_all_command_help_embed(ctx.prefix, &ctx.rt, &ctx.extras)) .component(HelpWebsiteLinkButton, 1) .component(HelpSupportLinkButton, 1) .component(HelpDonateLinkButton, 1) .component(CodeOfConductButton, 1) .await?; } Ok(()) } } #[derive(Debug)] pub struct CodeOfConductCommand; #[async_trait] impl Command for CodeOfConductCommand { fn name(&self) -> &'static str { "codeofconduct" } fn aliases(&self) -> &'static [&'static str] { &["co"] } fn description(&self) -> &'static str { "Shows a link to Payphone's Code of Conduct." } fn show_in_help(&self, _rt: &Runtime, _extras: &Extras) -> bool { false } fn only_runs_if_startswith(&self) -> bool { false } async fn execute( &self, ctx: CommandContext<'_, State, Extras>, _args: &str, ) -> Result<(), CommandError> { ctx.send() .content("") .reply_to(ctx.event.id) .await?; Ok(()) } } #[derive(Debug)] pub struct DonateCommand; #[async_trait] impl Command for DonateCommand { fn name(&self) -> &'static str { "donate" } fn aliases(&self) -> &'static [&'static str] { &["d"] } fn description(&self) -> &'static str { "Shows a link to Payphone's Ko-Fi page." } fn show_in_help(&self, _rt: &Runtime, _extras: &Extras) -> bool { false } fn only_runs_if_startswith(&self) -> bool { false } async fn execute( &self, ctx: CommandContext<'_, State, Extras>, _args: &str, ) -> Result<(), CommandError> { ctx.send() .reply_to(ctx.event.id) .content("") .await?; Ok(()) } }