twilight_command_parser/lib.rs
1//! # twilight-command-parser
2//!
3//! [![codecov badge][]][codecov link] [![discord badge][]][discord link] [![github badge][]][github link] [![license badge][]][license link] ![rust badge]
4//!
5//! **This crate has been deprecated. Please use [Discord interactions] via the
6//! [`twilight-gateway`] or [`twilight-http`] crates.**
7//!
8//! `twilight-command-parser` is a command parser for the [`twilight-rs`]
9//! ecosystem.
10//!
11//! Included is a mutable configuration that allows you to specify the command
12//! names and prefixes. The parser parses out commands matching an available
13//! command and prefix and provides the command arguments to you.
14//!
15//! ### Examples
16//!
17//! A simple parser for a bot with one prefix (`"!"`) and two commands: `"echo"`
18//! and `"ping"`:
19//!
20//! ```rust,no_run
21//! use twilight_command_parser::{Command, CommandParserConfig, Parser};
22//!
23//! let mut config = CommandParserConfig::new();
24//!
25//! config.add_command("echo", false);
26//! config.add_command("ping", false);
27//!
28//! // Add the prefix `"!"`.
29//! // (Use `CommandParserConfig::add_prefixes` to add multiple prefixes)
30//! config.add_prefix("!");
31//!
32//! let parser = Parser::new(config);
33//!
34//! // Now pass a command to the parser
35//! match parser.parse("!echo a message") {
36//! Some(Command { name: "echo", arguments, .. }) => {
37//! let content = arguments.as_str();
38//!
39//! println!("Got an echo request to send `{}`", content);
40//! },
41//! Some(Command { name: "ping", .. }) => {
42//! println!("Got a ping request");
43//! },
44//! // Ignore all other commands.
45//! Some(_) => {},
46//! None => println!("Message didn't match a prefix and command"),
47//! }
48//! ```
49//!
50//! [Discord interactions]: https://discord.com/developers/docs/interactions/application-commands
51//! [codecov badge]: https://img.shields.io/codecov/c/gh/twilight-rs/twilight?logo=codecov&style=for-the-badge&token=E9ERLJL0L2
52//! [codecov link]: https://app.codecov.io/gh/twilight-rs/twilight/
53//! [discord badge]: https://img.shields.io/discord/745809834183753828?color=%237289DA&label=discord%20server&logo=discord&style=for-the-badge
54//! [discord link]: https://discord.gg/7jj8n7D
55//! [github badge]: https://img.shields.io/badge/github-twilight-6f42c1.svg?style=for-the-badge&logo=github
56//! [github link]: https://github.com/twilight-rs/twilight
57//! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin
58//! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md
59//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust
60//! [`twilight-gateway`]: https://crates.io/crates/twilight-gateway
61//! [`twilight-http`]: https://crates.io/crates/twilight-http
62//! [`twilight-rs`]: https://github.com/twilight-rs/twilight
63
64#![deprecated(
65 since = "0.8.1",
66 note = "use interactions via `twilight-http` or `twilight-gateway`"
67)]
68#![deny(
69 clippy::all,
70 clippy::missing_const_for_fn,
71 clippy::pedantic,
72 future_incompatible,
73 missing_docs,
74 nonstandard_style,
75 rust_2018_idioms,
76 unsafe_code,
77 unused,
78 warnings
79)]
80#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]
81
82pub mod config;
83
84mod arguments;
85mod casing;
86mod parser;
87
88pub use self::{
89 arguments::Arguments,
90 config::CommandParserConfig,
91 parser::{Command, Parser},
92};