Fix issue with default handler execution; Bump version
This commit is contained in:
parent
ff2a734a91
commit
34694e8507
|
@ -19,15 +19,21 @@ abstract class CommandEntity {
|
|||
CommandEntity? get parent;
|
||||
|
||||
/// A list of valid command names
|
||||
List<String> get commandNames => [this.name, ...this.aliases];
|
||||
List<String> get commandNames => [if (this.name.isNotEmpty) this.name, ...this.aliases];
|
||||
|
||||
/// RegEx matching the fully qualified command name with its parents and all aliases
|
||||
String getFullCommandMatch() {
|
||||
var parentMatch = "";
|
||||
|
||||
if (parent != null) {
|
||||
parentMatch = "${parent!.getFullCommandMatch()} ";
|
||||
}
|
||||
return '$parentMatch(${this.commandNames.join('|')})';
|
||||
|
||||
if (this.commandNames.isNotEmpty) {
|
||||
parentMatch += "(${this.commandNames.join('|')})";
|
||||
}
|
||||
|
||||
return parentMatch;
|
||||
}
|
||||
|
||||
/// Returns true if provided String [str] is entity name or alias
|
||||
|
@ -66,7 +72,7 @@ class CommandGroup extends CommandEntity with ICommandRegistrable {
|
|||
/// Registers default command handler which will be executed if no subcommand is matched to message content
|
||||
void registerDefaultCommand(CommandHandlerFunction commandHandler,
|
||||
{PassHandlerFunction? beforeHandler, AfterHandlerFunction? afterHandler}) {
|
||||
this.defaultHandler = BasicCommandHandler(this.name, commandHandler, beforeHandler: beforeHandler, afterHandler: afterHandler, parent: this);
|
||||
this.defaultHandler = BasicCommandHandler("", commandHandler, beforeHandler: beforeHandler, afterHandler: afterHandler, parent: this);
|
||||
}
|
||||
|
||||
/// Registers subcommand
|
||||
|
|
|
@ -105,7 +105,7 @@ class Commander with ICommandRegistrable {
|
|||
// Example: (?<finalCommand>(quote|q) (remove|rm))
|
||||
// This will match the command `quote remove`, `q remove`, `quote rm` and `q rm`
|
||||
|
||||
final match = RegExp("(?<finalCommand>${matchingCommand.getFullCommandMatch()})").firstMatch(event.message.content);
|
||||
final match = RegExp("(?<finalCommand>${matchingCommand.getFullCommandMatch().trim()})").firstMatch(event.message.content);
|
||||
|
||||
final finalCommand = match?.namedGroup("finalCommand");
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: nyxx_commander
|
||||
version: 1.1.0-dev.4
|
||||
version: 1.1.0-dev.5
|
||||
description: A Discord library for Dart.
|
||||
homepage: https://github.com/l7ssha/nyxx
|
||||
repository: https://github.com/l7ssha/nyxx
|
||||
|
|
|
@ -22,6 +22,10 @@ void main() {
|
|||
|
||||
if (event.message.content == "Test 11") {
|
||||
await event.message.delete();
|
||||
}
|
||||
|
||||
if (event.message.content == "Test 12") {
|
||||
await event.message.delete();
|
||||
|
||||
await event.message.channel.getFromCache()?.sendMessage(content: "Commander tests completed sucessfuly!");
|
||||
exit(0);
|
||||
|
@ -44,6 +48,9 @@ void main() {
|
|||
|
||||
final msg4 = await channel.sendMessage(content: "test>test4");
|
||||
msg4.delete(); // ignore: unawaited_futures
|
||||
|
||||
final msg5 = await channel.sendMessage(content: "test>test4 test5");
|
||||
msg5.delete(); // ignore: unawaited_futures
|
||||
});
|
||||
|
||||
Commander(bot, prefix: "test>", beforeCommandHandler: (context) async {
|
||||
|
@ -68,7 +75,9 @@ void main() {
|
|||
await context.message.delete();
|
||||
})
|
||||
..registerCommandGroup(CommandGroup(name: "test4")
|
||||
..registerDefaultCommand((context, message) async => await context.channel.sendMessage(content: "Test 11")));
|
||||
..registerDefaultCommand((context, message) => context.channel.sendMessage(content: "Test 11"))
|
||||
..registerSubCommand("test5", (context, message) => context.channel.sendMessage(content: "Test 12"))
|
||||
);
|
||||
|
||||
Timer(const Duration(seconds: 60), () {
|
||||
print("Timed out waiting for messages");
|
||||
|
|
Loading…
Reference in a new issue