diff --git a/src/message_handler.rs b/src/message_handler.rs index f0ba326..f8189f6 100644 --- a/src/message_handler.rs +++ b/src/message_handler.rs @@ -2,9 +2,11 @@ use rand::random; 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::util::debug::send_error; +use crate::util::utilities; use crate::commands::moove::{moove, moove_check}; @@ -29,6 +31,22 @@ pub async fn handle(ctx: Context, msg: Message) { } } + // 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", "//fxtwitter.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) => send_error(ctx.http.clone(), e.to_string()).await + }; + } + } + + if random::() % 1000 == 666 { match msg.reply(ctx.http(), "Povedz loď").await { Ok(_) => {}, diff --git a/src/util/utilities.rs b/src/util/utilities.rs index 781ee0c..7669eb7 100644 --- a/src/util/utilities.rs +++ b/src/util/utilities.rs @@ -1,10 +1,16 @@ use std::sync::Arc; -use serenity::{all::{GuildId, ChannelId}, http::Http}; +use serenity::{all::{ChannelId, CreateMessage, GuildId, Message}, http::Http}; use anyhow::Context; pub async fn get_system_channel(guild_id: GuildId, http: Arc) -> anyhow::Result { return http.get_guild(guild_id).await?.system_channel_id .context(format!("System channel of guild: {} not found", guild_id.get())); +} + +pub async fn replace_msg(http: Arc, msg: Message, content: String) -> Result { + msg.delete(http.clone()).await?; + + return ChannelId::new(msg.channel_id.get()).send_message(http.clone(), CreateMessage::new().content(content)).await; } \ No newline at end of file