#discord #discord-api #twilight

twilight-command-parser

Message command parser for the Twilight ecosystem

9 releases

0.2.2 Nov 2, 2020
0.2.1 Oct 31, 2020
0.1.3 Nov 7, 2020
0.1.2 Oct 7, 2020
0.0.0 Aug 30, 2020

#125 in Parser implementations

Download history 11/week @ 2020-08-29 4/week @ 2020-09-05 56/week @ 2020-09-12 26/week @ 2020-09-19 17/week @ 2020-09-26 21/week @ 2020-10-03 96/week @ 2020-10-10 29/week @ 2020-10-17 30/week @ 2020-10-24 56/week @ 2020-10-31 72/week @ 2020-11-07 5/week @ 2020-11-14

115 downloads per month
Used in twilight

ISC license

29KB
543 lines

twilight-command-parser

discord badge github badge license badge rust badge

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

~92KB