Commit Graph

549 Commits

Author SHA1 Message Date
Still Hsu
82cfdffc65 Add various optimizations and cleanups (#1114)
* Change all Select(... as ...) to OfType

* Add changes according to 194a8aa427
2018-08-30 17:36:44 -04:00
JustNrik
143fb2808b Update CommandAttribute.cs 2018-08-29 17:07:17 +01:00
JustNrik
c56fff9fe5 Update CommandAttribute.cs 2018-08-29 17:07:17 +01:00
JustNrik
4259b8cb0c Update CommandAttribute.cs
Nullable<T> is not valid for Attributes, this is my suggested fix.
2018-08-29 17:07:17 +01:00
Joe4evr
748e92bcda Allow FromError(Exception) on all IResult types. 2018-08-09 17:39:37 +01:00
Joe4evr
5dad0fa1a1 Minor fixes around OnModuleBuilding (#1116)
* Don't attempt instantiation of an abstract module
* Attempt associating a TypeReader in case one is registered late (ie. OnModuleBuilding)
2018-08-01 10:10:21 -04:00
Casino Boyale
afc3a9d063 Added GetJumpUrl() as an extension method for IMessage (#1102)
* Added GetJumpUrl() as an IMessage extension method

* Removed extra line for consistency

* Moved the namespace from Discord.Commands to Discord

* lint: remove eof newline

* lint: use TextChannel to get GuildID
2018-07-20 20:31:30 -04:00
HelpfulStranger999
4bc06a0a54 Patch lazy default readers not getting replaced (#1083) 2018-07-02 16:29:42 -04:00
HelpfulStranger999
93878e4a90 Refactors an unused parameter in CommandService#Search (#1025) 2018-06-18 15:57:58 -04:00
Hawx
bbbac85c46 Update Dependencies and support NS2.0 builds (#1046)
* Update deps, fix test warnings.

* Support ns2.0

* Fix typo

* Remove ns1.1 support

* Net.Http and Net.Websockets.Client are not needed in ns2.0

* Move to net46 per volt

* Remove ns1.3 constants
2018-05-25 08:14:28 -04:00
Chris Johnston
cee71ef35a Add support for parsing multiple types of quotation marks in commands, Fix #942 (#943)
* Add ability to support different types of quotation marks

* Added normal quotation mark to list of aliases, removed single quote mark

* clean up leftover changes from testing

* change quotation mark parsing to use a map of matching pairs

* remove commented out code

* Fix conventions of the command parser utility functions

* change storage type of alias dictionary to be IReadOnlyDictionary

* revert type of CommandServiceConfig QuotationMarkAliasMap to Dictionary

* minor formatting changes to CommandParser

* remove unnecessary whitespace

* Move aliases outside of CommandInfo class

* copy IReadOnlyDictionary to ImmutableDictionary

* minor syntax changes in CommandServiceConfig

* add newline before namespace for consistency

* newline formatting tweak

* simplification of GetMatch method for CommandParser

* add more quote unicode punctuation pairs

* add check for null value when building ImmutableDictionary

* Move default alias map into a separate source file

* Ensure that the collection passed into command service is not null
2018-05-24 20:07:37 -04:00
Joe4evr
b52af7ae7c Add a dedicated TimeSpan reader so it doesn't suck (#1005)
* Add a dedicated TimeSpan reader so it doesn't suck

* Pass input as lower case
2018-05-24 19:59:32 -04:00
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
Joe4evr
6d3010065f Allow setting IgnoreExtraArgs on an individual basis (#998)
* Allow setting IgnoreExtraArgs on an individual basis

* Remove passing in the flag as a separate parameter

* VS plz

* Push the RunMode setting out to its own attribute, because fox wants consistency.

Bonus: Removes the need for that godawful 'RunMode.Default'.

* Revert previous commit

* Fox doesn't like module-wide switches 😒
2018-04-29 11:10:00 -04:00
Quahu
7457847489 I broke it even more with this PR, lol
Remainder parameters weren't parsed properly.
2018-04-01 00:28:11 +02:00
HelpfulStranger999
c67db88961 Cleaned up and refactored slightly 2018-03-30 15:57:22 -04:00
Christopher F
b918712ad2 Cleanup of #1009 2018-03-30 15:51:28 -04:00
Paulo
6b7c6e9667 Add new overload for AddTypeReader (#1009) 2018-03-30 15:40:43 -04:00
Quahu
7d1f4d1dff Smh, Finitey 2018-03-24 01:22:25 +01:00
Christopher F
b38dca7803 All arguments in ReplyAsync should be optional
To reply with just a rich embed, users have to invoke ReplyAsync with
`ReplyAsync("", embed: embed)`, which seems wasteful, when they only
need to specify the embed.
2018-03-18 15:48:34 -04:00
Christopher F
b70ae41285 AddModule(s)Async should be explicit about IServiceProvider
In f19730e4, AddModule(s)Async was changed so that the IServiceProvider
was optional, both at compile time and runtime. This had the side effect
of meaning that there was no longer a compile-time hint that users would
need to pass an IServiceProvider to AddModulesAsync. I assumed this
would not be an issue - users would recognize the runtime exception here
and self correct - but activity in our Discord support channel would
indicate otherwise.

We now require the user to explicitly opt-out of dependency injection -
they are still free to pass null in place of an IServiceProvider if they
do not intend to use one, and the library will handle this at runtime.
2018-03-18 15:35:10 -04:00
Christopher F
f9ac190e9a Don't create a service scope in CommandService#ExecuteAsync anymore
IServiceProvider does not support scopes by itself - this is a behavior
introduced by Microsoft's DI container. As such, not all DI containers
may support an IScopeFactory the way that Microsoft's DI is expecting
them to.

This also means that our builtin EmptyServiceProvider does not support
scopes - meaning that users who do not use a DI container can not invoke
commands.
2018-03-13 18:23:42 -04:00
Joe4evr
2fd4f5670e Remove support for TokenType.User (#958)
* Set usage of TokenType.User as an error rather than a warning.

* Remove commented sections and #pragma's

Additionally, changes use of ReadMessages to ViewChannel since that Obsolete was also suppressed by the pragma
2018-03-12 13:59:22 -04:00
Joe4evr
170a2e00bd Resolve #936 (#941)
* Resolve #936

* Remember to not search *only* typereaders for primitives 😒
2018-03-08 16:09:34 -05:00
Alex Gravely
4edbd8d4b9 Allow nested ModuleBase classes to be built when declared from non-module classes. (#969)
* Allow modules to be built regardless of their declaring type.

* Need to exclude submodules.
2018-03-04 13:15:00 -05:00
Christopher F
f19730e433 AddModuleAsync/AddModulesAsync should not require an IServiceProvider
If one is not passed, they will default to an EmptyServiceProvider

This resolves issues where since the merging of OnModuleBuilding, users
were effectively forced to use the DI pattern, where before they were
not.

While this isn't necessarily a bad idea, we shouldn't just change this
behavior for no reason (though I assume making the IServiceProvider
argument required was a mistake)
2018-03-03 20:36:06 -05:00
Christopher F
b1eaa44021 Don't attempt to load types with generic parameters as a module
This fixes an issue where custom ModuleBases that contained a generic
parameter would be loaded as a module - only to fail when trying to be
built.

Realistically, ModuleBases _should_ be abstract - but it was still a bug
that we allowed them to be included as a module.
2018-02-26 19:35:43 -05:00
Christopher F
bb8ebc13d2 Add callback method for when a module class has been added (#934)
commit 5b047bf02b4299f34172cac05dc7e4a84ecc108c
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Fri Feb 2 22:22:00 2018 +0100

    [feature/OnModuleAdded] Quickstart fixes (#946)

    * Quickstart: fix minor derp

    * Other overdue fixes

commit bd3e9eee943b9092cc45217b19ff95bae359f888
Author: Christopher F <computerizedtaco@gmail.com>
Date:   Sat Jan 27 16:51:18 2018 -0500

    Resort usings in ModuleBase

commit 8042767579b337fdae7fe48e0a6ea2f007aef440
Author: Christopher F <computerizedtaco@gmail.com>
Date:   Sat Jan 27 16:41:39 2018 -0500

    Clean up removed owned IServiceProvider

commit 30066cb102ffbd65906ead72a377811aa501abba
Author: Christopher F <computerizedtaco@gmail.com>
Date:   Sat Jan 27 16:37:22 2018 -0500

    Remove redundant try-catch around OnModuleBuilding invocation

    If this exception is going to be rethrown, there's no reason to include
    a try-catch.

commit 60c7c31d4476c498a97ae0536ec5792f08efb89b
Author: Christopher F <computerizedtaco@gmail.com>
Date:   Sat Jan 27 16:36:27 2018 -0500

    Include the ModuleBuilder in OnModuleBuilding

    This allows modules hooking into OnModuleBuilding method to mutate
    theirselves at runtime.

commit b6a9ff57860ff3bddbad7ca850fd331529cb8e6e
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 22 13:17:14 2018 +0100

    #DERP

commit f623d19c68c5642a44898a561f77ed82d53fd103
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 22 13:15:31 2018 +0100

    Resolution for #937 because it's literally 4 lines of code

commit 8272c9675b0d63b4100aaf57f5067d635b68f5e6
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 22 11:39:28 2018 +0100

    Re-adjust quickstart

commit e30b9071351b69baa30a93a4851516dca9ea43cf
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 22 11:35:08 2018 +0100

    Undo experimental changes, request IServiceProvider instance everywhere instead

commit ad7e0a46c8709e845dfacdc298a893e22dc11567
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Fri Jan 19 03:40:27 2018 +0100

    Fix quickstart leftover from previous draft

commit e3349ef3d400bb3ad8cb28dd4234d5316a80bcc4
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Fri Jan 19 03:33:46 2018 +0100

    Doc comment on items

commit 81bd9111faaf98a52679daae863ab04dce96e63e
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Fri Jan 19 03:16:44 2018 +0100

    Add comment about the ServiceProviderFactory in the quickstart

commit 72b5e6c8a149d8e989b46351965daa14f8ca318c
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Fri Jan 19 03:10:40 2018 +0100

    Remove superfluous comments, provide simpler alternative for setting the ServiceProvider.

commit 74b17b0e04e2c413397a2e1b66ff814615326205
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Tue Jan 16 18:06:28 2018 +0100

    Experimental change for feedback

commit 7b100e99bb119be190006d1cd8e403776930e401
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 15 23:34:06 2018 +0100

    * Make the service provider parameters required

    * Adjust quickstart guide to reflect changes

commit 7f1b792946ac6b950922b06178aa5cc37d9f4144
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 15 20:04:37 2018 +0100

    I..... missed one.

commit 031b289d80604666dde62619e521af303203d48d
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 15 20:02:20 2018 +0100

    Rename method to more intuitive 'OnModuleBuilding'

commit 9a166ef1d0baecd21e4e5b965e2ac364feddbe2e
Author: Joe4evr <jii.geugten@gmail.com>
Date:   Mon Jan 15 19:09:10 2018 +0100

    Add callback method for when a module class has been added to the CommandService.
2018-02-18 19:16:38 -05:00
Christopher F
97397f3617 Apply consistency to attributes in the commands extension (#928)
* Apply consistency to attributes in the commands extension

This resolves #527.

Not sure if I missed any, putting this up for review.

* Allow preconditions to be used multiple times (for use with groups)
2018-01-08 12:56:31 -05:00
ObsidianMinor
5bbd9bba82 Renamed existing Flatten method to FlattenAsync and added new Flatten method. Also fixed ClientHelper using incorrect guild batch count. (#744) 2018-01-06 22:43:11 -05:00
vim2meta
5f46aef3a7 Ability to ignore unused parameters instead of failing the command. (#915)
* Addition of FailOnTooManyArgs

* Correct name & only pass in bool
2018-01-05 15:02:27 -05:00
Christopher F
e5dfb6c3e5 Fix null channel being passed in RequirePermission preconditions (#886)
* Fix null channel being passed in RequirePermission preconditions

* c#7 pattern matching
2017-11-21 16:33:46 -05:00
Christopher F
8d533930fa Move CommandExecuted invoking up a scope for generic Task commands
Resovles #870
2017-11-10 15:26:58 -05:00
Christopher F
14fbe40cbc Add Async suffix to command-related Tasks (#804)
commit b7fb44a94fb1e75f696f281d6b201eba3f48e864
Author: Hsu Still <341464@gmail.com>
Date:   Sat Sep 2 14:34:18 2017 +0800

    Fix more async naming violation

commit e6912e2d020c69325826dbfa62c07cd1ef2cc45f
Author: Hsu Still <341464@gmail.com>
Date:   Sat Sep 2 14:23:04 2017 +0800

    Fix incorrect null xmldocs string

commit da8d23222d207853375c3512232d1d7fd3629cad
Author: Hsu Still <341464@gmail.com>
Date:   Sat Sep 2 14:17:12 2017 +0800

    Fix CheckPreconditionsAsync

commit 992407407a42fec9087c9ed18e0bf5de30dff82c
Author: Hsu Still <341464@gmail.com>
Date:   Sat Sep 2 14:07:12 2017 +0800

    Add Async suffix to abstract Task methods
2017-10-09 19:45:12 -04:00
Vollrat
71e8b88514 Improve upon Property Summaries in CommandServiceConfig (#839)
* Improve Boolean Property Summaries

Having the `CaseSensitiveCommands` property summary asking a question whenever Intellisense is invoked seems a bit nonessential instead of *properly* explaining what exactly it does. It would be better if instead, it stated it's use to be more comprehensible to the reader.

### Changes

- Edits the summaries of `CaseSensitiveCommands` and `ThrowOnError` to follow a more methodical convention for boolean property summaries (`Determines whether X ...` rather than `Should X be ... ?`).

This is just a small change to improve upon the current documentation, so it shouldn't conflict with anything.

* "DefaultRunMode should also be "Gets or sets blah blah blah" to be consistent."
2017-10-03 20:04:38 -04:00
Christopher F
347c5a0d39 Disable obsolete warnings in files that reference TokenType.User 2017-09-29 17:37:07 -04:00
Christopher F
608bc359ee Removed IChannel#Nsfw, added to ITextChannel 2017-08-29 17:26:36 -04:00
Christopher F
e991715bac Added CommandService.CommandExecuted (#747) 2017-08-29 16:50:32 -04:00
Izumemori
9c81ab9fe4 changed NameAttribute to work for parameter (#765) 2017-08-29 16:45:30 -04:00
Alex Gravely
cb0ff7817d Add NullableTypeReader (#785)
* Add NullableTypeReader.

Primitives now also load a NullableTypeReader<T> and any value types that get a typereader added will also have a NullableTypeReader<T> added for it.

* Remove unnecessary null check.

* Added docstrings.
2017-08-29 16:38:11 -04:00
RogueException
dfcb4b39fb Allow duplicate RequireBotPermissionAttribute 2017-08-17 02:41:42 -03:00
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