mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-22 02:54:21 +00:00
Add /echo
command
This commit is contained in:
parent
a8534c8d27
commit
251080aa48
2 changed files with 23 additions and 1 deletions
20
src/telegram/commands/echo.rs
Normal file
20
src/telegram/commands/echo.rs
Normal 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(())
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue