html terminal
fix emotes
bendn 2023-10-21
parent 87e7f96 · commit 6529afa
-rw-r--r--Cargo.toml10
-rw-r--r--src/bot/mod.rs58
-rw-r--r--src/bot/schematic.rs8
-rw-r--r--src/conv.rs256
-rw-r--r--src/main.rs1
-rw-r--r--src/webhook.rs7
6 files changed, 273 insertions, 67 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 4973400..88f955f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,24 +34,28 @@ poise = "0.5.5"
anyhow = "1.0.75"
regex = { version = "1.8.4", features = ["std"], default-features = false }
minify-js = "0.5.6"
-itertools = "0.11"
convert_case = "0.6.0"
parse_duration = "2.1.1"
serde = "1.0"
serde_json = "1.0"
btparse = "0.1.1"
mindus = { version = "5", features = [], default-features = false }
-oxipng = { git = "https://github.com/shssoichiro/oxipng", branch = "master", features = [], default-features = false }
+oxipng = { git = "https://github.com/shssoichiro/oxipng", branch = "master", default-features = false }
flate2 = { version = "1.0", features = ["cloudflare_zlib"], default-features = false }
strip-ansi-escapes = "0.2.0"
dashmap = "5.5.1"
lemu = { features = ["diagnose"], default-features = false, version = "0.2.0" }
+phf = { version = "0.11.2", features = ["macros"] }
[profile.release]
strip = true
+lto = "thin"
[build-dependencies]
minify-html = "0.11.1"
-[profile.dev.package."*"]
+[profile.dev.package.mindus]
+opt-level = 3
+
+[profile.dev.package.fimg]
opt-level = 3
diff --git a/src/bot/mod.rs b/src/bot/mod.rs
index 1a79f2e..534e2a4 100644
--- a/src/bot/mod.rs
+++ b/src/bot/mod.rs
@@ -60,7 +60,6 @@ macro_rules! send_ctx {
pub const SOURCE_GUILD: u64 = 1003092764919091282;
pub mod emojis {
use super::SOURCE_GUILD;
- use mindus::item::Type as Item;
use poise::serenity_prelude::Emoji;
use serenity::http::client::Http;
use std::sync::OnceLock;
@@ -83,31 +82,7 @@ pub mod emojis {
}
} };
}
- create![
- ARROW,
- COPPER,
- GRAPHITE,
- LEAD,
- SILICON,
- TITANIUM,
- SAND,
- COAL,
- PYRATITE,
- PLASTANIUM,
- SCRAP,
- SPOREPOD,
- THORIUM,
- SURGEALLOY,
- TUNGSTEN,
- PHASEFABRIC,
- OXIDE,
- METAGLASS,
- FISSILEMATTER,
- DORMANTCYST,
- CARBIDE,
- BLASTCOMPOUND,
- BERYLLIUM
- ];
+ create![ARROW,];
macro_rules! get {
($e: ident) => {
@@ -115,35 +90,6 @@ pub mod emojis {
};
}
pub(crate) use get;
-
- pub fn item(i: Item) -> Emoji {
- use Item::*;
- // exec() when
- match i {
- Copper => get!(COPPER),
- Lead => get!(LEAD),
- Metaglass => get!(METAGLASS),
- Graphite => get!(GRAPHITE),
- Sand => get!(SAND),
- Coal => get!(COAL),
- Titanium => get!(TITANIUM),
- Thorium => get!(THORIUM),
- Scrap => get!(SCRAP),
- Silicon => get!(SILICON),
- Plastanium => get!(PLASTANIUM),
- PhaseFabric => get!(PHASEFABRIC),
- SurgeAlloy => get!(SURGEALLOY),
- SporePod => get!(SPOREPOD),
- BlastCompound => get!(BLASTCOMPOUND),
- Pyratite => get!(PYRATITE),
- Beryllium => get!(BERYLLIUM),
- Tungsten => get!(TUNGSTEN),
- Oxide => get!(OXIDE),
- Carbide => get!(CARBIDE),
- FissileMatter => get!(FISSILEMATTER),
- DormantCyst => get!(DORMANTCYST),
- }
- }
}
const PFX: &str = ">";
#[cfg(debug_assertions)]
@@ -187,7 +133,7 @@ pub async fn safe(m: &Message, c: &serenity::client::Context) -> String {
result = result.replace(&mention, "@deleted-role");
}
}
- result
+ crate::conv::replace(&result)
}
pub async fn say(c: &serenity::client::Context, m: &Message, d: &Data) -> Result<()> {
diff --git a/src/bot/schematic.rs b/src/bot/schematic.rs
index a8c5374..4c3aced 100644
--- a/src/bot/schematic.rs
+++ b/src/bot/schematic.rs
@@ -7,7 +7,7 @@ use regex::Regex;
use std::sync::LazyLock;
use std::{borrow::Cow, ops::ControlFlow};
-use super::{emojis, strip_colors, SMsg, SUCCESS};
+use super::{strip_colors, SMsg, SUCCESS};
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(```)?(\n)?([^`]+)(\n)?(```)?").unwrap());
@@ -38,8 +38,8 @@ async fn from_attachments(attchments: &[Attachment]) -> Result<Option<Schematic>
pub async fn with(m: SMsg, c: &serenity::client::Context) -> Result<ControlFlow<Message, ()>> {
let author = m.author;
let send = |v: Schematic| async move {
- let d = v.tags.get("description").cloned();
- let name = strip_colors(v.tags.get("name").unwrap());
+ let d = v.tags.get("description").map(|t| crate::conv::replace(t));
+ let name = crate::conv::replace(&strip_colors(v.tags.get("name").unwrap()));
let cost = v.compute_total_cost().0;
let p = tokio::task::spawn_blocking(move || to_png(&v)).await?;
anyhow::Ok(
@@ -58,7 +58,7 @@ pub async fn with(m: SMsg, c: &serenity::client::Context) -> Result<ControlFlow<
continue;
}
use std::fmt::Write;
- write!(s, "{} {n} ", emojis::item(i)).unwrap();
+ write!(s, "{} {n} ", crate::conv::item(i)).unwrap();
}
e.field("", s, true);
e.title(name)
diff --git a/src/conv.rs b/src/conv.rs
new file mode 100644
index 0000000..19752dd
--- /dev/null
+++ b/src/conv.rs
@@ -0,0 +1,256 @@
+use mindus::item::Type as Item;
+
+static E2E: phf::Map<char, &str> = phf::phf_map! {
+ '' => "<:launch_pad:1165059549477220382>",
+ '' => "<:surge_conveyor:1165056614835945542>",
+ '' => "<:pyratite_mixer:1164832608002256906>",
+ '' => "<:poly:1165060238341316720>",
+ '' => "<:vault:1165057825110761583>",
+ '' => "<:copper_wall_large:1164868430726430790>",
+ '' => "<:segment:1164869661591089163>",
+ '' => "<:ripple:1164869672458530816>",
+ '' => "<:hail:1164869685133717564>",
+ '' => "<:force_projector:1164868932440698891>",
+ '' => "<:distributor:1165056571445874798>",
+ '' => "<:message:1165059277409484820>",
+ '' => "<:naval_factory:1164846856094875738>",
+ '' => "<:liquid_source:1165056998862237857>",
+ '' => "<:impact_reactor:1165057397711179846>",
+ '' => "<:illuminator:1165057394418655311>",
+ '' => "<:melter:1164832622455824395>",
+ '' => "<:item_source:1165056586012700793>",
+ '' => "<:logic_processor:1165059269356433459>",
+ '' => "<:payload_source:1165055051648209008>",
+ '' => "<:phase_conduit:1165057015228407899>",
+ '' => "<:disassembler:1164832634598346813>",
+ '' => "<:minke:1165060225489981440>",
+ '' => "<:titanium_wall:1164868373335773184>",
+ '' => "<:plastanium_wall:1164868410379874404>",
+ '' => "<:scrap_wall_gigantic:1164868400410005545>",
+ '' => "<:bridge_conveyor:1165056566337220678>",
+ '' => "<:payload_loader:1165055042408165376>",
+ '' => "<:container:1165057808954310667>",
+ '' => "<:zenith:1165060268607418440>",
+ '' => "<:hyper_processor:1165059260837806110>",
+ '' => "<:phase_weaver:1164832617389113374>",
+ '' => "<:cyerce:1165060197996310618>",
+ '' => "<:world_cell:1165059286414659657>",
+ '' => "<:vela:1165060264958382081>",
+ '' => "<:liquid_container:1165056989135655034>",
+ '' => "<:scatter:1164869667295346732>",
+ '' => "<:liquid_void:1165057004889444402>",
+ '' => "<:payload_router:1165055049630748672>",
+ '' => "<:quad:1165060243500322967>",
+ '' => "<:memory_cell:1165059275572387921>",
+ '' => "<:salvo:1164869669224722432>",
+ '' => "<:liquid_router:1165056995783614574>",
+ '' => "<:wave:1164869646873280562>",
+ '' => "<:overdrive_dome:1164868924186316940>",
+ '' => "<:payload_void:1165055058988240906>",
+ '' => "<:meltdown:1164869678598979655>",
+ '' => "<:scrap_wall_huge:1164868397377527849>",
+ '' => "<:core_nucleus:1165057814801170583>",
+ '' => "<:tsunami:1164869649125605396>",
+ '' => "<:swarmer:1164869653357670480>",
+ '' => "<:cryofluid_mixer:1164832639807655988>",
+ '' => "<:oil_extractor:1165059446301536317>",
+ '' => "<:plated_conduit:1165057017388482660>",
+ '' => "<:pulverizer:1164832611500310548>",
+ '' => "<:rotary_pump:1165057025089228891>",
+ '' => "<:surge_wall:1164868390024921148>",
+ '' => "<:duct:1165056574872633354>",
+ '' => "<:micro_processor:1165059281087889479>",
+ '' => "<:nova:1165060232070828062>",
+ '' => "<:water_extractor:1165059449917018143>",
+ '' => "<:interplanetary_accelerator:1165059547526860950>",
+ '' => "<:fortress:1165060214580580352>",
+ '' => "<:mega:1165060222956621847>",
+ '' => "<:inverted_sorter:1165056577020121190>",
+ '' => "<:air_factory:1164846858871513148>",
+ '' => "<:rtg_generator:1165057406506651708>",
+ '' => "<:thruster:1164868368235507754>",
+ '' => "<:ground_factory:1164846860800892938>",
+ '' => "<:copper_wall:1164868434006392842>",
+ '' => "<:junction:1165056592169926677>",
+ '' => "<:payload_conveyor:1165055040411668500>",
+ '' => "<:multiplicative_reconstructor:1164846850013134920>",
+ '' => "<:pulsar:1165060241394765834>",
+ '' => "<:phase_conveyor:1165056600520802305>",
+ '' => "<:conduit:1165056982974210179>",
+ '' => "<:surge_wall_large:1164868386929512509>",
+ '' => "<:tetrative_reconstructor:1164846844053028945>",
+ '' => "<:bryde:1165060187229519963>",
+ '' => "<:unloader:1165057822791307344>",
+ '' => "<:armored_conveyor:1165056561492803644>",
+ '' => "<:reign:1165060249892433940>",
+ '' => "<:toxopid:1165060263368736920>",
+ '' => "<:scepter:1165060256276164668>",
+ '' => "<:arkyid:1165060180455739535>",
+ '' => "<:canvas:1165059258124087356>",
+ '' => "<:core_shard:1165057818148225064>",
+ '' => "<:item_void:1165056589275865168>",
+ '' => "<:corvus:1165060189876125806>",
+ '' => "<:combustion_generator:1165057385799352321>",
+ '' => "<:power_node_large:1165057403176358018>",
+ '' => "<:plastanium_compressor:1164832614096576555>",
+ '' => "<:battery:1165057379935727756>",
+ '' => "<:silicon_smelter:1164832599328444447>",
+ '' => "<:crawler:1165060193940422786>",
+ '' => "<:antumbra:1165060178392129698>",
+ '' => "<:scorch:1164869663663071282>",
+ '' => "<:mend_projector:1164868930616180746>",
+ '' => "<:logic_display:1165059267267674224>",
+ '' => "<:router:1165056609395949638>",
+ '' => "<:liquid_junction:1165056991853559868>",
+ '' => "<:dagger:1165060204858183690>",
+ '' => "<:cyclone:1164869703437668392>",
+ '' => "<:differential_generator:1165057389242896395>",
+ '' => "<:payload_unloader:1165055055473410048>",
+ '' => "<:mono:1165060228618928178>",
+ '' => "<:world_message:1165059289648480297>",
+ '' => "<:plastanium_conveyor:1165056604174045277>",
+ '' => "<:conveyor:1165056569621369013>",
+ '' => "<:foreshadow:1164869696064073760>",
+ '' => "<:thermal_generator:1165057421899726968>",
+ '' => "<:mender:1164868927264915466>",
+ '' => "<:fuse:1164869692591198208>",
+ '' => "<:overdrive_projector:1164868922135289996>",
+ '' => "<:switch:1165059283331862620>",
+ '' => "<:battery_large:1165057382066434149>",
+ '' => "<:graphite_press:1164832630643105853>",
+ '' => "<:memory_bank:1165059272426668102>",
+ '' => "<:incinerator:1164832628642431037>",
+ '' => "<:oct:1165060234310598788>",
+ '' => "<:solar_panel:1165057408616366101>",
+ '' => "<:armored_duct:1165056563300544523>",
+ '' => "<:arc:1164869705882943580>",
+ '' => "<:retusa:1165060254183206942>",
+ '' => "<:quasar:1165060246646046740>",
+ '' => "<:thorium_wall:1164868384018665552>",
+ '' => "<:overflow_gate:1165056597467332678>",
+ '' => "<:power_node:1165057399678308383>",
+ '' => "<:blast_drill:1165059437363474504>",
+ '' => "<:kiln:1164832625547018251>",
+ '' => "<:mass_driver:1165056595466649620>",
+ '' => "<:separator:1164832606160961606>",
+ '' => "<:liquid_tank:1165057003027181649>",
+ '' => "<:mechanical_drill:1165059443264864307>",
+ '' => "<:core_foundation:1165057811387011203>",
+ '' => "<:impulse_pump:1165056986040250448>",
+ '' => "<:titanium_wall_large:1164868370177466388>",
+ '' => "<:sei:1165060259719680160>",
+ '' => "<:atrax:1165060183593074710>",
+ '' => "<:gamma:1165060216719683664>",
+ '' => "<:shield_projector:1164868919903928330>",
+ '' => "<:exponential_reconstructor:1164846847148445716>",
+ '' => "<:mechanical_pump:1165057009620635749>",
+ '' => "<:scrap_wall:1164868403593482281>",
+ '' => "<:horizon:1165060220070932551>",
+ '' => "<:payload_mass_driver:1165055046216585226>",
+ '' => "<:surge_tower:1165057419894853725>",
+ '' => "<:phase_wall_large:1164868414100213760>",
+ '' => "<:door_large:1164868422555926538>",
+ '' => "<:bridge_conduit:1165056979702657024>",
+ '' => "<:titanium_conveyor:1165056617809715210>",
+ '' => "<:sorter:1165056611480502322>",
+ '' => "<:thorium_reactor:1165057424915431474>",
+ '' => "<:cultivator:1164832636452216922>",
+ '' => "<:phase_wall:1164868417803796490>",
+ '' => "<:coal_centrifuge:1164832643246989333>",
+ '' => "<:thorium_wall_large:1164868375353249793>",
+ '' => "<:flare:1165060210944127067>",
+ '' => "<:multi_press:1164832620522242068>",
+ '' => "<:lancer:1164869681472094219>",
+ '' => "<:world_processor:1165059291473006612>",
+ '' => "<:duo:1164869699817967616>",
+ '' => "<:plastanium_wall_large:1164868405661278229>",
+ '' => "<:diode:1165057391172272188>",
+ '' => "<:underflow_gate:1165056619873320981>",
+ '' => "<:pneumatic_drill:1165059448058953728>",
+ '' => "<:pulse_conduit:1165057021205303336>",
+ '' => "<:eclipse:1165060207517372456>",
+ '' => "<:steam_generator:1165057415658614795>",
+ '' => "<:laser_drill:1165059440077189140>",
+ '' => "<:blast_mixer:1164832645126041600>",
+ '' => "<:door:1164868425294823524>",
+ '' => "<:parallax:1164869674568261683>",
+ '' => "<:scrap_wall_large:1164868391950106704>",
+ '' => "<:spectre:1164869658365673512>",
+ '' => "<:surge_smelter:1164832648426950706>",
+ '' => "<:solar_panel_large:1165057412126998649>",
+ '' => "<:silicon_crucible:1164832602696462346>",
+ '' => "<:large_logic_display:1165059264230981702>",
+ '' => "<:spore_press:1164832597411647508>",
+ '' => "<:additive_reconstructor:1164846854006120551>",
+ '' => item(Item::Tungsten),
+ '' => item(Item::Titanium),
+ '' => item(Item::Thorium),
+ '' => item(Item::SurgeAlloy),
+ '' => item(Item::SporePod),
+ '' => item(Item::Silicon),
+ '' => item(Item::Scrap),
+ '' => item(Item::Sand),
+ '' => item(Item::Pyratite),
+ '' => item(Item::Plastanium),
+ '' => item(Item::PhaseFabric),
+ '' => item(Item::Metaglass),
+ '' => item(Item::Lead),
+ '' => item(Item::Graphite),
+ '' => item(Item::FissileMatter),
+ '' => item(Item::DormantCyst),
+ '' => item(Item::Copper),
+ '' => item(Item::Coal),
+ '' => item(Item::Carbide),
+ '' => item(Item::BlastCompound),
+ '' => item(Item::Beryllium),
+ '' => item(Item::Oxide),
+};
+
+/// Returns the emoji of a item
+pub const fn item(i: Item) -> &'static str {
+ use Item::*;
+ match i {
+ Tungsten => "<:tungsten:1144220586382458970>",
+ Titanium => "<:titanium:1144220588978749551>",
+ Thorium => "<:thorium:1144220593068191784>",
+ SurgeAlloy => "<:surgealloy:1144220597484789822>",
+ SporePod => "<:sporepod:1144220601205149777>",
+ Silicon => "<:silicon:1144220607710502922>",
+ Scrap => "<:scrap:1144220611531505704>",
+ Sand => "<:sand:1144220613880315934>",
+ Pyratite => "<:pyratite:1144220617319657572>",
+ Plastanium => "<:plastanium:1144220622403153971>",
+ PhaseFabric => "<:phasefabric:1144220626224156794>",
+ Metaglass => "<:metaglass:1144220649901019206>",
+ Lead => "<:lead:1144220654686699570>",
+ Graphite => "<:graphite:1144220661137551400>",
+ FissileMatter => "<:fissilematter:1144220673670131742>",
+ DormantCyst => "<:dormantcyst:1144220677994446928>",
+ Copper => "<:copper:1144220690216648704>",
+ Coal => "<:coal:1144220692729036800>",
+ Carbide => "<:carbide:1144220696927555584>",
+ BlastCompound => "<:blastcompound:1144220701671305319>",
+ Beryllium => "<:beryllium:1144220705739788288>",
+ Oxide => "<:oxide:1144220632746295316>",
+ }
+}
+
+pub fn replace(s: &str) -> String {
+ let mut o = String::with_capacity(s.len());
+ for ch in s.chars() {
+ if let Some(mtch) = E2E.get(&ch) {
+ o.push_str(mtch)
+ } else {
+ o.push(ch);
+ }
+ }
+ o
+}
+
+#[test]
+fn convrt() {
+ assert_eq!(
+ replace("the  will output many /s"),
+ "the <:spore_press:1164832597411647508> will output many <:sporepod:1144220601205149777>/s"
+ );
+}
diff --git a/src/main.rs b/src/main.rs
index 34ee551..8e0b2d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ use std::str::FromStr;
mod logging;
#[macro_use]
mod bot;
+mod conv;
mod process;
mod server;
mod webhook;
diff --git a/src/webhook.rs b/src/webhook.rs
index e0b24b4..c41f931 100644
--- a/src/webhook.rs
+++ b/src/webhook.rs
@@ -1,4 +1,3 @@
-use itertools::Itertools;
use poise::serenity_prelude::Webhook as RealHook;
use regex::Regex;
use serenity::{builder::ExecuteWebhook, http::Http, json};
@@ -130,13 +129,13 @@ fn get(line: &str) -> Option<Message> {
static HAS_UUID: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[a-zA-Z0-9+/]{22}==").unwrap());
- if let Some((u, c)) = line.split(": ").map(unify).collect_tuple() {
+ if let Some((u, c)) = line.split_once(": ") {
let u = u.trim_start_matches('<');
let c = c.trim_end_matches('>');
if !(u.is_empty() || c.is_empty() || HAS_UUID.is_match(c) || HAS_UUID.is_match(u)) {
return Some(Message::Chat {
- player: u.to_owned(),
- content: c.to_owned(),
+ player: unify(u),
+ content: unify(&crate::conv::replace(c)),
});
}
}