107 lines
No EOL
3.1 KiB
Rust
107 lines
No EOL
3.1 KiB
Rust
use rand::random;
|
|
use rand::seq::IndexedRandom;
|
|
use serenity::http::CacheHttp;
|
|
use serenity::{client::Context, http::Http};
|
|
use serenity::model::channel::Message;
|
|
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
|
|
use crate::utils::debug::send_error;
|
|
use crate::utils::utilities;
|
|
|
|
use crate::commands::moover::moove::{moove, moove_check};
|
|
|
|
pub async fn handle(ctx: Context, msg: Message) {
|
|
if msg.author.bot {
|
|
return
|
|
}
|
|
|
|
let lower_case_content = msg.content.to_lowercase();
|
|
|
|
let bot_id = ctx.cache.current_user().id;
|
|
if msg.mentions_user_id(bot_id) || lower_case_content.contains("moover") {
|
|
if !response(ctx.http.clone(), msg.clone()).await {
|
|
// NOTE maybe should exit here instead since there is something very wrong if I can't reply
|
|
return
|
|
}
|
|
}
|
|
else if lower_case_content.contains("henlo") {
|
|
if !henlo(ctx.http.clone(), msg.clone()).await {
|
|
// NOTE same as above
|
|
return
|
|
}
|
|
}
|
|
|
|
// X and IG not embedding correctly (IG fix does not work for now need to find different one)
|
|
let link_fixes = HashMap::from([
|
|
("//x.com", "//fixvx.com")
|
|
]);
|
|
|
|
for (site, fix) in link_fixes {
|
|
if lower_case_content.contains(site) {
|
|
let new_content = format!("Sent by {}\n{}", msg.clone().author, lower_case_content.replace(site, fix));
|
|
match utilities::replace_msg(ctx.http.clone(), msg.clone(), new_content).await {
|
|
Ok(_) => {},
|
|
Err(e) => {
|
|
let _ = send_error(ctx.http.clone(), e.to_string()).await;
|
|
return;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
if random::<u16>() % 10000 == 666 {
|
|
match msg.reply(ctx.http(), "Povedz loď").await {
|
|
Ok(_) => {},
|
|
Err(e) => {
|
|
let _ = send_error(ctx.http.clone(), e.to_string()).await;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
let channel_id = match moove_check(&msg).await {
|
|
Some(val) => val,
|
|
None => return
|
|
};
|
|
|
|
match moove(ctx.http, msg.clone(), channel_id).await {
|
|
Ok(_) => return,
|
|
Err(e) => println!("ERROR: {e}")
|
|
};
|
|
}
|
|
|
|
async fn response(http: Arc<Http>, msg: Message) -> bool {
|
|
// NOTE probably not clever to do it this way
|
|
const RESPONSES: [&str; 4] = [
|
|
"To som jaaa",
|
|
"Henloooo",
|
|
"No čo je?",
|
|
"Hm?"
|
|
];
|
|
|
|
let response = RESPONSES.choose(&mut rand::rng()).unwrap_or(&"?").to_string();
|
|
match msg.reply(http.clone(), response).await {
|
|
Ok(_) => { return true }
|
|
Err(e) => {
|
|
let _ = send_error(http, e.to_string()).await;
|
|
return false
|
|
}
|
|
};
|
|
}
|
|
|
|
async fn henlo(http: Arc<Http>, msg: Message) -> bool {
|
|
const EMOJIS: [&str; 7] = ["🥰", "🐄", "🐮", "❤️", "👋", "🤠", "😊"];
|
|
|
|
let emoji = EMOJIS.choose(&mut rand::rng()).unwrap_or(&"🐮");
|
|
let response = format!("Henlooo {} {}", msg.author.name, emoji);
|
|
|
|
match msg.reply(http.clone(), response).await {
|
|
Ok(_) => { return true }
|
|
Err(e) => {
|
|
let _ = send_error(http, e.to_string()).await;
|
|
return false
|
|
}
|
|
};
|
|
} |