html terminal
| -rw-r--r-- | src/bot/lb.rs | 41 | ||||
| -rw-r--r-- | src/bot/mod.rs | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/bot/lb.rs b/src/bot/lb.rs new file mode 100644 index 0000000..5d2eea3 --- /dev/null +++ b/src/bot/lb.rs @@ -0,0 +1,41 @@ +use super::{get_nextblock, send_ctx, Context}; +use anyhow::Result; +use regex::Regex; +use std::sync::LazyLock; + +#[derive(poise::ChoiceParameter)] +pub enum Team { + #[name = "survivors"] + #[name_localized("it", "sopravvissuto")] + #[name_localized("vi", "người sống sót")] + Survivor, + #[name = "infected"] + #[name_localized("it", "infetto")] + #[name_localized("vi", "bị lây nhiễm")] + Infected, +} + +#[poise::command(slash_command, category = "Info")] +/// show leaderboard! +pub async fn lb( + c: Context<'_>, + #[description = "the team to get the leaderboard of"] team: Team, +) -> Result<()> { + send_ctx!( + c, + "lb {}", + match team { + Team::Survivor => "surv", + Team::Infected => "inf", + } + ) + .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( + &get_nextblock().await[14..], + "<$1$2> $3: $4 wins", + ))) + .await?; + Ok(()) +} diff --git a/src/bot/mod.rs b/src/bot/mod.rs index b207868..2713f42 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -2,6 +2,7 @@ mod admin; mod bans; mod config; mod js; +mod lb; pub mod maps; mod player; mod rules; @@ -211,6 +212,7 @@ impl Bot { rules::set(), rules::del(), trace::trace(), + lb::lb(), start(), end(), help(), |