html terminal
| -rw-r--r-- | src/bot/admin.rs | 3 | ||||
| -rw-r--r-- | src/bot/bans.rs | 3 | ||||
| -rw-r--r-- | src/bot/config.rs | 3 | ||||
| -rw-r--r-- | src/bot/js.rs | 3 | ||||
| -rw-r--r-- | src/bot/maps.rs | 3 | ||||
| -rw-r--r-- | src/bot/mod.rs | 13 | ||||
| -rw-r--r-- | src/bot/player.rs | 9 | ||||
| -rw-r--r-- | src/bot/rules.rs | 22 | ||||
| -rw-r--r-- | src/bot/status.rs | 15 | ||||
| -rw-r--r-- | src/main.rs | 1 |
10 files changed, 32 insertions, 43 deletions
diff --git a/src/bot/admin.rs b/src/bot/admin.rs index a1972a5..00558da 100644 --- a/src/bot/admin.rs +++ b/src/bot/admin.rs @@ -1,6 +1,5 @@ -use super::{Context, Result}; +use super::{return_next, send_ctx, Context, Result}; use crate::bot::player::{self, Players}; -use crate::{return_next, send_ctx}; #[poise::command( slash_command, diff --git a/src/bot/bans.rs b/src/bot/bans.rs index 0938972..a5c9015 100644 --- a/src/bot/bans.rs +++ b/src/bot/bans.rs @@ -1,6 +1,5 @@ -use super::{Context, Result}; +use super::{return_next, send_ctx, Context, Result}; use crate::bot::player::{self, Players}; -use crate::{return_next, send_ctx}; #[poise::command( slash_command, diff --git a/src/bot/config.rs b/src/bot/config.rs index e39b2c9..b4d015f 100644 --- a/src/bot/config.rs +++ b/src/bot/config.rs @@ -1,5 +1,4 @@ -use super::{Context, Result}; -use crate::{return_next, send_ctx}; +use super::{return_next, send_ctx, Context, Result}; use convert_case::{Case, Casing}; use futures_util::StreamExt; diff --git a/src/bot/js.rs b/src/bot/js.rs index bd11c18..c882c77 100644 --- a/src/bot/js.rs +++ b/src/bot/js.rs @@ -1,5 +1,4 @@ -use super::{Context, Result}; -use crate::{return_next, send_ctx}; +use super::{return_next, send_ctx, Context, Result}; use minify_js::{Session, TopLevelMode}; use regex::Regex; use std::sync::LazyLock; diff --git a/src/bot/maps.rs b/src/bot/maps.rs index 94321db..0ce0b82 100644 --- a/src/bot/maps.rs +++ b/src/bot/maps.rs @@ -1,5 +1,4 @@ -use super::{get_nextblock, strip_colors, Context, Result, SUCCESS}; -use crate::send; +use super::{get_nextblock, send, strip_colors, Context, Result, SUCCESS}; use futures_util::StreamExt; use mindus::*; use oxipng::*; diff --git a/src/bot/mod.rs b/src/bot/mod.rs index ed87005..592859f 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -34,19 +34,26 @@ pub struct Data { static SKIPPING: OnceLock<(Arc<AtomicU8>, broadcast::Sender<String>)> = OnceLock::new(); -#[macro_export] macro_rules! send { ($e:expr, $fmt:literal $(, $args:expr)* $(,)?) => { $e.send(format!($fmt $(, $args)*)) }; } +use send; +macro_rules! repl { + ($c:expr, $fmt:literal $(, $args:expr)* $(,)?) => { + poise::say_reply($c, format!($fmt $(, $args)*)).await + } +} +use repl; -#[macro_export] macro_rules! send_ctx { ($e:expr,$fmt:literal $(, $args:expr)* $(,)?) => { $e.data().stdin.send(format!($fmt $(, $args)*)) }; } +use send_ctx; + pub const SOURCE_GUILD: u64 = 1003092764919091282; pub mod emojis { use super::SOURCE_GUILD; @@ -330,7 +337,6 @@ async fn raw( Ok(()) } -#[macro_export] macro_rules! return_next { ($ctx:expr) => {{ let line = $crate::bot::get_nextblock().await; @@ -339,6 +345,7 @@ macro_rules! return_next { return Ok(()); }}; } +use return_next; async fn get_nextblock() -> String { let (skip_count, skip_send) = SKIPPING.get().unwrap(); diff --git a/src/bot/player.rs b/src/bot/player.rs index 9cfa9ba..1939542 100644 --- a/src/bot/player.rs +++ b/src/bot/player.rs @@ -1,5 +1,4 @@ -use super::{get_nextblock, strip_colors, Context, FAIL, SUCCESS}; -use crate::send; +use super::{get_nextblock, send, strip_colors, Context, FAIL, SUCCESS}; use anyhow::Result; use futures_util::StreamExt; use itertools::Itertools; @@ -96,11 +95,7 @@ pub async fn list(ctx: Context<'_>) -> Result<()> { } else { CreateEmbed::new() .fields(players.into_iter().map(|p| { - let admins = if p.admin { - "<:admin:1182128872435749005>" - } else { - "" - }; + let admins = if p.admin { 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 ba9874c..ddf11ee 100644 --- a/src/bot/rules.rs +++ b/src/bot/rules.rs @@ -1,5 +1,6 @@ -use super::{Context, Result}; +use super::{repl, send, Context, Result}; use crate::bot::get_nextblock; +use emoji::named::*; use futures_util::StreamExt; use poise::serenity_prelude::*; use tokio::sync::Mutex; @@ -183,7 +184,7 @@ rules!( // ); pub async fn commit(stdin: &broadcast::Sender<String>) { - crate::send!( + send!( stdin, "rules {}", serde_json::to_string(&*rules(stdin).await).unwrap() @@ -195,7 +196,7 @@ pub async fn rules(stdin: &broadcast::Sender<String>) -> tokio::sync::MutexGuard static RULES: OnceCell<Mutex<Rules>> = OnceCell::const_new(); RULES .get_or_init(|| async move { - crate::send!(stdin, "rules").unwrap(); + send!(stdin, "rules").unwrap(); let res = get_nextblock().await; Mutex::new(deser_hjson::from_str(&res).unwrap()) }) @@ -251,7 +252,7 @@ pub async fn set( ) -> Result<()> { rules(&ctx.data().stdin).await.set(&rule, &value)?; commit(&ctx.data().stdin).await; - poise::say_reply(ctx, "<:ok:1182120559916625971>").await?; + repl!(ctx, "{OK}")?; Ok(()) } @@ -270,15 +271,10 @@ pub async fn del( rule: String, ) -> Result<()> { match rules(&ctx.data().stdin).await.delete(&rule) { - Some(true) => poise::say_reply(ctx, "<:ok:1182120559916625971>"), - Some(false) => poise::say_reply( - ctx, - "<:warning:1182119952048726066> rule existed, but already none", - ), - - None => poise::say_reply(ctx, "<:cancel:1182128899166064720> invalid rule!"), - } - .await?; + Some(true) => repl!(ctx, "{OK} removed"), + Some(false) => repl!(ctx, "{WARNING} rule existed, but already none"), + None => repl!(ctx, "{CANCEL} invalid rule!"), + }?; commit(&ctx.data().stdin).await; Ok(()) diff --git a/src/bot/status.rs b/src/bot/status.rs index d0792ec..308ae42 100644 --- a/src/bot/status.rs +++ b/src/bot/status.rs @@ -1,5 +1,5 @@ +use super::send_ctx; use super::{get_nextblock, Context, FAIL, SUCCESS}; -use crate::send_ctx; use anyhow::Result; use itertools::Itertools; use poise::serenity_prelude::*; @@ -77,17 +77,14 @@ pub async fn command(ctx: Context<'_>) -> Result<()> { }; poise::send_reply( ctx, - poise::CreateReply::default().embed(if pcount > 0 { + poise::CreateReply::default().embed( CreateEmbed::new() .title("server online") - .field("tps", format!("{tps}"), true) + .field("tps", tps.to_string(), true) .field("memory use", humanize_bytes(Size::Mb(f64::from(mem))), true) - .field("players", format!("{pcount}"), true) - .color(SUCCESS) - .footer(CreateEmbedFooter::new("see /players for player list")) - } else { - CreateEmbed::new().title("no players online").color(FAIL) - }), + .field("players", pcount.to_string(), true) + .color(SUCCESS), + ), ) .await?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 34ee551..8b08b11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use std::str::FromStr; #[macro_use] mod logging; -#[macro_use] mod bot; mod process; mod server; |