use super::dox_impl::DoxReport;
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 {
if msg.from.is_none() && msg.sender_chat.is_none() {
return Some(
include_str!("./messages/doxer-identification-failed.html").to_string(),
);
}
match *origin {
MessageOrigin::User(origin_user) => {
DoxReport::from_user(origin_user.sender_user)
.complete_full_info(bot)
.await
.to_string()
}
MessageOrigin::Channel(origin_channel) => {
DoxReport::from_chat(origin_channel.chat)
.with_title(origin_channel.author_signature)
.to_string()
}
MessageOrigin::Chat(origin_chat) => {
DoxReport::from_chat(origin_chat.sender_chat)
.with_title(origin_chat.author_signature)
.to_string()
}
MessageOrigin::HiddenUser(_) => {
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
}
}