html terminal
app emoj
| -rw-r--r-- | Cargo.toml | 7 | ||||
| -rw-r--r-- | build.rs | 2 | ||||
| -rw-r--r-- | html-src/masm-bindings.js | 2 | ||||
| -rw-r--r-- | html-src/masm.wasm | bin | 677618 -> 678619 bytes | |||
| -rw-r--r-- | src/alerts.rs | 2 | ||||
| -rw-r--r-- | src/bot/exec.rs | 4 | ||||
| -rw-r--r-- | src/bot/lb.rs | 2 | ||||
| -rw-r--r-- | src/bot/mod.rs | 2 | ||||
| -rw-r--r-- | src/bot/player.rs | 6 | ||||
| -rw-r--r-- | src/bot/rules.rs | 2 | ||||
| -rw-r--r-- | src/bot/trace.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/server.rs | 8 | ||||
| -rw-r--r-- | src/webhook.rs | 2 |
14 files changed, 30 insertions, 15 deletions
@@ -45,12 +45,17 @@ flate2 = { version = "1.0", features = [ strip-ansi-escapes = "0.2.0" phf = { version = "0.11.2", features = ["macros"] } itertools = "0.11.0" -emoji = { git = "https://github.com/Apricot-Conservation-Project/emoji" } +emojib = { git = "https://github.com/Apricot-Conservation-Project/emoji", package = "emoji" } serde_derive = "1.0.193" serde_json = "1.0.109" strconv = "0.1.0" jemallocator-global = "0.3.2" +[build-dependencies] +emojib = { git = "https://github.com/Apricot-Conservation-Project/emoji", package = "emoji", features = [ + "build", +] } + [profile.release] strip = true lto = "thin" @@ -32,6 +32,8 @@ fn main() -> std::io::Result<()> { fs::create_dir("html")?; } + emojib::load(); + for path in fs::read_dir("html-src")? { process(path.unwrap().path().file_name().unwrap())?; } diff --git a/html-src/masm-bindings.js b/html-src/masm-bindings.js index d53f472..0f7a91c 100644 --- a/html-src/masm-bindings.js +++ b/html-src/masm-bindings.js @@ -1 +1 @@ -let wasm;let cachedUint8Memory0=null;function getUint8Memory0(){if(cachedUint8Memory0===null||cachedUint8Memory0.byteLength===0){cachedUint8Memory0=new Uint8Array(wasm.memory.buffer)}return cachedUint8Memory0}let WASM_VECTOR_LEN=0;function passArray8ToWasm0(arg,malloc){const ptr=malloc(arg.length*1,1)>>>0;getUint8Memory0().set(arg,ptr/1);WASM_VECTOR_LEN=arg.length;return ptr}let cachedInt32Memory0=null;function getInt32Memory0(){if(cachedInt32Memory0===null||cachedInt32Memory0.byteLength===0){cachedInt32Memory0=new Int32Array(wasm.memory.buffer)}return cachedInt32Memory0}function getArrayU8FromWasm0(ptr,len){ptr=ptr>>>0;return getUint8Memory0().subarray(ptr/1,ptr/1+len)}export function render_map_(v){try{const retptr=wasm.__wbindgen_add_to_stack_pointer(-16);const ptr0=passArray8ToWasm0(v,wasm.__wbindgen_export_0);const len0=WASM_VECTOR_LEN;wasm.render_map_(retptr,ptr0,len0);var r0=getInt32Memory0()[retptr/4+0];var r1=getInt32Memory0()[retptr/4+1];var v2=getArrayU8FromWasm0(r0,r1).slice();wasm.__wbindgen_export_1(r0,r1*1,1);return v2}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}export function render_schem_(v){try{const retptr=wasm.__wbindgen_add_to_stack_pointer(-16);const ptr0=passArray8ToWasm0(v,wasm.__wbindgen_export_0);const len0=WASM_VECTOR_LEN;wasm.render_schem_(retptr,ptr0,len0);var r0=getInt32Memory0()[retptr/4+0];var r1=getInt32Memory0()[retptr/4+1];var v2=getArrayU8FromWasm0(r0,r1).slice();wasm.__wbindgen_export_1(r0,r1*1,1);return v2}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}async function __wbg_load(module,imports){if(typeof Response==="function"&&module instanceof Response){if(typeof WebAssembly.instantiateStreaming==="function"){try{return await WebAssembly.instantiateStreaming(module,imports)}catch(e){if(module.headers.get("Content-Type")!="application/wasm"){console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",e)}else{throw e}}}const bytes=await module.arrayBuffer();return await WebAssembly.instantiate(bytes,imports)}else{const instance=await WebAssembly.instantiate(module,imports);if(instance instanceof WebAssembly.Instance){return{instance:instance,module:module}}else{return instance}}}function __wbg_get_imports(){const imports={};imports.wbg={};return imports}function __wbg_init_memory(imports,maybe_memory){}function __wbg_finalize_init(instance,module){wasm=instance.exports;__wbg_init.__wbindgen_wasm_module=module;cachedInt32Memory0=null;cachedUint8Memory0=null;return wasm}function initSync(module){if(wasm!==undefined)return wasm;const imports=__wbg_get_imports();__wbg_init_memory(imports);if(!(module instanceof WebAssembly.Module)){module=new WebAssembly.Module(module)}const instance=new WebAssembly.Instance(module,imports);return __wbg_finalize_init(instance,module)}async function __wbg_init(input){if(wasm!==undefined)return wasm;if(typeof input==="undefined"){input=new URL("masm_bg.wasm",import.meta.url)}const imports=__wbg_get_imports();if(typeof input==="string"||typeof Request==="function"&&input instanceof Request||typeof URL==="function"&&input instanceof URL){input=fetch(input)}__wbg_init_memory(imports);const{instance,module}=await __wbg_load(await input,imports);return __wbg_finalize_init(instance,module)}export{initSync};export default __wbg_init;export function render_map(x){return URL.createObjectURL(new Blob([render_map_(new Uint8Array(x))]))}export function render_schem(x){return URL.createObjectURL(new Blob([render_schem_(new Uint8Array(x))]))} +let wasm;const cachedTextDecoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};if(typeof TextDecoder!=="undefined"){cachedTextDecoder.decode()}let cachedUint8Memory0=null;function getUint8Memory0(){if(cachedUint8Memory0===null||cachedUint8Memory0.byteLength===0){cachedUint8Memory0=new Uint8Array(wasm.memory.buffer)}return cachedUint8Memory0}function getStringFromWasm0(ptr,len){ptr=ptr>>>0;return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr,ptr+len))}const heap=new Array(128).fill(undefined);heap.push(undefined,null,true,false);let heap_next=heap.length;function addHeapObject(obj){if(heap_next===heap.length)heap.push(heap.length+1);const idx=heap_next;heap_next=heap[idx];heap[idx]=obj;return idx}let WASM_VECTOR_LEN=0;function passArray8ToWasm0(arg,malloc){const ptr=malloc(arg.length*1,1)>>>0;getUint8Memory0().set(arg,ptr/1);WASM_VECTOR_LEN=arg.length;return ptr}let cachedInt32Memory0=null;function getInt32Memory0(){if(cachedInt32Memory0===null||cachedInt32Memory0.byteLength===0){cachedInt32Memory0=new Int32Array(wasm.memory.buffer)}return cachedInt32Memory0}let cachedUint32Memory0=null;function getUint32Memory0(){if(cachedUint32Memory0===null||cachedUint32Memory0.byteLength===0){cachedUint32Memory0=new Uint32Array(wasm.memory.buffer)}return cachedUint32Memory0}function getObject(idx){return heap[idx]}function dropObject(idx){if(idx<132)return;heap[idx]=heap_next;heap_next=idx}function takeObject(idx){const ret=getObject(idx);dropObject(idx);return ret}function getArrayJsValueFromWasm0(ptr,len){ptr=ptr>>>0;const mem=getUint32Memory0();const slice=mem.subarray(ptr/4,ptr/4+len);const result=[];for(let i=0;i<slice.length;i++){result.push(takeObject(slice[i]))}return result}export function tags_(t){try{const retptr=wasm.__wbindgen_add_to_stack_pointer(-16);const ptr0=passArray8ToWasm0(t,wasm.__wbindgen_export_0);const len0=WASM_VECTOR_LEN;wasm.tags_(retptr,ptr0,len0);var r0=getInt32Memory0()[retptr/4+0];var r1=getInt32Memory0()[retptr/4+1];var v2=getArrayJsValueFromWasm0(r0,r1).slice();wasm.__wbindgen_export_1(r0,r1*4,4);return v2}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}function getArrayU8FromWasm0(ptr,len){ptr=ptr>>>0;return getUint8Memory0().subarray(ptr/1,ptr/1+len)}export function render_map_(v){try{const retptr=wasm.__wbindgen_add_to_stack_pointer(-16);const ptr0=passArray8ToWasm0(v,wasm.__wbindgen_export_0);const len0=WASM_VECTOR_LEN;wasm.render_map_(retptr,ptr0,len0);var r0=getInt32Memory0()[retptr/4+0];var r1=getInt32Memory0()[retptr/4+1];var v2=getArrayU8FromWasm0(r0,r1).slice();wasm.__wbindgen_export_1(r0,r1*1,1);return v2}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}export function render_schem_(v){try{const retptr=wasm.__wbindgen_add_to_stack_pointer(-16);const ptr0=passArray8ToWasm0(v,wasm.__wbindgen_export_0);const len0=WASM_VECTOR_LEN;wasm.render_schem_(retptr,ptr0,len0);var r0=getInt32Memory0()[retptr/4+0];var r1=getInt32Memory0()[retptr/4+1];var v2=getArrayU8FromWasm0(r0,r1).slice();wasm.__wbindgen_export_1(r0,r1*1,1);return v2}finally{wasm.__wbindgen_add_to_stack_pointer(16)}}async function __wbg_load(module,imports){if(typeof Response==="function"&&module instanceof Response){if(typeof WebAssembly.instantiateStreaming==="function"){try{return await WebAssembly.instantiateStreaming(module,imports)}catch(e){if(module.headers.get("Content-Type")!="application/wasm"){console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",e)}else{throw e}}}const bytes=await module.arrayBuffer();return await WebAssembly.instantiate(bytes,imports)}else{const instance=await WebAssembly.instantiate(module,imports);if(instance instanceof WebAssembly.Instance){return{instance:instance,module:module}}else{return instance}}}function __wbg_get_imports(){const imports={};imports.wbg={};imports.wbg.__wbindgen_string_new=function(arg0,arg1){const ret=getStringFromWasm0(arg0,arg1);return addHeapObject(ret)};return imports}function __wbg_init_memory(imports,maybe_memory){}function __wbg_finalize_init(instance,module){wasm=instance.exports;__wbg_init.__wbindgen_wasm_module=module;cachedInt32Memory0=null;cachedUint32Memory0=null;cachedUint8Memory0=null;return wasm}function initSync(module){if(wasm!==undefined)return wasm;const imports=__wbg_get_imports();__wbg_init_memory(imports);if(!(module instanceof WebAssembly.Module)){module=new WebAssembly.Module(module)}const instance=new WebAssembly.Instance(module,imports);return __wbg_finalize_init(instance,module)}async function __wbg_init(input){if(wasm!==undefined)return wasm;if(typeof input==="undefined"){input=new URL("masm_bg.wasm",import.meta.url)}const imports=__wbg_get_imports();if(typeof input==="string"||typeof Request==="function"&&input instanceof Request||typeof URL==="function"&&input instanceof URL){input=fetch(input)}__wbg_init_memory(imports);const{instance,module}=await __wbg_load(await input,imports);return __wbg_finalize_init(instance,module)}export{initSync};export default __wbg_init;export function render_map(x){return URL.createObjectURL(new Blob([render_map_(new Uint8Array(x))]))}export function render_schem(x){return URL.createObjectURL(new Blob([render_schem_(new Uint8Array(x))]))}export function tags(x){let map={};tags_(new Uint8Array(x)).forEach(tag=>map[tag.split("⬟")[0]]=tag.split("⬟")[1]);return map} diff --git a/html-src/masm.wasm b/html-src/masm.wasm Binary files differindex c49978a..d8b9b53 100644 --- a/html-src/masm.wasm +++ b/html-src/masm.wasm diff --git a/src/alerts.rs b/src/alerts.rs index a16ba0e..3f89cdd 100644 --- a/src/alerts.rs +++ b/src/alerts.rs @@ -1,4 +1,4 @@ -use emoji::named::*; +use crate::emoji::named::*; use regex::Regex; use std::{ sync::{ diff --git a/src/bot/exec.rs b/src/bot/exec.rs index 8528a8c..b727fa0 100644 --- a/src/bot/exec.rs +++ b/src/bot/exec.rs @@ -1,5 +1,5 @@ use super::{Context, Result}; -use emoji::named::*; +use crate::emoji::named::*; use poise::serenity_prelude::*; use std::process::ExitStatus; use tokio::sync::broadcast::{channel, error::TryRecvError as ChannelE}; @@ -41,7 +41,7 @@ pub async fn exec( .arg("-c") .arg(cc) .env("FORCE_COLOR", "1") - .current_dir(env!("HOME")) + .current_dir("/root") .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) .spawn() diff --git a/src/bot/lb.rs b/src/bot/lb.rs index 5d2eea3..244ffbf 100644 --- a/src/bot/lb.rs +++ b/src/bot/lb.rs @@ -32,7 +32,7 @@ pub async fn lb( .unwrap(); static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new("[0-9]: <(.)([0-3])> ([^:]+): ([0-9]+) wins").unwrap()); - c.reply(emoji::mindustry::to_discord(&RE.replace_all( + c.reply(crate::emoji::mindustry::to_discord(&RE.replace_all( &get_nextblock().await[14..], "<$1$2> $3: $4 wins", ))) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index eb56ae8..a39b731 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -11,10 +11,10 @@ mod status; mod trace; mod voting; +use crate::emoji::named::*; use crate::webhook::Webhook; use anyhow::Result; use maps::Maps; -use emoji::named::*; use poise::serenity_prelude::*; use regex::Regex; use serenity::http::Http; diff --git a/src/bot/player.rs b/src/bot/player.rs index 1939542..d5753e7 100644 --- a/src/bot/player.rs +++ b/src/bot/player.rs @@ -95,7 +95,11 @@ pub async fn list(ctx: Context<'_>) -> Result<()> { } else { CreateEmbed::new() .fields(players.into_iter().map(|p| { - let admins = if p.admin { emoji::named::ADMIN } else { "" }; + let admins = if p.admin { + crate::emoji::named::ADMIN + } else { + "" + }; (p.name, admins, true) })) .description("currently online players.") diff --git a/src/bot/rules.rs b/src/bot/rules.rs index ae34acc..a0f2c6f 100644 --- a/src/bot/rules.rs +++ b/src/bot/rules.rs @@ -1,6 +1,6 @@ use super::{repl, send, Context, Result}; use crate::bot::get_nextblock; -use emoji::named::*; +use crate::emoji::named::*; use futures_util::StreamExt; use poise::serenity_prelude::*; use tokio::sync::Mutex; diff --git a/src/bot/trace.rs b/src/bot/trace.rs index 96f4273..e065296 100644 --- a/src/bot/trace.rs +++ b/src/bot/trace.rs @@ -1,6 +1,6 @@ use super::{get_nextblock, Context, SUCCESS}; +use crate::emoji::named::*; use anyhow::Result; -use emoji::named::*; use poise::serenity_prelude::*; use std::net::Ipv4Addr; diff --git a/src/main.rs b/src/main.rs index a05b28c..ca92d73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#![feature(lazy_cell, let_chains, iter_intersperse)] +#![feature(let_chains, iter_intersperse)] #![allow(mixed_script_confusables)] use std::str::FromStr; #[macro_use] @@ -11,7 +11,7 @@ mod webhook; use server::*; use std::net::SocketAddr; - +emojib::the_crate! {} #[tokio::main(flavor = "current_thread")] async fn main() { tokio::spawn(alerts::run()); diff --git a/src/server.rs b/src/server.rs index a823311..0775463 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,7 +1,7 @@ use crate::bot::Bot; use crate::process::Process; use axum::{ - http::header::{CONTENT_ENCODING, CONTENT_TYPE}, + http::header::*, response::{AppendHeaders, Html, IntoResponse}, routing::get, Router, Server as AxumServer, @@ -90,6 +90,7 @@ impl Server { [ (CONTENT_TYPE, "application/wasm"), (CONTENT_ENCODING, "gzip"), + (ACCESS_CONTROL_ALLOW_ORIGIN, "*"), ], include_bytes!("../html-src/masm.wasm"), ) @@ -99,7 +100,10 @@ impl Server { "/masm.js", get(|| async { ( - [(CONTENT_TYPE, "application/javascript")], + [ + (CONTENT_TYPE, "application/javascript"), + (ACCESS_CONTROL_ALLOW_ORIGIN, "*"), + ], include_str!("../html-src/masm-bindings.js"), ) }), diff --git a/src/webhook.rs b/src/webhook.rs index 77da058..d239dc2 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -196,7 +196,7 @@ fn get(line: &str) -> Option<Message> { } pub fn mindustry_to_discord(s: &str) -> String { - strip_colors(&mention(&emoji::mindustry::to_discord(&unify(s)))) + strip_colors(&mention(&crate::emoji::mindustry::to_discord(&unify(s)))) } pub fn unify(s: &str) -> String { |