use super::dox_impl::{dox, get_full_info};
use frakti::{
client_cyper::Bot,
types::{ChatType, Message, MessageOrigin},
};
use log::{debug, info};
pub async fn handle_non_command(bot: &Bot, msg: Message) -> Option<String> {
if matches!(msg.chat.type_field, ChatType::Private) {
info!("Handling non-command message in PM: {msg:?}");
let reply = if let Some(origin) = msg.forward_origin {
let doxer = match &msg.from {
None => {
return Some(
include_str!("./messages/doxer-identification-failed.html").to_string(),
);
}
Some(doxer) => doxer,
};
let _doxer_info = match get_full_info(bot, doxer.id).await {
None => {
return Some(
include_str!("./messages/doxer-identification-failed.html").to_string(),
);
}
Some(full_info) => full_info,
};
if let MessageOrigin::User(origin_user) = *origin {
let doxee = origin_user.sender_user;
let full_info = get_full_info(bot, doxee.id).await;
dox(&doxee, full_info.as_ref())
} else {
debug!("Cannot determine the origin as a user: {origin:?}");
include_str!("messages/invalid-origin.html").to_string()
}
} else {
debug!(
"Not a command or forwarded message: {:?}",
msg.text.as_ref()
);
include_str!("messages/incomprehensible.html").to_string()
};
Some(reply)
} else {
None
}
}