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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
#![warn(missing_docs)] //! A command framework for Serenity that allows commands to be registered both as a traditional text command and a discord slash command /// Everything related to parsing and representing arguments. pub mod argument; /// Everything related to commands. pub mod commands; /// Everything related to the framework metadata and handlers. pub mod framework; /// Default permission checks and PermissionCheck type pub mod permissions; /// The settings for the framework. pub mod settings; #[cfg(test)] mod tests; /// Macro to create commands. /// /// # Command macro format /// ```text /// command!{ /// name, /// description, /// function, /// [ /// required Type name = function | "description" {choices: map} [children] /// ] /// } /// ``` /// /// ## Argument Types /// - Integer (u32) /// - Str (String) /// - Boolean (bool) /// - User (UserId) /// - Channel (ChannelId) /// - Role (RoleId) /// - SubCommand /// - SubCommandGroup /// /// ### Type Specific Fields /// The fields `children`, `choices`, and `function` are all only valid for some of the argument types.<br> /// Only SubCommand and SubCommandGroup arguments can have `function` or `children`.<br> /// And only Integer and Str can have `choices`. /// /// ## SubCommands /// SubCommands allow you to have multiple paths to your command. /// /// By including a function when defining a SubCommand that function will be run when the SubCommand is given. /// /// SubCommands can also have child arguments and their functions will only be run when all required arguments are present. /// /// ## Examples /// `stats get|set [user]` /// ``` /// # use slashy_macros::*; /// # use slashy::commands::*; /// # use slashy::framework::*; /// # #[subcommand] /// # pub async fn points(_ctx: &CommandContext) -> CommandResult {Ok(())} /// # #[subcommand] /// # pub async fn credits(_ctx: &CommandContext) -> CommandResult {Ok(())} /// # #[subcommand] /// # pub async fn set_stats(_ctx: &CommandContext) -> CommandResult {Ok(())} /// command!{ /// stats, /// "get or set a user's stats", /// [ /// optional SubCommandGroup get | "get info about stats" [ /// optional SubCommand points = points | "get a user's points" [ /// optional User user | "the user whose points you want to get" /// ], /// optional SubCommand credits = credits | "get a user's credits" [ /// optional User user | "the user whose points you want to get" /// ] /// ], /// optional SubCommand set = set_stats | "set a user's stats" /// ] /// } /// ``` /// /// `add a b` /// ``` /// # use slashy_macros::*; /// # use slashy::commands::*; /// # use slashy::framework::*; /// # #[subcommand] /// # pub async fn add(_ctx: &CommandContext) -> CommandResult {Ok(())} /// command!{ /// add, /// "adds two numbers", /// add, /// [ /// required Integer a | "the first number to add", /// required Integer b | "the second number to add" /// ] /// } /// ``` /// /// `grid size` with choices of 1, 5, and 12 /// ``` /// # use slashy_macros::*; /// # use slashy::commands::*; /// # use slashy::framework::*; /// # #[subcommand] /// # pub async fn grid(_ctx: &CommandContext) -> CommandResult {Ok(())} /// command!{ /// grid, /// "prints a grid", /// grid, /// [ /// required Integer size | "the size of the grid" {"small": 1, "medium": 5, "large": 12}, /// ] /// } /// ``` /// /// You have to follow all the rules of normal discord slash commands.<br> /// This includes not allowing required arguments after optional ones. /// /// ```compile_fail /// # use slashy_macros::*; /// # use slashy::commands::*; /// # use slashy::framework::*; /// # #[subcommand] /// # pub async fn test(_ctx: &CommandContext) -> CommandResult {Ok(())} /// command!{ /// test, /// "testing", /// test /// [ /// required Integer test | "the first argument", /// optional String test2 | "the second argument", /// required String test3 | "the third argument" // Fails to compile /// ] /// } ///``` pub use slashy_macros::command; /// Denotes a function that is used in a command. /// /// Functions must take a [CommandContext](crate::framework::CommandContext) and return a [CommandResult](crate::commands::CommandResult). pub use slashy_macros::subcommand; /// Denotes a function that is used to check permissions before running a command. pub use slashy_macros::permissions_check;