diff --git a/CHANGELOG.md b/CHANGELOG.md index cb91675..9e79d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Procedure when bumping the version number: ## Unreleased ### Added +- `bot::botrulez::FullHelp` now implements `bot::command::Command` - `bot::botrulez::Ping` now implements `bot::command::Command` - `bot::botrulez::ShortHelp` now implements `bot::command::Command` diff --git a/src/bot/botrulez/full_help.rs b/src/bot/botrulez/full_help.rs index d14ae21..f1508ab 100644 --- a/src/bot/botrulez/full_help.rs +++ b/src/bot/botrulez/full_help.rs @@ -2,18 +2,18 @@ use async_trait::async_trait; use clap::Parser; use crate::api::Message; -use crate::bot::command::{ClapCommand, Context}; +use crate::bot::command::{ClapCommand, Command, Context}; use crate::conn; -/// Show full bot help. -#[derive(Parser)] -pub struct Args {} - pub struct FullHelp { pub before: String, pub after: String, } +pub trait HasDescriptions { + fn descriptions(&self, ctx: &Context) -> Vec; +} + impl FullHelp { pub fn new(before: S1, after: S2) -> Self { Self { @@ -21,27 +21,8 @@ impl FullHelp { after: after.to_string(), } } -} -pub trait HasDescriptions { - fn descriptions(&self, ctx: &Context) -> Vec; -} - -#[async_trait] -impl ClapCommand for FullHelp -where - B: HasDescriptions + Send, - E: From, -{ - type Args = Args; - - async fn execute( - &self, - _args: Self::Args, - msg: &Message, - ctx: &Context, - bot: &mut B, - ) -> Result<(), E> { + fn formulate_reply(&self, ctx: &Context, bot: &B) -> String { let mut result = String::new(); if !self.before.is_empty() { @@ -59,7 +40,46 @@ where result.push('\n'); } - ctx.reply(msg.id, result).await?; + result + } +} + +#[async_trait] +impl Command for FullHelp +where + B: HasDescriptions + Send, + E: From, +{ + async fn execute(&self, arg: &str, msg: &Message, ctx: &Context, bot: &mut B) -> Result<(), E> { + if arg.trim().is_empty() { + let reply = self.formulate_reply(ctx, bot); + ctx.reply(msg.id, reply).await?; + } + Ok(()) + } +} + +/// Show full bot help. +#[derive(Parser)] +pub struct Args {} + +#[async_trait] +impl ClapCommand for FullHelp +where + B: HasDescriptions + Send, + E: From, +{ + type Args = Args; + + async fn execute( + &self, + _args: Self::Args, + msg: &Message, + ctx: &Context, + bot: &mut B, + ) -> Result<(), E> { + let reply = self.formulate_reply(ctx, bot); + ctx.reply(msg.id, reply).await?; Ok(()) } }