Reworked dispatcher, added testing "Thanks" endpoint
This commit is contained in:
parent
07138bb5e2
commit
9ebd181161
|
@ -25,6 +25,18 @@ impl Godette {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn message_dispatcher(bot: Bot, msg: Message) -> ResponseResult<()> {
|
||||||
|
let text = msg
|
||||||
|
.text()
|
||||||
|
.unwrap_or(msg.caption().unwrap_or_default())
|
||||||
|
.to_string();
|
||||||
|
match text.to_lowercase().find("спасибо") {
|
||||||
|
Some(_id) => bot.send_message(msg.chat.id, "Не за что!").await?,
|
||||||
|
None => todo!(),
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn show_help(bot: Bot, msg: Message) -> ResponseResult<Message> {
|
async fn show_help(bot: Bot, msg: Message) -> ResponseResult<Message> {
|
||||||
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
||||||
.await
|
.await
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -1,19 +1,38 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
mod godette;
|
mod godette;
|
||||||
|
|
||||||
use teloxide::{
|
use teloxide::prelude::*;
|
||||||
prelude::*, types::ParseMode::MarkdownV2, utils::command::BotCommands, utils::markdown,
|
|
||||||
};
|
use godette::Godette;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
|
|
||||||
let bot = godette::Godette::new();
|
let bot = Godette::new();
|
||||||
teloxide::commands_repl(
|
let handler = Update::filter_message()
|
||||||
bot.bot,
|
.branch(
|
||||||
godette::Godette::commands_dispatcher,
|
dptree::entry()
|
||||||
commands::Command::ty(),
|
.filter_command::<commands::Command>()
|
||||||
|
.endpoint(Godette::commands_dispatcher),
|
||||||
)
|
)
|
||||||
|
.branch(
|
||||||
|
dptree::filter(|msg: Message| {
|
||||||
|
msg.from()
|
||||||
|
.map(|user| user.id == UserId(60441930))
|
||||||
|
.unwrap_or_default()
|
||||||
|
})
|
||||||
|
.endpoint(Godette::message_dispatcher),
|
||||||
|
);
|
||||||
|
Dispatcher::builder(bot.bot, handler)
|
||||||
|
.default_handler(|upd| async move {
|
||||||
|
log::warn!("Unhandled update: {:?}", upd);
|
||||||
|
})
|
||||||
|
.error_handler(LoggingErrorHandler::with_custom_text(
|
||||||
|
"An error has occurred in the dispatcher",
|
||||||
|
))
|
||||||
|
.enable_ctrlc_handler()
|
||||||
|
.build()
|
||||||
|
.dispatch()
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue