From f1909ecad87bcd4c0d11fbde0ff2709f4233b29e Mon Sep 17 00:00:00 2001 From: core Date: Tue, 18 Jul 2023 14:48:35 -0400 Subject: [PATCH] make the bot more bettererererererer --- src/bot.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 21a71ac..c4d8283 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -2,6 +2,7 @@ use std::error::Error; use std::io::Cursor; use std::net::SocketAddr; use std::sync::{Arc}; +use std::thread; use serenity::prelude::*; use std::time::SystemTime; use azalea_buf::{McBufReadable, McBufVarReadable, McBufVarWritable}; @@ -117,13 +118,24 @@ async fn handle_packet(e: Event, config: &Arc>, reciever: &Receiv let re = Regex::new(r"@[a-z0-9_-]+:").unwrap(); if !(re.is_match(&pkt.content()) && pkt.uuid() == Some(config.read().await.relay.uuid)) { for wh in webhooks { - wh - .execute(http, false, |w| { - w.content(pkt.content()) - .username(pkt.username().unwrap_or("console".to_string())).allowed_mentions(|am| am.parse(ParseValue::Users).parse(ParseValue::Roles)).avatar_url(&format!("https://mc-heads.net/head/{}", pkt.uuid().map(|u| u.to_string()).unwrap_or("console".to_string()))) - }) - .await - .expect("Could not execute webhook."); + + tokio::spawn({ + let wh_clone = wh.clone(); + let http = Http::new(""); + let pkt = pkt.clone(); + move || { + async move { + wh_clone + .execute(http, false, |w| { + w.content(pkt.content()) + .username(pkt.username().unwrap_or("console".to_string())).allowed_mentions(|am| am.parse(ParseValue::Users).parse(ParseValue::Roles)).avatar_url(&format!("https://mc-heads.net/head/{}", pkt.uuid().map(|u| u.to_string()).unwrap_or("console".to_string()))) + }) + .await + .expect("Could not execute webhook."); + } + } + }()); + } }