2022-03-07 19:10:58 +00:00
|
|
|
use discord_webhook::client::WebhookClient;
|
2022-03-07 19:21:46 +00:00
|
|
|
use std::error::Error;
|
2022-03-04 17:57:02 +00:00
|
|
|
|
|
|
|
use crate::config::toml;
|
|
|
|
|
2022-04-03 19:01:58 +00:00
|
|
|
// send embed with link and deletehash to discord (something like logger)
|
2022-03-04 18:46:58 +00:00
|
|
|
pub async fn send_discord_webhook(
|
2022-05-18 18:52:47 +00:00
|
|
|
link: &str,
|
|
|
|
deletehash: &str,
|
2022-04-03 19:01:58 +00:00
|
|
|
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
|
|
|
// get discord webhook uri from config
|
2022-03-04 17:57:02 +00:00
|
|
|
let url = toml::parse().discord_webhook.uri;
|
2022-04-03 19:01:58 +00:00
|
|
|
|
|
|
|
// create WebhookClient
|
2022-03-04 17:57:02 +00:00
|
|
|
let client: WebhookClient = WebhookClient::new(&url);
|
|
|
|
|
2022-04-03 19:01:58 +00:00
|
|
|
// get program version
|
|
|
|
let version = option_env!("CARGO_PKG_VERSION").unwrap_or("unknown");
|
|
|
|
|
|
|
|
// send discord webhook
|
2022-03-10 21:02:03 +00:00
|
|
|
client
|
2022-03-04 18:46:58 +00:00
|
|
|
.send(|message| {
|
|
|
|
message.username("Imgurs").embed(|embed| {
|
|
|
|
embed
|
2022-05-18 18:58:00 +00:00
|
|
|
.title(link)
|
2022-03-04 18:46:58 +00:00
|
|
|
.description(&format!("Delete Hash ||{deletehash}||"))
|
2022-05-18 18:58:00 +00:00
|
|
|
.image(link)
|
2022-04-03 19:01:58 +00:00
|
|
|
.footer(&format!("Imgurs v{version}"), None)
|
2022-03-04 18:46:58 +00:00
|
|
|
})
|
|
|
|
})
|
2022-04-03 19:01:58 +00:00
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
2022-03-04 17:57:02 +00:00
|
|
|
}
|