TODO: reply_handler does not work
This commit is contained in:
parent
b03d76c494
commit
b9ea2f8caf
|
@ -1,4 +1,4 @@
|
|||
use teloxide::prelude::*;
|
||||
use teloxide::{prelude::*, repl};
|
||||
|
||||
pub mod commands;
|
||||
mod handlers;
|
||||
|
@ -43,16 +43,45 @@ impl Godette {
|
|||
}
|
||||
|
||||
pub async fn message_dispatcher(bot: Bot, msg: Message) -> ResponseResult<()> {
|
||||
let thanks = vec!["спасибо", "спс", "благодар очка"];
|
||||
let text = msg
|
||||
.text()
|
||||
.unwrap_or(msg.caption().unwrap_or_default())
|
||||
.to_string();
|
||||
match text.to_lowercase().find("спасибо") {
|
||||
|
||||
for thank in thanks {
|
||||
match text.to_lowercase().find(thank) {
|
||||
Some(_id) => {
|
||||
bot.send_message(msg.chat.id, "Не за что!").await?;
|
||||
}
|
||||
None => (),
|
||||
};
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn reply_dispatcher(
|
||||
bot: Bot,
|
||||
msg: Message,
|
||||
reply_to_message: Message,
|
||||
) -> ResponseResult<()> {
|
||||
let thanks = vec!["спасибо", "спс", "благодар очка"];
|
||||
let text = msg
|
||||
.text()
|
||||
.unwrap_or(msg.caption().unwrap_or_default())
|
||||
.to_string();
|
||||
println!("{:?}", msg);
|
||||
println!("{:?}", bot);
|
||||
println!("{:?}", reply_to_message);
|
||||
for thank in thanks {
|
||||
match text.to_lowercase().find(thank) {
|
||||
Some(_id) => {
|
||||
handlers::karma(&bot, &msg, &reply_to_message, 1).await?;
|
||||
()
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,3 +66,27 @@ pub async fn unwarn(bot: Bot, msg: Message) -> ResponseResult<Message> {
|
|||
bot.send_message(msg.chat.id, "Это разбан".to_string())
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn karma(
|
||||
bot: &Bot,
|
||||
msg: &Message,
|
||||
reply: &Message,
|
||||
change: i8,
|
||||
) -> ResponseResult<Message> {
|
||||
let giver = msg.from().unwrap();
|
||||
let reciever = reply.from().unwrap();
|
||||
let change_text = match change {
|
||||
1 => "повысил",
|
||||
-1 => "понизил",
|
||||
_ => "изменил",
|
||||
};
|
||||
let text = format!(
|
||||
"*{}* {} карму *{}*",
|
||||
escape(&giver.first_name),
|
||||
change_text,
|
||||
escape(&reciever.first_name)
|
||||
);
|
||||
bot.send_message(msg.chat.id, text)
|
||||
.parse_mode(MarkdownV2)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -11,16 +11,21 @@ async fn main() {
|
|||
|
||||
let bot = Godette::new();
|
||||
let handler = Update::filter_message()
|
||||
// User commands
|
||||
.branch(
|
||||
dptree::entry()
|
||||
.filter_command::<commands::Command>()
|
||||
.endpoint(Godette::commands_dispatcher),
|
||||
)
|
||||
// Admin commands
|
||||
.branch(
|
||||
dptree::entry()
|
||||
.filter_command::<commands::AdminCommand>()
|
||||
.endpoint(Godette::admin_dispatcher),
|
||||
)
|
||||
// Replies
|
||||
.branch(Message::filter_reply_to_message().endpoint(Godette::reply_dispatcher))
|
||||
// Messages
|
||||
.branch(
|
||||
dptree::filter(|msg: Message| {
|
||||
msg.from()
|
||||
|
|
Loading…
Reference in New Issue