From 8b8d281f8a2dffe3aaa273a623d604e81c81fae5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 26 Feb 2023 19:50:29 +0100 Subject: [PATCH] Implement Command for Ping --- CHANGELOG.md | 3 +++ src/bot/botrulez/ping.rs | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a99e5b2..93b3841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Procedure when bumping the version number: ## Unreleased +### Added +- `bot::botrulez::Ping` now implements `bot::command::Command` + ### Changed - Instances log to target `euphoxide::live::` diff --git a/src/bot/botrulez/ping.rs b/src/bot/botrulez/ping.rs index 056ac35..cb48195 100644 --- a/src/bot/botrulez/ping.rs +++ b/src/bot/botrulez/ping.rs @@ -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 Command for Ping +where + E: From, +{ + 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 ClapCommand for Ping where