change edit_msg_handler logic for more extensibility
This commit is contained in:
parent
2bac30e711
commit
4a37792c0c
32
src/main.rs
32
src/main.rs
@ -12,7 +12,9 @@ use envconfig::Envconfig;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use teloxide::dispatching::dialogue::serializer::Json;
|
use teloxide::dispatching::dialogue::serializer::Json;
|
||||||
use teloxide::dispatching::dialogue::{GetChatId, InMemStorage, PostgresStorage};
|
use teloxide::dispatching::dialogue::{GetChatId, InMemStorage, PostgresStorage};
|
||||||
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup, ReplyMarkup};
|
use teloxide::types::{
|
||||||
|
InlineKeyboardButton, InlineKeyboardMarkup, MediaKind, MessageKind, ReplyMarkup,
|
||||||
|
};
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
payloads::SendMessageSetters,
|
payloads::SendMessageSetters,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -195,16 +197,28 @@ async fn edit_msg_handler(
|
|||||||
(literal, lang): (String, String),
|
(literal, lang): (String, String),
|
||||||
msg: Message,
|
msg: Message,
|
||||||
) -> Result<(), teloxide::RequestError> {
|
) -> Result<(), teloxide::RequestError> {
|
||||||
match msg.html_text() {
|
use teloxide::utils::render::Renderer;
|
||||||
Some(text) => {
|
|
||||||
db.set_literal(&literal, &text).await.unwrap();
|
let chat_id = msg.chat.id;
|
||||||
bot.send_message(msg.chat.id, "Updated text of message!")
|
println!("Type: {:#?}", msg.kind);
|
||||||
.await
|
let msg = if let MessageKind::Common(msg) = msg.kind {
|
||||||
.unwrap();
|
msg
|
||||||
|
} else {
|
||||||
|
println!("Not a Common, somehow");
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
match msg.media_kind {
|
||||||
|
MediaKind::Text(text) => {
|
||||||
|
let html_text = Renderer::new(&text.text, &text.entities).as_html();
|
||||||
|
db.set_literal(&literal, &html_text).await.unwrap();
|
||||||
|
bot.send_message(chat_id, "Updated text of message!")
|
||||||
|
.await?;
|
||||||
dialogue.exit().await.unwrap();
|
dialogue.exit().await.unwrap();
|
||||||
}
|
}
|
||||||
None => {
|
_ => {
|
||||||
bot.send_message(msg.chat.id, "Send text!").await.unwrap();
|
bot.send_message(chat_id, "this type of message is not supported yet")
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user