convert property
override
The function called to perform the conversion.
view
is a view on the current argument string. For text commands, this will contain the
entire content of the message. For Slash Commands, this will contain the content provided by
the user for the current argument.
This function should not throw if parsing fails, it should instead return null
to indicate
failure. A BadInputException will then be added to CommandsPlugin.onCommandError where it
can be handled appropriately.
Implementation
@override
FutureOr<T?> Function(StringView view, ContextData context) get convert => (view, context) async {
StringView? used;
T? ret = await converters.fold(Future.value(null), (previousValue, element) async {
if (await previousValue != null) {
return await previousValue;
}
used = view.copy();
return await element.convert(used!, context);
});
if (used != null) {
view.history
..clear()
..addAll(used!.history);
view.index = used!.index;
}
return ret;
};