Add botrulez commands
This commit is contained in:
parent
12448c26c9
commit
4160d69a2b
8 changed files with 389 additions and 1 deletions
62
euphoxide-bot/src/command/botrulez/short_help.rs
Normal file
62
euphoxide-bot/src/command/botrulez/short_help.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
use async_trait::async_trait;
|
||||
#[cfg(feature = "clap")]
|
||||
use clap::Parser;
|
||||
use euphoxide::api::Message;
|
||||
|
||||
#[cfg(feature = "clap")]
|
||||
use crate::command::clap::ClapCommand;
|
||||
use crate::command::{Command, Context, Propagate};
|
||||
|
||||
pub struct ShortHelp(pub String);
|
||||
|
||||
impl ShortHelp {
|
||||
pub fn new<S: ToString>(text: S) -> Self {
|
||||
Self(text.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<B, E> Command<B, E> for ShortHelp
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
async fn execute(
|
||||
&self,
|
||||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &mut B,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
Ok(Propagate::No)
|
||||
} else {
|
||||
Ok(Propagate::Yes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show short bot help.
|
||||
#[cfg(feature = "clap")]
|
||||
#[derive(Parser)]
|
||||
pub struct ShortHelpArgs {}
|
||||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<B, E> ClapCommand<B, E> for ShortHelp
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
type Args = ShortHelpArgs;
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
_args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &mut B,
|
||||
) -> Result<Propagate, E> {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
Ok(Propagate::No)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue