Reworked dispatcher, added testing "Thanks" endpoint
This commit is contained in:
parent
07138bb5e2
commit
9ebd181161
|
@ -25,6 +25,18 @@ impl Godette {
|
|||
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> {
|
||||
bot.send_message(msg.chat.id, Command::descriptions().to_string())
|
||||
.await
|
||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -1,19 +1,38 @@
|
|||
mod commands;
|
||||
mod godette;
|
||||
|
||||
use teloxide::{
|
||||
prelude::*, types::ParseMode::MarkdownV2, utils::command::BotCommands, utils::markdown,
|
||||
};
|
||||
use teloxide::prelude::*;
|
||||
|
||||
use godette::Godette;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let bot = godette::Godette::new();
|
||||
teloxide::commands_repl(
|
||||
bot.bot,
|
||||
godette::Godette::commands_dispatcher,
|
||||
commands::Command::ty(),
|
||||
let bot = Godette::new();
|
||||
let handler = Update::filter_message()
|
||||
.branch(
|
||||
dptree::entry()
|
||||
.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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue