2020-12-31 01:42:36 +03:00
|
|
|
//use crate::commands::Command;
|
|
|
|
use crate::commands::{Execute, Here, Markov, MarkovAll, Omedeto, 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
|
|
|
|
2020-12-31 01:42:36 +03:00
|
|
|
// struct Command {
|
|
|
|
// command: Commands,
|
|
|
|
// explicit: bool,
|
|
|
|
// rest: String,
|
|
|
|
// }
|
|
|
|
|
|
|
|
// async fn detector(msg: String, me: &User) -> Result<Command, ()> {
|
|
|
|
// let cleaned_message = msg.replace(&format!("@{}", me.clone().username.unwrap()), "");
|
|
|
|
// match cleaned_message.as_str() {
|
|
|
|
// "/here" => Ok(Command::Here {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// s if s.contains("/here") => Ok(Command::Here {
|
|
|
|
// data: s.to_string(),
|
|
|
|
// }),
|
|
|
|
// "/top" => Ok(Command::Top {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// "/stat" => Ok(Command::Top {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// s if s.contains(|z| z == "/top" || z == "/stat") => Ok(Command::Top {
|
|
|
|
// data: s.to_string(),
|
|
|
|
// }),
|
|
|
|
// "/markov_all" => Ok(Command::MarkovAll {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// s if s.contains("/markov_all") => Ok(Command::MarkovAll {
|
|
|
|
// data: s.to_string(),
|
|
|
|
// }),
|
|
|
|
// "/markov" => Ok(Command::Markov {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// s if s.contains("/markov") => Ok(Command::Markov {
|
|
|
|
// data: s.to_string(),
|
|
|
|
// }),
|
|
|
|
// "/omedeto" => Ok(Command::Omedeto {
|
|
|
|
// data: "".to_string(),
|
|
|
|
// }),
|
|
|
|
// s if s.contains("/Omedeto") => Ok(Command::Omedeto {
|
|
|
|
// data: s.to_string(),
|
|
|
|
// }),
|
|
|
|
// _ => Err(()),
|
|
|
|
// }
|
|
|
|
// }
|
2020-12-30 14:30:53 +03:00
|
|
|
|
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?;
|
2020-12-30 14:30:53 +03:00
|
|
|
let cleaned_message = data
|
2020-12-31 01:42:36 +03:00
|
|
|
.replace(&format!("@{}", me.clone().username.unwrap()), "");
|
|
|
|
debug!("Cleaned - {}", cleaned_message);
|
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(),
|
|
|
|
}
|
|
|
|
.run(api, message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/top" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.run(api, message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/stat" => {
|
|
|
|
Top {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.run(api, message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov_all" => {
|
|
|
|
MarkovAll {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.run(api, message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/markov" => {
|
|
|
|
MarkovAll {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.run(api, message)
|
|
|
|
.await?
|
|
|
|
}
|
|
|
|
"/omedeto" => {
|
|
|
|
Omedeto {
|
|
|
|
data: "".to_string(),
|
|
|
|
}
|
|
|
|
.run_mystem(api, message, mystem)
|
|
|
|
.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(())
|
|
|
|
}
|