Commit Graph

15 Commits

Author SHA1 Message Date
Joe4evr
660fec0cbc Expose the internal entity type readers (#986)
* Expose the internal entity type readers

* Add BestMatch property to TypeReaderResult for easily accessing the parsed object
2018-04-29 11:24:24 -04:00
Finite Reality
74f6a4b392 Allow commands to return a Task<RuntimeResult> (#466)
* Allow commands to return a Task<RuntimeResult>

This allows bot developers to centralize command result logic by
using result data whether the command as successful or not.

Example usage:
```csharp
var _result = await Commands.ExecuteAsync(context, argPos);
if (_result is RuntimeResult result)
{
    await message.Channel.SendMessageAsync(result.Reason);
}
else if (!_result.IsSuccess)
{
    // Previous error handling
}
```

The RuntimeResult class can be subclassed too, for example:
```csharp
var _result = await Commands.ExecuteAsync(context, argPos);
if (_result is MySubclassedResult result)
{
    var builder = new EmbedBuilder();
    for (var pair in result.Data)
    {
        builder.AddField(pair.Key, pair.Value, true);
    }
    await message.Channel.SendMessageAsync("", embed: builder);
}
else if (_result is RuntimeResult result)
{
    await message.Channel.SendMessageAsync(result.Reason);
}
else if (!_result.IsSuccess)
{
    // Previous error handling
}
```

* Make RuntimeResult's ctor protected

* Make RuntimeResult abstract

It never really made sense to have it instantiable in the first place,
frankly.
2017-06-29 19:21:05 -03:00
Joe4evr
4a9c8168a9 Add grouping of preconditions to allow for flexible precondition logic. (#672)
* Add grouping of preconditions to allow for flexible precondition logic.

* Fix checking Module Preconditions twice (and none of the command's own)

* Fix command preconditions group 0 looping over every other precondition anyway #whoopsies

* Use custom message when a non-zero Precondition Group fails.

* Fix doc comment rendering.

* Refactor loops into local function

* Considering a new result type

* Switch to IReadOnlyCollection<T> and fix compiler errors

* Revert PreconditionResult -> IResult in return types - Change PreconditionResult to a class that PreconditionGroupResult inherits.

* Feedback on property name.

* Change grouping type int -> string

* Explicitly use an ordinal StringComparer

* Full stops on error messages

* Remove some sillyness.

* Remove unneeded using.
2017-06-23 11:28:22 -03:00
Aaron Scherer
858af5e8bb Typo 2017-02-04 05:48:48 -08:00
RogueException
5663e47db6 Added command separator char, improved passing search results to parser 2016-12-18 17:48:33 -04:00
RogueException
635819b89f Reduced command module lifetime to a single command execution. Removed ModuleAttribute. 2016-10-10 20:27:16 -03:00
RogueException
8aa1050b93 Cleaned up usings 2016-10-04 09:01:57 -03:00
RogueException
f6d8659a2e Removed ParamList null checks 2016-08-21 21:47:32 -03:00
RogueException
99e9c36a69 Fixed nullrefs in command parsing 2016-08-21 11:07:32 -03:00
RogueException
324664917d Added new parameter scoring, support multiple matches 2016-08-21 11:03:50 -03:00
RogueException
e452aa9662 Cleaned up Command Result structs 2016-08-09 17:53:08 -03:00
Finite Reality
0e920da21f Complete Preconditions implementation 2016-08-03 17:21:38 +01:00
RogueException
7bb890cbfe Added command groups, fixed several bugs 2016-06-27 06:56:24 -03:00
RogueException
bfea0ef0a2 Added ordered user mentions, fixed role and channel mention resolving 2016-06-26 19:06:10 -03:00
RogueException
f59b6b9004 Implemented command type readers, parser and service. 2016-06-26 03:35:40 -03:00