html terminal
remove panic
| -rw-r--r-- | src/bot/maps.rs | 10 | ||||
| -rw-r--r-- | src/bot/schematic.rs | 12 | ||||
| -rw-r--r-- | src/webhook.rs | 7 |
3 files changed, 11 insertions, 18 deletions
diff --git a/src/bot/maps.rs b/src/bot/maps.rs index a50d527..ad8bbcc 100644 --- a/src/bot/maps.rs +++ b/src/bot/maps.rs @@ -5,10 +5,7 @@ use mindus::*; use oxipng::*; use poise::serenity_prelude::*; use std::borrow::Cow; -use std::sync::{ - atomic::{AtomicU64, Ordering::Relaxed}, - LazyLock, -}; +use std::sync::atomic::{AtomicU64, Ordering::Relaxed}; use std::time::{Duration, Instant, SystemTime}; use tokio::sync::broadcast::{self, Sender}; use tokio::sync::{MutexGuard, OnceCell}; @@ -101,8 +98,7 @@ impl MapImage { // parsing the thing doesnt negate the need for a env var sooo let o = std::fs::read(std::env::var("SAVE_PATH").unwrap())?; let then = Instant::now(); - static REG: LazyLock<mindus::block::BlockRegistry> = LazyLock::new(build_registry); - let m = MapSerializer(®).deserialize(&mut mindus::data::DataRead::new(&o))?; + let m = Map::deserialize(&mut mindus::data::DataRead::new(&o))?; let deser_took = then.elapsed(); let name = m.tags.get("mapname").unwrap().to_owned(); let render_took = Instant::now(); @@ -158,7 +154,7 @@ pub async fn view(ctx: Context<'_>) -> Result<()> { }) .embed(|e| { if let Some(RenderInfo { deserialization, render, compression, total, name }) = info { - e.footer(|f| f.text(format!("render of {name} took: {:.2}s (deser: {}ms, render: {:.2}s, compression: {:.2}s)", total.as_secs_f32(), deserialization.as_millis(), render.as_secs_f32(), compression.as_secs_f32()))); + e.footer(|f| f.text(format!("render of {name} took: {:.3}s (deser: {}ms, render: {:.3}s, compression: {:.3}s)", total.as_secs_f32(), deserialization.as_millis(), render.as_secs_f32(), compression.as_secs_f32()))); } e.attachment("0.png").color(SUCCESS) }) diff --git a/src/bot/schematic.rs b/src/bot/schematic.rs index 16d1b07..9098a59 100644 --- a/src/bot/schematic.rs +++ b/src/bot/schematic.rs @@ -1,6 +1,6 @@ use super::{strip_colors, Context, SUCCESS}; use anyhow::{anyhow, Result}; -use mindus::data::{DataRead, DataWrite, Serializer}; +use mindus::data::{DataRead, DataWrite}; use mindus::*; use oxipng::*; use poise::serenity_prelude::*; @@ -11,7 +11,6 @@ use std::sync::LazyLock; static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"(```)?(\n)?([^`]+)(\n)?(```)?"#).unwrap()); -static REG: LazyLock<mindus::block::BlockRegistry> = LazyLock::new(build_registry); #[poise::command(context_menu_command = "Render schematic", category = "Info")] /// draw schematic. @@ -21,10 +20,9 @@ pub async fn context_draw(ctx: Context<'_>, msg: Message) -> Result<()> { if let Some(a) = msg.attachments.get(0) && let Some(e) = Path::new(&a.filename).extension() && e == "msch" { - let mut ss = SchematicSerializer(®); let s = a.download().await?; let mut s = DataRead::new(&s); - let s = ss.deserialize(&mut s).map_err(|e| anyhow!("invalid schematic: {e} with file {}", a.filename))?; + let s = Schematic::deserialize(&mut s).map_err(|e| anyhow!("invalid schematic: {e} with file {}", a.filename))?; return send(&ctx, &s, false).await; } draw_impl(ctx, &msg.content, false).await @@ -69,7 +67,7 @@ async fn send(ctx: &Context<'_>, s: &Schematic<'_>, send_schematic: bool) -> Res poise::send_reply(*ctx, |m| { if send_schematic { let mut out = DataWrite::default(); - SchematicSerializer(®).serialize(&mut out, s).unwrap(); + s.serialize(&mut out).unwrap(); m.attachment(AttachmentType::Bytes { data: Cow::Owned(out.consume()), filename: "schem.msch".to_string(), @@ -94,15 +92,13 @@ async fn send(ctx: &Context<'_>, s: &Schematic<'_>, send_schematic: bool) -> Res } async fn draw_impl(ctx: Context<'_>, msg: &str, send_schematic: bool) -> Result<()> { - let mut ss = SchematicSerializer(®); let schem_text = RE .captures(msg) .ok_or(anyhow!("couldnt find schematic"))? .get(3) .unwrap() .as_str(); - let s = ss - .deserialize_base64(schem_text) + let s = Schematic::deserialize_base64(schem_text) .map_err(|e| anyhow!("schematic deserializatiion failed: {e}"))?; send(&ctx, &s, send_schematic).await } diff --git a/src/webhook.rs b/src/webhook.rs index 71f8c79..ab71b90 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -87,7 +87,10 @@ impl<'a> Webhook<'a> { .is_ok() { input!("{m} < skipped"); - self.skipped.send(m).unwrap(); + match self.skipped.send(m) { + Err(e) => eprintln!("err skipping: {e}"), + Ok(_) => {} + }; continue; } for line in m.lines() { @@ -106,8 +109,6 @@ impl<'a> Webhook<'a> { let mut current: Option<String> = None; let mut message: Option<String> = None; let mut unnamed: Option<String> = None; - - // this code is very game dependent for line in feed { let line: String = Style::fix(line); if let Some((name, msg)) = Style::split(&line) { |