feat: add twitter video embed fixes

This commit is contained in:
Ladislav Hano 2024-09-28 18:39:32 +02:00
parent 08e6e91b1c
commit ff9e3607b3
2 changed files with 25 additions and 1 deletions

View file

@ -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::<u16>() % 1000 == 666 {
match msg.reply(ctx.http(), "Povedz loď").await {
Ok(_) => {},

View file

@ -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<Http>) -> anyhow::Result<ChannelId> {
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<Http>, msg: Message, content: String) -> Result<Message, serenity::Error> {
msg.delete(http.clone()).await?;
return ChannelId::new(msg.channel_id.get()).send_message(http.clone(), CreateMessage::new().content(content)).await;
}