Add botrulez commands
This commit is contained in:
parent
e27694ef85
commit
af7d386371
7 changed files with 396 additions and 1 deletions
71
euphoxide-bot/src/command/botrulez/ping.rs
Normal file
71
euphoxide-bot/src/command/botrulez/ping.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
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::{
|
||||
bot::Bot,
|
||||
command::{Command, Context, Propagate},
|
||||
};
|
||||
|
||||
pub struct Ping(pub String);
|
||||
|
||||
impl Ping {
|
||||
pub fn new<S: ToString>(reply: S) -> Self {
|
||||
Self(reply.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Ping {
|
||||
fn default() -> Self {
|
||||
Self::new("Pong!")
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S, E> Command<S, E> for Ping
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
async fn execute(
|
||||
&self,
|
||||
arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
) -> Result<Propagate, E> {
|
||||
if arg.trim().is_empty() {
|
||||
ctx.reply_only(msg.id, &self.0).await?;
|
||||
Ok(Propagate::No)
|
||||
} else {
|
||||
Ok(Propagate::Yes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Trigger a short reply.
|
||||
#[cfg(feature = "clap")]
|
||||
#[derive(Parser)]
|
||||
pub struct PingArgs {}
|
||||
|
||||
#[cfg(feature = "clap")]
|
||||
#[async_trait]
|
||||
impl<S, E> ClapCommand<S, E> for Ping
|
||||
where
|
||||
E: From<euphoxide::Error>,
|
||||
{
|
||||
type Args = PingArgs;
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
_args: Self::Args,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
_bot: &Bot<S, E>,
|
||||
) -> 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