#discord #twilight #discord-api #command-arguments #config-parser #name

twilight-command-parser

Message command parser for the Twilight ecosystem

20 releases (9 breaking)

0.9.0 Jan 23, 2022
0.8.1 Dec 27, 2021
0.7.0 Oct 21, 2021
0.6.0 Jul 31, 2021
0.2.2 Nov 2, 2020

#17 in #twilight

Download history 1/week @ 2024-02-18 21/week @ 2024-02-25 252/week @ 2024-03-31

252 downloads per month

ISC license

32KB
561 lines

twilight-command-parser

codecov badge discord badge github badge license badge rust badge

This crate has been deprecated. Please use Discord interactions via the twilight-gateway or twilight-http crates.

twilight-command-parser is a command parser for the twilight-rs ecosystem.

Included is a mutable configuration that allows you to specify the command names and prefixes. The parser parses out commands matching an available command and prefix and provides the command arguments to you.

Examples

A simple parser for a bot with one prefix ("!") and two commands: "echo" and "ping":

use twilight_command_parser::{Command, CommandParserConfig, Parser};

let mut config = CommandParserConfig::new();

config.add_command("echo", false);
config.add_command("ping", false);

// Add the prefix `"!"`.
// (Use `CommandParserConfig::add_prefixes` to add multiple prefixes)
config.add_prefix("!");

let parser = Parser::new(config);

// Now pass a command to the parser
match parser.parse("!echo a message") {
    Some(Command { name: "echo", arguments, .. }) => {
        let content = arguments.as_str();

        println!("Got an echo request to send `{}`", content);
    },
    Some(Command { name: "ping", .. }) => {
        println!("Got a ping request");
    },
    // Ignore all other commands.
    Some(_) => {},
    None => println!("Message didn't match a prefix and command"),
}

Dependencies

~95KB