This commit is contained in:
MedzikUser 2022-03-04 19:46:58 +01:00
parent 06a908ff36
commit ef1f9342ee
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
2 changed files with 25 additions and 10 deletions

View File

@ -2,7 +2,7 @@ use super::clipboard::set_clipboard;
use imgurs::api::{upload_image::upload_image as upload_img, ImgurClient};
use notify_rust::Notification;
use crate::{config::toml, cli::webhook::send_discord_webhook};
use crate::{cli::webhook::send_discord_webhook, config::toml};
use super::print_image_info;
@ -50,6 +50,8 @@ pub async fn upload_image(client: ImgurClient, path: &str) {
}
if config.discord_webhook.enabled {
send_discord_webhook(i.data.link, i.data.deletehash.unwrap()).await.expect("send discord webhook");
send_discord_webhook(i.data.link, i.data.deletehash.unwrap())
.await
.expect("send discord webhook");
}
}

View File

@ -3,17 +3,30 @@ use webhook::client::WebhookClient;
use crate::config::toml;
pub async fn send_discord_webhook(link: String, deletehash: String) -> Result<bool, Box<dyn Error + Send + Sync>> {
pub async fn send_discord_webhook(
link: String,
deletehash: String,
) -> Result<bool, Box<dyn Error + Send + Sync>> {
let url = toml::parse().discord_webhook.uri;
let client: WebhookClient = WebhookClient::new(&url);
let webhook = client.send(|message| message
.username("Imgurs")
.embed(|embed| embed
.title("Imgurs")
.description(&format!("Delete Hash ||{deletehash}||"))
.image(&link)
.footer(&format!("Imgurs v{}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")), None))).await;
let webhook = client
.send(|message| {
message.username("Imgurs").embed(|embed| {
embed
.title("Imgurs")
.description(&format!("Delete Hash ||{deletehash}||"))
.image(&link)
.footer(
&format!(
"Imgurs v{}",
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")
),
None,
)
})
})
.await;
webhook
}