html terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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(crate::emoji::mindustry::to_discord(&RE.replace_all(
        &get_nextblock().await[14..],
        "<$1$2> $3: $4 wins",
    )))
    .await?;
    Ok(())
}