Commit Graph

458 Commits

Author SHA1 Message Date
Finite Reality
d2afb06942 Make the "cannot be loaded" warning fire correctly (#729)
Why am I such a bad programmer? Maybe I'm just bad with git. Maybe I'm
just bad in general. Maybe I should resign from programming.
2017-07-05 20:19:09 -03:00
Joe4evr
b6dcc9e8d8 Add back the case for ParameterPreconditions (#735) 2017-07-05 20:13:49 -03:00
Finite Reality
7597cf5baa Fix CalculateScore throwing on missing parameters (#727)
* Fix CalculateScore throwing on missing parameters

* Bump to version 1.0.1
2017-07-05 20:09:38 -03:00
RogueException
14dfc48df3 Style cleanup 2017-06-29 19:44:32 -03: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
Finite Reality
b96748f9c3 Allow arbitrary attributes to be added to commands (#458)
* Allow arbitrary attributes to be added to commands

I still don't approve adding type info back into commands, so
I decided to use this solution for allowing arbitrary attributes to be
added to commands.

Add attributes property to ParameterBuilder

Add Attributes properties to info types

* Why on earth git

* Add using for system so that Attribute can be used
2017-06-29 18:30:26 -03:00
Finite Reality
032aba9129 Update commands with C#7 features (#689)
* C#7 features in commands, CommandInfo in ModuleBase

* Update TypeReaders with C#7 features and IServiceProvider

* Add best-choice command selection to CommandService

* Normalize type reader scores correctly

* Fix logic error and rebase onto dev

* Change GetMethod for SetMethod in ReflectionUtils

Should be checking against setters, not getters

* Ensure args/params scores do not overwhelm Priority

* Remove possibility of NaNs
2017-06-29 17:43:55 -03:00
Christopher F
3b8434cdc4 Merge pull request #715 from Joe4evr/patch-2
PreconditionGroup quick fix
2017-06-28 13:02:58 -04:00
Joe4evr
cc390f03de Fix the off-chance that someone has a property without a getter 2017-06-24 02:56:57 +02:00
Joe4evr
34917a35de In my defense, it was 2:40 AM 2017-06-24 02:50:30 +02:00
Joe4evr
444868b22d Fix attempting to inject into static properties 2017-06-24 02:39:15 +02:00
Joe4evr
36ed2b49f0 PreconditionGroup quick fix
It didn't make much sense
2017-06-23 20:46:59 +02:00
Finite Reality
cce572c600 Include names in command builder exceptions (#663) 2017-06-23 11:28:30 -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
FiniteReality
0550006d56 Change wording of permission preconditions
Also fix an issue where RequireBotPermission may throw if used in a
non-guild channel which required guild permissions.
2017-06-17 15:10:35 +01:00
RogueException
285a0e5817 Updated deps, cleaned csprojs 2017-05-09 20:51:00 -03:00
FiniteReality
1e888cde24 Fix CheckPreconditions giving empty service provider
Parameter preconditions were always getting the empty service provider,
even when a custom one was provided in ExecuteAsync, which means that
preconditions which use services cannot work properly.
2017-05-08 22:15:47 +01:00
FiniteReality
00895b1227 Remove CommandService.BuildServiceCollection
💥
2017-05-06 18:25:44 +01:00
Finite Reality
112a434424 Allow for case-insensitive HasStringPrefix (#644)
This was 👍'd in the dev chat, I forgot to make a PR for it (whoops!)
2017-05-06 02:39:46 -03:00
RogueException
870dc50a68 Fixed RequireNsfwAttribute definition 2017-05-04 13:15:51 -03:00
RogueException
ba1982a3f9 Replaced DependencyMap with ServiceCollection and IServiceProvider (#625) 2017-05-04 12:52:26 -03:00
Christopher F
7f1fc286cf Add IChannel.Nsfw, RequireNsfw precondition (#633)
* Add IChannel.Nsfw, RequireNsfw precondition

* Refactored IChannel.Nsfw to IsNsfw, removed NsfwUtils

Per pull-request feedback

* proper nsfw channel check
2017-05-04 12:49:32 -03:00
Bond-009
cb4f6e37f6 Overloaded AddModuleAsync with Type (#581)
* Overloaded AddModuleAsync with Type

* Overloaded RemoveModuleAsync with Type

* Use expression-bodied method for consistency
2017-04-29 04:42:47 -03:00
Confruggy
3365bbb043 Fixes ChannelTypeReader (#630) 2017-04-28 11:49:59 -03:00
Confruggy
4ca273dd4a Fixes RoleTypeReader (#631) 2017-04-28 11:49:50 -03:00
RogueException
f8b9acc4a1 Use implicit package references (#626) 2017-04-26 10:03:23 -03:00
Christopher F
6000b15c4d C#7 TODOs 2017-04-23 15:13:31 -04:00
RogueException
1c6eebf875 Ensure command completes before cleaning up 2017-04-22 08:04:33 -03:00
RogueException
aca8def0cb ModuleBase should map to ICommandContext 2017-04-08 18:38:58 -03:00
RogueException
a6469e9021 Add support for void-returning commands 2017-04-07 05:48:33 -03:00
RogueException
bceb72dd92 Typo 2017-04-06 20:57:46 -03:00
RogueException
17ba8fe4d0 Better handle the primary alias. 2017-04-06 20:50:48 -03:00
RogueException
33cd1a6c9f Scan base types during DI injection 2017-04-06 20:29:42 -03:00
RogueException
14f0535a43 Improved typereader not found message 2017-04-05 23:53:20 -03:00
RogueException
b5d817f171 Cleaned up csprojs, added support for tag builds. 2017-04-01 11:11:09 -03:00
Christopher F
2b4a1249f4 Restrict DependencyMap#Get to reference types
It's impossible to add non-reference types to the map, so why allow pulling them out of it.
2017-03-25 17:08:45 -04:00
RogueException
bbd45a6f4b Fixed CommandException 2017-03-25 11:19:31 -03:00
Finite Reality
ca18eb0eb4 Replace TryGetValue call with TryRemove call (#586)
Resolves #584
2017-03-23 11:03:06 -03:00
RogueException
0c8d643519 Minor doc/exception edits 2017-03-18 23:22:39 -03:00
RogueException
3fb21e06c2 Fixed RunMode.Sync running Async. Added ThrowOnError option. 2017-03-18 21:38:28 -03:00
RogueException
ba07484fe9 Removed Mixed RunMode 2017-03-18 12:23:51 -03:00
RogueException
a2b12520b2 Added CommandService logging 2017-03-18 12:14:14 -03:00
Finite Reality
2160e5dac8 Improve parameter precondition type safety (#532)
* Improve parameter precondition type safety

Also removes some terrible code which was left over when I first
implemented parameter preconditions. I don't know why that was there.

With this commit, parameter preconditions should be much safer as they
use generic methods instead of janky casting of objects.

* Remove generic CheckPreconditions method
2017-03-18 09:55:53 -03:00
Finite Reality
3ddb01a5a2 Fix order of iteration in ExecuteAsync (#534) 2017-03-18 08:55:56 -03:00
RogueException
11ba30c6fa Cleaned up DepMap type checks 2017-03-18 08:48:18 -03:00
RogueException
334ceacdbf Merge pull request #546 from khionu/dev
Fix detection of IDependencyMap impl
2017-03-18 08:42:57 -03:00
RogueException
683541ba24 Added RequireOwner support for User tokens 2017-03-18 08:38:24 -03:00
Flamanis
94ea80b45e Modified User#Discrim check to properly check guild 2017-03-08 00:51:10 -06:00
Flamanis
dc2230de86 guildUsers instantiated to empty collection, removed added nullchecks
A null conditional operator was required at line 70 to avoid a nullref.
2017-03-08 00:48:18 -06:00
Flamanis
c643ceaa47 Add space after if and before ( 2017-03-07 18:41:31 -06:00