2021-01-08 17:32:39 +03:00
|
|
|
//use crate::commands::Command;
|
|
|
|
use crate::commands::{Code, Execute, Here, Markov, MarkovAll, Omedeto, Sql, Top};
|
|
|
|
use crate::db;
|
|
|
|
use crate::errors;
|
|
|
|
use crate::utils;
|
|
|
|
use mystem::MyStem;
|
|
|
|
use telegram_bot::*;
|
|
|
|
|
|
|
|
include!("../assets/help_text.rs");
|
|
|
|
|
|
|
|
pub async fn handler(
|
|
|
|
api: Api,
|
|
|
|
message: Message,
|
|
|
|
token: String,
|
|
|
|
mystem: &mut MyStem,
|
|
|
|
me: User,
|
|
|
|
) -> Result<(), errors::Error> {
|
|
|
|
match message.kind {
|
|
|
|
MessageKind::Text { ref data, .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: {}",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
2021-01-10 21:21:07 +03:00
|
|
|
data.replace("\n", " ")
|
2021-01-08 17:32:39 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
let cleaned_message = data.replace(&format!("@{}", me.clone().username.unwrap()), "");
|
|
|
|
match cleaned_message.as_str() {
|
|
|
|
s if s.to_string().starts_with("/code") => {
|
|
|
|
match {
|
|
|
|
Code {
|
|
|
|
data: s.replace("/code", ""),
|
|
|
|
}
|
2021-01-10 21:21:07 +03:00
|
|
|
.exec_with_result(&api, &message)
|
|
|
|
.await
|
2021-01-08 17:32:39 +03:00
|
|
|
} {
|
|
|
|
Ok(path) => {
|
|
|
|
let file = InputFileUpload::with_path(path.clone());
|
|
|
|
// api.send(message.chat.document(&file)).await?;
|
|
|
|
//
|
|
|
|
// // Send an image from disk
|
|
|
|
api.send(message.chat.photo(&file)).await?;
|
|
|
|
//debug!("{:#?}", formatter);
|
|
|
|
let _ = std::fs::remove_file(&path);
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
let _ = api
|
2021-01-10 21:38:18 +03:00
|
|
|
.send(message.text_reply(CODE_HELP).parse_mode(ParseMode::Html))
|
2021-01-08 17:32:39 +03:00
|
|
|
.await?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s if s.contains("/here") => {
|
|
|
|
db::add_sentence(&message, mystem).await?;
|
|
|
|
Here {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec(&api, &message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
s if s.to_string().starts_with("/sql") => match {
|
|
|
|
Sql {
|
|
|
|
data: s.replace("/sql ", ""),
|
|
|
|
}
|
|
|
|
.exec_with_result(&api, &message)
|
|
|
|
.await
|
|
|
|
} {
|
|
|
|
Ok(msg) => {
|
|
|
|
let _ = api
|
|
|
|
.send(message.text_reply(msg).parse_mode(ParseMode::Html))
|
|
|
|
.await?;
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
let _ = api
|
|
|
|
.send(
|
|
|
|
message
|
|
|
|
.text_reply(format!("Error: {:#?}", e))
|
|
|
|
.parse_mode(ParseMode::Html),
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"/top" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec(&api, &message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/stat" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec(&api, &message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov_all" => {
|
|
|
|
MarkovAll {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec(&api, &message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov" => {
|
|
|
|
Markov {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec(&api, &message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/omedeto" => {
|
|
|
|
Omedeto {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.exec_mystem(&api, &message, mystem)
|
|
|
|
.await?
|
|
|
|
}
|
2021-01-10 21:21:07 +03:00
|
|
|
_ => {
|
|
|
|
db::add_sentence(&message, mystem).await?
|
|
|
|
}
|
2021-01-08 17:32:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MessageKind::Photo { ref caption, .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *PHOTO* {}",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
caption.clone().unwrap_or_else(|| "NO_TITLE".to_string())
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageKind::Document { ref caption, .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *DOCUMENT* {}",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
caption.clone().unwrap_or_else(|| "NO_TITLE".to_string())
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageKind::Sticker { .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *STICKER*",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageKind::Voice { .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *VOICE*",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageKind::Video { .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *VIDEO*",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageKind::VideoNote { .. } => {
|
|
|
|
let title = utils::get_title(&message);
|
|
|
|
info!(
|
|
|
|
"<{}({})>[{}({})]: *VIDEO_NOTE*",
|
|
|
|
&message.chat.id(),
|
|
|
|
title,
|
|
|
|
&message.from.id,
|
|
|
|
&message.from.first_name,
|
|
|
|
);
|
|
|
|
utils::get_files(api, message, token).await?;
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
};
|
|
|
|
Ok(())
|
|
|
|
}
|