From 98916b0d2be16f93267ba1d609730984ae1edca9 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 21 Feb 2025 03:07:39 +0100 Subject: [PATCH] Add CommandExt trait --- euphoxide-bot/examples/examplebot.rs | 29 ++++++++++++++-------------- euphoxide-bot/src/command.rs | 28 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/euphoxide-bot/examples/examplebot.rs b/euphoxide-bot/examples/examplebot.rs index 5de40f0..e71829d 100644 --- a/euphoxide-bot/examples/examplebot.rs +++ b/euphoxide-bot/examples/examplebot.rs @@ -5,10 +5,8 @@ use euphoxide::api::Message; use euphoxide_bot::{ bot::Bot, command::{ - bang::{General, Specific}, - basic::Described, botrulez::{FullHelp, Ping, ShortHelp}, - Command, Commands, Context, Info, Propagate, + Command, CommandExt, Commands, Context, Info, Propagate, }, }; use tokio::sync::mpsc; @@ -46,17 +44,20 @@ async fn run() -> anyhow::Result<()> { let (event_tx, mut event_rx) = mpsc::channel(10); let commands = Commands::new() - .then(Described::hidden(General::new("ping", Ping::default()))) - .then(Described::hidden(Specific::new("ping", Ping::default()))) - .then(Described::hidden(General::new( - "help", - ShortHelp::new("/me demonstrates how to use euphoxide"), - ))) - .then(Described::hidden(Specific::new( - "help", - FullHelp::new().with_after("Created using euphoxide."), - ))) - .then(General::new("pyramid", Pyramid)); + .then(Ping::default().general("ping").hidden()) + .then(Ping::default().specific("ping").hidden()) + .then( + ShortHelp::new("/me demonstrates how to use euphoxide") + .general("help") + .hidden(), + ) + .then( + FullHelp::new() + .with_after("Created using euphoxide.") + .specific("help") + .hidden(), + ) + .then(Pyramid.general("pyramid")); let bot: Bot = Bot::new_simple(commands, event_tx); diff --git a/euphoxide-bot/src/command.rs b/euphoxide-bot/src/command.rs index ce654f5..1826c73 100644 --- a/euphoxide-bot/src/command.rs +++ b/euphoxide-bot/src/command.rs @@ -123,6 +123,34 @@ pub trait Command { ) -> Result; } +pub trait CommandExt: Sized { + fn described(self) -> basic::Described { + basic::Described::new(self) + } + + fn hidden(self) -> basic::Described { + basic::Described::hidden(self) + } + + fn prefixed(self, prefix: impl ToString) -> basic::Prefixed { + basic::Prefixed::new(prefix, self) + } + + fn general(self, name: impl ToString) -> bang::General { + bang::General::new(name, self) + } + + fn global(self, name: impl ToString) -> bang::Global { + bang::Global::new(name, self) + } + + fn specific(self, name: impl ToString) -> bang::Specific { + bang::Specific::new(name, self) + } +} + +impl CommandExt for C {} + pub struct Commands { commands: Vec + Sync + Send>>, }