Implement Command for Ping

This commit is contained in:
Joscha 2023-02-26 19:50:29 +01:00
parent 5b4bf87506
commit 8b8d281f8a
2 changed files with 27 additions and 5 deletions

View file

@ -2,13 +2,9 @@ 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;
/// Trigger a short reply.
#[derive(Parser)]
pub struct Args {}
pub struct Ping(pub String);
impl Ping {
@ -23,6 +19,29 @@ impl Default for Ping {
}
}
#[async_trait]
impl<B, E> Command<B, E> for Ping
where
E: From<conn::Error>,
{
async fn execute(
&self,
arg: &str,
msg: &Message,
ctx: &Context,
_bot: &mut B,
) -> Result<(), E> {
if arg.trim().is_empty() {
ctx.reply(msg.id, &self.0).await?;
}
Ok(())
}
}
/// Trigger a short reply.
#[derive(Parser)]
pub struct Args {}
#[async_trait]
impl<B, E> ClapCommand<B, E> for Ping
where