2020-12-31 01:42:36 +03:00
|
|
|
//use crate::commands::Command;
|
2021-01-05 03:50:20 +03:00
|
|
|
use crate::commands::{Code, Execute, Here, Markov, MarkovAll, Omedeto, Sql, Top};
|
2020-12-29 17:01:56 +03:00
|
|
|
use crate::db;
|
|
|
|
use crate::errors;
|
2020-12-10 16:54:39 +03:00
|
|
|
use crate::utils;
|
2020-12-29 17:01:56 +03:00
|
|
|
use mystem::MyStem;
|
|
|
|
use telegram_bot::*;
|
2020-12-10 16:54:39 +03:00
|
|
|
|
|
|
|
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,
|
|
|
|
data
|
|
|
|
);
|
|
|
|
db::add_sentence(&message, mystem).await?;
|
2021-01-03 22:37:37 +03:00
|
|
|
let cleaned_message = data.replace(&format!("@{}", me.clone().username.unwrap()), "");
|
2020-12-30 14:30:53 +03:00
|
|
|
match cleaned_message.as_str() {
|
2020-12-31 01:42:36 +03:00
|
|
|
s if s.contains("/here") => {
|
|
|
|
Here {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec(&api, &message)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
2021-01-05 03:30:21 +03:00
|
|
|
s if s.to_string().starts_with("/sql") => match {
|
2021-01-03 22:37:37 +03:00
|
|
|
Sql {
|
|
|
|
data: s.replace("/sql ", ""),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec_with_result(&api, &message)
|
2021-01-05 03:30:21 +03:00
|
|
|
.await
|
|
|
|
} {
|
2021-01-05 04:30:28 +03:00
|
|
|
Ok(msg) => {
|
|
|
|
let _ = api
|
|
|
|
.send(
|
|
|
|
message
|
|
|
|
.text_reply(msg)
|
|
|
|
.parse_mode(ParseMode::Html),
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
},
|
2021-01-05 03:30:21 +03:00
|
|
|
Err(e) => {
|
2021-01-05 04:30:28 +03:00
|
|
|
let _ = api
|
|
|
|
.send(
|
|
|
|
message
|
|
|
|
.text_reply(format!("Error: {:#?}", e))
|
|
|
|
.parse_mode(ParseMode::Html),
|
|
|
|
)
|
|
|
|
.await?;
|
2021-01-05 03:30:21 +03:00
|
|
|
}
|
|
|
|
},
|
2021-01-05 03:50:20 +03:00
|
|
|
s if s.to_string().starts_with("/code") => {
|
|
|
|
Code {
|
|
|
|
data: s.to_string(),
|
|
|
|
}
|
2021-01-05 05:01:34 +03:00
|
|
|
.exec(&api, &message)
|
2021-01-05 03:50:20 +03:00
|
|
|
.await?
|
|
|
|
}
|
2020-12-31 01:42:36 +03:00
|
|
|
"/top" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec(&api, &message)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/stat" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec(&api, &message)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov_all" => {
|
|
|
|
MarkovAll {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec(&api, &message)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov" => {
|
2020-12-31 01:56:20 +03:00
|
|
|
Markov {
|
2020-12-31 01:42:36 +03:00
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec(&api, &message)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/omedeto" => {
|
|
|
|
Omedeto {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
2021-01-05 04:30:28 +03:00
|
|
|
.exec_mystem(&api, &message, mystem)
|
2020-12-31 01:42:36 +03:00
|
|
|
.await?
|
|
|
|
}
|
2020-12-10 16:54: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("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("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(())
|
|
|
|
}
|