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
use super::{Context, Result};
use crate::{return_next, send_ctx};
use convert_case::{Case, Casing};
use futures_util::StreamExt;

const ITEMS: &'static [&'static str] = &[
    "autoUpdate",
    "showConnectMessages",
    "enableVotekick",
    "startCommands",
    "logging",
    "strict",
    "antiSpam",
    "interactRateWindow",
    "interactRateKick",
    "messageRateLimit",
    "messageSpamKick",
    "packetSpamLimit",
    "chatSpamLimit",
    "socketInput",
    "socketInputPort",
    "socketInputAddress",
    "allowCustomClients",
    "whitelist",
    "motd",
    "autosave",
    "autosaveAmount",
    "debug",
    "snapshotInterval",
    "autoPause",
];

async fn complete<'a>(
    _ctx: Context<'_>,
    partial: &'a str,
) -> impl futures::Stream<Item = String> + 'a {
    futures::stream::iter(ITEMS)
        .filter(move |name| futures::future::ready(name.starts_with(partial)))
        .map(|name| name.from_case(Case::Camel).to_case(Case::Lower))
}

#[poise::command(slash_command, category = "Configuration", rename = "config")]
/// change a setting
pub async fn set(
    ctx: Context<'_>,
    #[autocomplete = "complete"]
    #[description = "setting to change"]
    setting: String,
    #[description = "the value"] config: String,
) -> Result<()> {
    let setting = setting.from_case(Case::Lower).to_case(Case::Camel);
    send_ctx!(ctx, "config {setting} {config}")?;
    return_next!(ctx)
}
// TODO: config::list