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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use super::{return_next, send_ctx, Context, Result};
use crate::bot::player::{self, Players};

#[poise::command(
    slash_command,
    category = "Control",
    rename = "ban",
    required_permissions = "ADMINISTRATOR",
    default_member_permissions = "ADMINISTRATOR"
)]
/// ban a ingame player by uuid and ip
pub async fn add(
    ctx: Context<'_>,
    #[description = "player to ban"]
    #[autocomplete = "player::autocomplete"]
    player: String,
) -> Result<()> {
    let _ = ctx.defer().await;
    let player = Players::find(&ctx.data().stdin, player)
        .await
        .unwrap()
        .unwrap();
    send_ctx!(ctx, "ban ip {}", player.ip)?;
    send_ctx!(ctx, "ban id {}", player.uuid)?;
    ctx.say(format!("banned {}", player.name)).await?;
    Ok(())
}

#[poise::command(
    slash_command,
    category = "Control",
    required_permissions = "ADMINISTRATOR",
    default_member_permissions = "ADMINISTRATOR"
)]
/// kick somebody off the server
pub async fn kick(
    ctx: Context<'_>,
    #[description = "player to kick"]
    #[autocomplete = "player::autocomplete"]
    player: String,
) -> Result<()> {
    let _ = ctx.defer().await;
    let player = Players::find(&ctx.data().stdin, player)
        .await
        .unwrap()
        .unwrap();
    send_ctx!(ctx, "kick {}", player.uuid)?; // FIXME
    ctx.say(format!("kicked {}", player.name)).await?;
    Ok(())
}

#[poise::command(
    slash_command,
    category = "Control",
    rename = "ban_raw",
    required_permissions = "ADMINISTRATOR",
    default_member_permissions = "ADMINISTRATOR"
)]
/// ban a player by uuid and/or ip
pub async fn add_raw(
    ctx: Context<'_>,
    #[description = "uuid of player to ban"] uuid: Option<String>,
    #[description = "ip address of player to ban"] ip: Option<String>,
) -> Result<()> {
    let _ = ctx.defer().await;
    if uuid.is_none() && ip.is_none() {
        anyhow::bail!("what are you banning? yourself?")
    }
    if let Some(uuid) = uuid {
        send_ctx!(ctx, "ban id {}", uuid)?;
    }
    if let Some(ip) = ip {
        send_ctx!(ctx, "ban ip {}", ip)?;
    }
    return_next!(ctx)
}

#[poise::command(
    slash_command,
    category = "Control",
    rename = "unban",
    default_member_permissions = "ADMINISTRATOR",
    required_permissions = "ADMINISTRATOR"
)]
/// unban a player by uuid or ip
pub async fn remove(
    ctx: Context<'_>,
    #[description = "Player id/ip"]
    #[rename = "ip_or_id"]
    player: String,
) -> Result<()> {
    let _ = ctx.defer().await;
    send_ctx!(ctx, "unban {}", player)?;
    return_next!(ctx)
}

// TODO: listbans