//Finally sends the webhook to the servers
Finally sends the webhook to the servers
Finally sends the webhook to the servers
pub async fn deliver_webhook(content: EmbedData, pos: usize) {
	let token_raw = fs::read_to_string(TOKEN_PATH).expect("Cannot read file");
	let webhook_auth: WebhookAuth = serde_json::from_str(&token_raw).expect("Json cannot be read");
	let uid = webhook_auth.hooks[pos].uid;
	let token = &webhook_auth.hooks[pos].token;
	let my_http_client = Http::new(token);
	let webhook = match my_http_client.get_webhook_with_token(uid, token).await {
		Err(why) => {
			print_log(&format!("{why}"), 0);
			std::panic::panic_any(why)
		}
		Ok(hook) => hook,
	};
	let embed = Embed::fake(|e| {
		e.title(content.scrape_type.to_string())
		 .color(Color::from_rgb(116, 16, 210))
		 .field(&content.title, &content.preview_text, false)
		 .description(format!("Fetched on: <t:{}>", chrono::offset::Local::now().timestamp()))
		 .thumbnail("https://avatars.githubusercontent.com/u/97326911?s=40&v=4")
		 .image(&content.img_url)
		 .url(&content.url)
		 .footer(|f| {
			 f.icon_url("https://warthunder.com/i/favicons/mstile-70x70.png").text("Report bugs/issues: FlareFlo🦆#2800")
		 })
	});
	webhook.execute(my_http_client, false, |w| {
		w.content(&format!("[{}]()", &content.url));
		w.embeds(vec![embed]);
		w
	}).await.unwrap();
	print_log(&format!("Posted webhook for {}", webhook_auth.hooks[pos].name), 1);
}
pub async fn deliver_webhook ( content : EmbedData , pos : usize ) { let token_raw = fs :: read_to_string ( TOKEN_PATH ) . expect ( " " ) ; let webhook_auth : WebhookAuth = serde_json :: from_str ( & token_raw ) . expect ( " " ) ; let uid = webhook_auth . hooks [ pos ] . uid ; let token = & webhook_auth . hooks [ pos ] . token ; let my_http_client = Http :: new ( token ) ; let webhook = match my_http_client . get_webhook_with_token ( uid , token ) . await { Err ( why ) => { print_log ( & format ! ( " " ) , 0 ) ; std :: panic :: panic_any ( why ) } Ok ( hook ) => hook , } ; let embed = Embed :: fake ( | e | { e . title ( content . scrape_type . to_string ( ) ) . color ( Color :: from_rgb ( 116 , 16 , 210 ) ) . field ( & content . title , & content . preview_text , false ) . description ( format ! ( " " chrono offset Local now ( ) timestamp ( ) ) ) . thumbnail ( " " ) . image ( & content . img_url ) . url ( & content . url ) . footer ( | f | { f . icon_url ( " " ) . text ( " } ) } ) ; webhook . execute ( my_http_client , false , | w | { w . content ( & format ! ( " " content url ) ) ; w . embeds ( vec ! [ embed ] ) ; w } ) . await . unwrap ( ) ; print_log ( & format ! ( " " webhook_auth hooks [ pos ] name ) , 1 ) ; }
Finally sends the webhook to the servers
Finally sends the webhook to the servers
content
EmbedData
pos
usize