nyxx/nyxx.commander/lib/src/utils.dart

31 lines
812 B
Dart
Raw Normal View History

part of nyxx_commander;
2020-06-11 19:46:57 +02:00
// TODO: FIX. I think that is just awful but is does its job
extension _CommandMatcher on Iterable<CommandEntity> {
CommandEntity? _findMatchingCommand(Iterable<String> messageParts) {
for (final entity in this) {
if(entity is CommandGroup && entity.name == "") {
final e = entity._commandEntities._findMatchingCommand(messageParts);
2020-06-11 19:46:57 +02:00
if(e != null) {
return e;
2020-06-11 19:46:57 +02:00
}
}
if(entity is CommandGroup && entity.isEntityName(messageParts.first)) {
final e = entity._commandEntities._findMatchingCommand(messageParts.skip(1));
2020-06-11 19:46:57 +02:00
if(e != null) {
return e;
2020-06-11 19:46:57 +02:00
}
}
2020-06-11 19:46:57 +02:00
if(entity is CommandHandler && entity.isEntityName(messageParts.first)) {
return entity;
2020-06-11 19:46:57 +02:00
}
}
2020-06-11 19:46:57 +02:00
return null;
}
2021-02-09 01:37:01 +01:00
}