1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-10-16 14:37:27 +00:00

Add /echo command

This commit is contained in:
Steffo 2024-07-08 04:23:18 +02:00
parent a8534c8d27
commit 251080aa48
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,20 @@
use anyhow::Context;
use teloxide::Bot;
use teloxide::payloads::SendMessageSetters;
use teloxide::requests::Requester;
use teloxide::types::{Message};
use super::{CommandResult};
pub async fn handler(bot: Bot, message: Message, text: String) -> CommandResult {
let text = format!(
"💬 {text}"
);
let _reply = bot
.send_message(message.chat.id, text)
.reply_to_message_id(message.id)
.await
.context("Failed to send message")?;
Ok(())
}

View file

@ -1,7 +1,6 @@
// See the following link for an example of how to use this file:
// https://github.com/teloxide/teloxide/blob/master/crates/teloxide/examples/dispatching_features.rs
use std::sync::Arc;
use anyhow::{Context, Error};
use teloxide::{Bot, dptree};
use teloxide::dispatching::{DefaultKey, Dispatcher, HandlerExt, UpdateFilterExt};
@ -13,12 +12,14 @@ use teloxide::utils::command::BotCommands;
mod start;
mod fortune;
mod echo;
#[derive(Debug, Clone, BotCommands)]
#[command(rename_rule = "lowercase")]
enum Command {
Start,
Fortune,
Echo(String)
}
async fn handle_command(bot: Bot, command: Command, message: Message) -> CommandResult {
@ -27,6 +28,7 @@ async fn handle_command(bot: Bot, command: Command, message: Message) -> Command
match command {
Command::Start => start::handler(bot, message).await,
Command::Fortune => fortune::handler(bot, message).await,
Command::Echo(text) => echo::handler(bot, message, text).await,
}
}