Created
January 30, 2026 17:56
-
-
Save dgxo/258d9b7e0c5c74a8dc935b53d3fbb661 to your computer and use it in GitHub Desktop.
Type definitions for Cmdr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --!strict | |
| -- Luau types for Cmdr - put in ReplicatedStorage | |
| -- I personally put my hooks and permissions module in ReplicatedStorage.Cmdr with this | |
| export type TypeDefinition = { | |
| Name: string?, | |
| Prefixes: string?, | |
| DisplayName: string?, | |
| Default: ((player: Player) -> string)?, | |
| Listable: boolean?, | |
| ArgumentOperatorAliases: any?, | |
| Transform: ((text: string, player: Player) -> any)?, | |
| Validate: ((value: any) -> (boolean, string?))?, | |
| ValidateOnce: ((value: any) -> (boolean, string?))?, | |
| Autocomplete: ((value: any) -> ({ string }, { IsPartial: boolean? }?)?)?, | |
| Parse: (value: any) -> any, | |
| } | |
| export type ArgumentDefinition = { | |
| Type: string | TypeDefinition, | |
| Name: string, | |
| Description: string?, | |
| Optional: boolean?, | |
| Default: any?, | |
| } | |
| export type CommandContext = { | |
| Dispatcher: Dispatcher, | |
| Cmdr: Cmdr | CmdrClient, | |
| Name: string, | |
| RawText: string, | |
| Object: CommandDefinition, | |
| Group: string?, | |
| State: { [any]: any }, | |
| Aliases: { string }?, | |
| Alias: string, | |
| ArgumentDefinitions: { ArgumentDefinition | (CommandContext) -> ArgumentDefinition }?, | |
| RawArguments: { string }, | |
| Arguments: { any }, | |
| Data: any?, | |
| Response: string?, | |
| Guards: any?, | |
| Executor: Player, | |
| GetData: (self: CommandContext) -> any, | |
| GetStore: (self: CommandContext, name: string) -> { [any]: any }, | |
| SendEvent: (self: CommandContext, player: Player, eventName: string, ...any) -> (), | |
| BroadcastEvent: (self: CommandContext, eventName: string, ...any) -> (), | |
| Reply: (self: CommandContext, text: string, color: Color3?) -> string, | |
| HasImplementation: (self: CommandContext) -> boolean, | |
| Parse: (self: CommandContext, allowIncompleteArguments: boolean?) -> (boolean, string?), | |
| Validate: (self: CommandContext, isTopLevel: boolean?) -> (boolean, string?), | |
| Run: (self: CommandContext) -> string?, | |
| } | |
| export type CommandDefinition = { | |
| Name: string, | |
| Aliases: { string }?, | |
| Description: string?, | |
| Group: string?, | |
| Args: { ArgumentDefinition | (context: CommandContext) -> ArgumentDefinition }?, | |
| Data: ((context: CommandContext, ...any) -> any)?, | |
| ClientRun: ((context: CommandContext, ...any) -> string | nil)?, | |
| Run: ((context: CommandContext, ...any) -> string?)?, | |
| AutoExec: { string }?, | |
| Guards: { (context: CommandContext, ...any) -> string? }?, | |
| } | |
| export type HookType = "BeforeRun" | "AfterRun" | |
| export type Hook = { | |
| callback: (context: CommandContext, ...any) -> string?, | |
| priority: number, | |
| } | |
| export type Dispatcher = { | |
| Cmdr: Cmdr | CmdrClient, | |
| Registry: Registry, | |
| Evaluate: ( | |
| self: Dispatcher, | |
| text: string, | |
| executor: Player, | |
| allowIncompleteArguments: boolean?, | |
| data: any? | |
| ) -> (CommandContext | false, string?), | |
| EvaluateAndRun: ( | |
| self: Dispatcher, | |
| text: string, | |
| executor: Player?, | |
| options: { | |
| Data: any?, | |
| IsHuman: boolean?, | |
| }? | |
| ) -> string, | |
| Send: (self: Dispatcher, text: string, data: any?) -> string, | |
| Run: (self: Dispatcher, ...string) -> string, | |
| RunGuards: (self: Dispatcher, commandContext: CommandContext, ...any) -> string?, | |
| RunHooks: (self: Dispatcher, hookName: string, commandContext: CommandContext, ...any) -> string?, | |
| PushHistory: (self: Dispatcher, text: string) -> (), | |
| GetHistory: (self: Dispatcher) -> { string }, | |
| } | |
| export type Registry = { | |
| TypeMethods: { [string]: true }, | |
| CommandMethods: { [string]: true }, | |
| CommandArgProps: { [string]: true }, | |
| Types: { [string]: TypeDefinition }, | |
| TypeAliases: { [string]: string }, | |
| Commands: { [string]: CommandDefinition }, | |
| CommandsArray: { CommandDefinition }, | |
| Cmdr: Cmdr | CmdrClient, | |
| Hooks: { [HookType]: { Hook } }, | |
| Stores: { [string]: { [any]: any } }, | |
| AutoExecBuffer: { { string } }, | |
| AutoExecFlushConnection: RBXScriptConnection?, | |
| RegisterType: (self: Registry, name: string, typeObject: TypeDefinition) -> (), | |
| RegisterTypePrefix: (self: Registry, name: string, union: string) -> (), | |
| RegisterTypeAlias: (self: Registry, name: string, alias: string) -> (), | |
| RegisterTypesIn: (self: Registry, container: Instance) -> (), | |
| RegisterHooksIn: (self: Registry, container: Instance) -> (), | |
| RegisterCommandObject: (self: Registry, commandObject: CommandDefinition) -> (), | |
| RegisterCommand: ( | |
| self: Registry, | |
| commandScript: ModuleScript, | |
| commandServerScript: ModuleScript?, | |
| filter: ((commandDefinition: any) -> boolean)? | |
| ) -> (), | |
| RegisterCommandsIn: ( | |
| self: Registry, | |
| container: Instance, | |
| filter: ((commandDefinition: any) -> boolean)? | |
| ) -> (), | |
| RegisterDefaultCommands: (self: Registry, arrayOrFunc: ({ string } | ((commandDefinition: any) -> boolean))?) -> (), | |
| GetCommand: (self: Registry, name: string) -> CommandDefinition?, | |
| GetCommands: (self: Registry) -> { CommandDefinition }, | |
| GetCommandNames: (self: Registry) -> { string }, | |
| GetCommandsAsStrings: (self: Registry) -> { string }, | |
| GetTypeNames: (self: Registry) -> { string }, | |
| GetType: (self: Registry, name: string) -> TypeDefinition?, | |
| GetTypeName: (self: Registry, name: string) -> string | TypeDefinition, | |
| RegisterHook: ( | |
| self: Registry, | |
| hookName: string, | |
| callback: (context: CommandContext, ...any) -> string?, | |
| priority: number? | |
| ) -> (), | |
| AddHook: ( | |
| self: Registry, | |
| hookName: string, | |
| callback: (context: CommandContext, ...any) -> string?, | |
| priority: number? | |
| ) -> (), | |
| GetStore: (self: Registry, name: string) -> { [any]: any }, | |
| FlushAutoExecBufferDeferred: (self: Registry) -> (), | |
| FlushAutoExecBuffer: (self: Registry) -> (), | |
| } | |
| export type Cmdr = Registry & { | |
| ReplicatedRoot: Folder, | |
| RemoteFunction: RemoteFunction, | |
| RemoteEvent: RemoteEvent, | |
| Util: Util, | |
| DefaultCommandsFolder: Folder, | |
| Registry: Registry, | |
| Dispatcher: Dispatcher, | |
| } | |
| export type CmdrClient = Dispatcher & { | |
| ReplicatedRoot: Folder, | |
| RemoteFunction: RemoteFunction, | |
| RemoteEvent: RemoteEvent, | |
| ActivationKeys: { [Enum.KeyCode]: true }, | |
| Enabled: boolean, | |
| MashToEnable: boolean, | |
| ActivationUnlocksMouse: boolean, | |
| HideOnLostFocus: boolean, | |
| PlaceName: string, | |
| Util: Util, | |
| Events: { [string]: (...any) -> () }, | |
| Registry: Registry, | |
| Dispatcher: Dispatcher, | |
| SetActivationKeys: (self: CmdrClient, keys: { Enum.KeyCode }) -> (), | |
| SetPlaceName: (self: CmdrClient, name: string) -> (), | |
| SetEnabled: (self: CmdrClient, enabled: boolean) -> (), | |
| SetActivationUnlocksMouse: (self: CmdrClient, enabled: boolean) -> (), | |
| Show: (self: CmdrClient) -> (), | |
| Hide: (self: CmdrClient) -> (), | |
| Toggle: (self: CmdrClient) -> (), | |
| SetMashToEnable: (self: CmdrClient, enabled: boolean) -> (), | |
| SetHideOnLostFocus: (self: CmdrClient, enabled: boolean) -> (), | |
| HandleEvent: (self: CmdrClient, name: string, callback: (...any) -> ()) -> (), | |
| } | |
| export type Util = { | |
| MakeDictionary: (array: { any }) -> { [any]: true }, | |
| DictionaryKeys: (dict: { [any]: any }) -> { any }, | |
| MakeFuzzyFinder: (setOrContainer: any) -> (text: string, returnFirst: boolean?, matchStart: boolean?) -> any, | |
| GetNames: (instances: any) -> { string }, | |
| SplitStringSimple: (input: string, sep: string?) -> { string }, | |
| ParseEscapeSequences: (text: string) -> string, | |
| EncodeEscapedOperator: (text: string, op: string) -> string, | |
| EncodeEscapedOperators: (text: string) -> string, | |
| SplitString: (text: string, max: number?) -> { string }, | |
| MashExcessArguments: (arguments: { string }, max: number) -> { string }, | |
| TrimString: (str: string) -> string, | |
| GetTextSize: (text: string, label: TextLabel, size: Vector2?) -> Vector2, | |
| MakeEnumType: (name: string, values: any) -> TypeDefinition, | |
| ParsePrefixedUnionType: (typeValue: string, rawValue: string) -> (string?, string?, string?), | |
| MakeListableType: (type: TypeDefinition, override: any?) -> TypeDefinition, | |
| RunCommandString: (dispatcher: Dispatcher, commandString: string) -> string?, | |
| RunEmbeddedCommands: (dispatcher: Dispatcher, str: string) -> string, | |
| SubstituteArgs: (str: string, replace: any) -> string, | |
| MakeAliasCommand: (name: string, commandString: string) -> CommandDefinition, | |
| MakeSequenceType: (options: any) -> TypeDefinition, | |
| SplitPrioritizedDelimeter: (text: string, delimiters: { string }) -> { string }?, | |
| Map: (array: { any }, callback: (value: any, index: number) -> any) -> { any }, | |
| Each: (callback: (value: any) -> any, ...any) -> ...any, | |
| EmulateTabstops: (text: string, tabWidth: number) -> string, | |
| Mutex: () -> () -> () -> (), | |
| } | |
| return {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --!strict | |
| -- ^ with strict mode there might be more warnings, switch to nonstrict foro a more relaxed typechecker | |
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
| local CmdrTypes = require(ReplicatedStorage.Cmdr.CmdrTypes) -- update path if needed | |
| local version = "v1.12.0" | |
| return { | |
| Name = "version", | |
| Args = {}, | |
| Description = "Shows the current version of Cmdr", | |
| Group = "DefaultDebug", | |
| Run = function() | |
| return ("Cmdr Version %s"):format(version) | |
| end, | |
| } :: CmdrTypes.CommandDefinition |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment