discord.rs
1 use serde::Serialize; 2 use url::Url; 3 4 use crate::http::{self, RequestBuilderExt}; 5 6 #[derive(Serialize, Debug)] 7 pub struct WebhookPayload<'a> { 8 pub username: &'a str, 9 pub avatar_url: &'a str, 10 pub embeds: &'a [Embed<'a>], 11 } 12 13 #[derive(Serialize, Debug)] 14 pub struct Embed<'a> { 15 pub title: String, 16 pub image: EmbedImage<'a>, 17 pub url: &'a Url, 18 pub author: EmbedAuthor<'a>, 19 pub color: u32, 20 pub timestamp: &'a str, 21 } 22 23 #[derive(Serialize, Debug)] 24 pub struct EmbedImage<'a> { 25 pub url: &'a Url, 26 } 27 28 #[derive(Serialize, Debug)] 29 pub struct EmbedAuthor<'a> { 30 pub name: &'a str, 31 pub url: &'a Url, 32 pub icon_url: &'a Url, 33 } 34 35 pub fn execute_webhook(url: Url, payload: &WebhookPayload) -> anyhow::Result<()> { 36 http::client() 37 .post(url) 38 .query(&[("wait", true)]) 39 .json(payload) 40 .execute_raw()?; 41 Ok(()) 42 } 43 44 pub fn check_webhook(url: Url) -> anyhow::Result<()> { 45 http::client().get(url).execute_raw()?; 46 Ok(()) 47 }