mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
fix: command and reply overlap
This commit is contained in:
parent
74518da0bc
commit
c5d073d29b
@ -17,7 +17,7 @@ pub enum Command {
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns a Teloxide error if the message fails to send.
|
/// Returns a Teloxide error if the message fails to send.
|
||||||
pub async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
|
pub async fn answer(bot: &Bot, msg: &Message, cmd: Command) -> ResponseResult<()> {
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Help => {
|
Command::Help => {
|
||||||
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
||||||
|
|||||||
17
src/main.rs
17
src/main.rs
@ -1,6 +1,7 @@
|
|||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use teloxide::{prelude::*, respond};
|
use teloxide::{prelude::*, respond, utils::command::BotCommands};
|
||||||
use tg_relay_rs::{
|
use tg_relay_rs::{
|
||||||
|
commands::{Command, answer},
|
||||||
comments::Comments,
|
comments::Comments,
|
||||||
config::{Config, global_config},
|
config::{Config, global_config},
|
||||||
handler::{Handler, create_handlers},
|
handler::{Handler, create_handlers},
|
||||||
@ -17,7 +18,7 @@ async fn main() -> color_eyre::Result<()> {
|
|||||||
Comments::load_from_file("comments.txt")
|
Comments::load_from_file("comments.txt")
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
warn!("failed to laod comments.txt: {}; using dummy comments", e);
|
warn!("failed to laod comments.txt: {e}; using dummy comments");
|
||||||
e
|
e
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|_| Comments::dummy())
|
.unwrap_or_else(|_| Comments::dummy())
|
||||||
@ -26,17 +27,17 @@ async fn main() -> color_eyre::Result<()> {
|
|||||||
|
|
||||||
Config::from_env()
|
Config::from_env()
|
||||||
.init()
|
.init()
|
||||||
.expect("failed to initialize comments");
|
.expect("failed to initialize config");
|
||||||
|
|
||||||
let bot = Bot::from_env();
|
let bot = Bot::from_env();
|
||||||
info!("bot starting");
|
info!("bot starting");
|
||||||
|
|
||||||
let handlers = create_handlers();
|
let handlers = create_handlers();
|
||||||
|
|
||||||
// Command::repl(bot.clone(), answer).await;
|
|
||||||
teloxide::repl(bot.clone(), move |bot: Bot, msg: Message| {
|
teloxide::repl(bot.clone(), move |bot: Bot, msg: Message| {
|
||||||
let handlers = handlers.clone();
|
let handlers = handlers.clone();
|
||||||
async move {
|
async move {
|
||||||
|
process_cmd(&bot, &msg).await;
|
||||||
process_message(&bot, &msg, &handlers).await;
|
process_message(&bot, &msg, &handlers).await;
|
||||||
respond(())
|
respond(())
|
||||||
}
|
}
|
||||||
@ -66,3 +67,11 @@ async fn process_message(bot: &Bot, msg: &Message, handlers: &[Handler]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn process_cmd(bot: &Bot, msg: &Message) {
|
||||||
|
if let Some(text) = msg.text()
|
||||||
|
&& let Ok(cmd) = Command::parse(text, "guenter")
|
||||||
|
{
|
||||||
|
let _ = answer(bot, msg, cmd).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user