Commit Graph

134 Commits

Author SHA1 Message Date
caf3d17d4a Rework entire cog system and partially document it and extensions. 2019-02-23 04:10:10 -05:00
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
e1c94a3b1c Do None instead of falsy checks on Command attributes 2019-01-28 22:22:44 -05:00
dc8aa7c35b Change Greedy behaviour slightly during conversion errors.
Make Greedy swallow conversion errors and return the default if there
are no convertible args
2019-01-28 21:57:29 -05:00
Xua
016963500b [commands] Add support for IDs in the role related checks.
This affects:

* commands.has_role
* commands.has_any_role
* commands.bot_has_role
* commands.bot_has_any_role
2018-11-24 23:02:47 -05:00
5a585ebf20 Add channel category cooldown bucket type 2018-11-24 22:51:18 -05:00
efb4ff850e [lint] Fix import order
Reorder imports to be consistenly grouped by standard library, third
party library, and local modules in that order thoughout the library.
2018-11-24 22:17:58 -05:00
51d626eabe [lint] Remove redundant paranthesis
Remove redundant parenthisis around await expressions.  Left over from
f25091ef.
2018-11-24 22:17:58 -05:00
fa46b07db1 [lint] Rename exception variables to exc
Use the more explicit (and common) exc instead of e as the variable
holding the exception in except handlers.
2018-11-24 22:17:57 -05:00
4ae8e81660 [lint] Remove redundant exception variables
Use bare raise statement when reraising the exception that occured, and
remove unused exception variables.  Also remove a pointless exception
handler in discord.opus.
2018-11-24 22:17:57 -05:00
a71b3b5fa0 [lint] Limit unneccessarily broad except clauses
Add exception qualifier(s) to bare except clauses swallowing exceptions.
2018-11-24 22:17:57 -05:00
814b03f5a8 [commands] Add commands.Greedy converter and documentation.
This allows for greedy "consume until you can't" behaviour similar to
typing.Optional but for lists.
2018-09-24 03:56:32 -04:00
00a445310b [commands] Allow for backtracking parsing with typing.Optional
Original code by zephyrkul.

This new parsing mode allows for backtracking in case of failure
when a typing.Union[..., NoneType] or a typing.Optional[...] is used.
This means that if a type would fail to parse, the view is undo'd to
a previous state, passing the default parameter to the callback, and
then continuing on the next parameter as if nothing had happened.
2018-09-23 06:12:26 -04:00
8ef509883a [commands] Properly parse bool when inside a typing.Union 2018-09-20 23:58:34 -04:00
9af0e54cd3 Correct ClientException message raised in invocation hooks.
For when the hooks are not coroutines.
2018-09-20 23:43:07 -04:00
a4d1599ce9 Change docstrings to raw-strings 2018-09-14 22:55:27 -04:00
52e8c06aed Fix typo in core.Command docstring 2018-08-24 06:24:04 +12:00
fdc71695dc [commands] Use eval instead of get_type_hints to resolve typehints
The previous usage of `typing.get_type_hints` caused issues as it would
incorrectly decide to convert annotations into their equivalent
`typing` form -- which is not what we want to happen here.

Due to some use-cases about how setting `Command.callback` work and
the amount of moving parts that have changed due to this patch, it is
probably better to refactor the way it is set so users can have this
use-case handled transparently for them.
2018-08-22 23:16:52 -04:00
ef89d3aa22 Add support for converters working with PEP-563 2018-08-22 21:53:47 -04:00
c8b49d37be [lint] Fix incorrect and inconsistent whitespace
Adjust whitespace to be consistent with the rest of the library.
2018-08-22 21:43:53 -04:00
119c5a0618 [lint] Remove unused variables
Left over from various refactoring and rewrites.
2018-08-22 21:43:51 -04:00
00a14a46f3 [commands] Added BucketType.members for cooldowns 2018-08-22 21:06:08 -04:00
8d3b2d0b70 [commands] Fix broken handling of keyword only parameters.
Had a missing `param` argument in the new `do_conversion` code.
2018-07-21 02:52:45 -04:00
69ca675ca0 [commands] Fix typing.Union converters for 3.7
Guido please don't break this
2018-07-20 18:01:48 -04:00
da5776a358 [commands] Make ConversionError have the original error as an attribute 2018-07-20 05:54:51 -04:00
92dde9aef9 [commands] Add support for typing.Union as a converter 2018-07-20 05:51:43 -04:00
2321ae8d97 [commands] raise ConversionError on Converter error
This assumes that a Converter class raising non-CommandError
is a programmer error. Makes this type of error easier to
disambiguate from a generic BadArgument.
2018-07-20 04:14:20 -04:00
bf9ca405e3 Fix case insensitive command removal 2018-06-21 07:44:00 -04:00
f25091efe1 Drop support for Python 3.4 and make minimum version 3.5.2. 2018-06-10 18:10:00 -04:00
871a262ee3 [commands] Add ability to have case insensitive commands.
This is powered by a dict-like class for the people who want to opt-in
to the performance downgrade for usability for majority English
speaking users.

Since it is slower than the regular dict due to the excessive calls to
str.lower along with the possibilities of gotchas for other languages
outside of English, this is kept as False for the default case.
2018-03-06 00:37:12 -05:00
Eli
ad7506050c [commands] Allow builtin unbound method converters 2018-02-10 22:07:44 -08:00
3112e1c17e Add intersphinx 2018-01-06 17:23:59 -05:00
3a8b97ffb0 [commands] Document that can_run can raise. 2017-12-29 06:00:25 -05:00
e61ac8e60f [commands] Forbid passing a string to aliases in Command.
Fixes #974
2017-12-29 01:42:45 -05:00
1bb7b6ff2d [commands] Make CooldownMapping.get_bucket take Message instead.
Requiring a full blown Context might be a bit overkill considering
we only use a single attribute from it.
2017-10-08 07:52:56 -04:00
bae6f80327 [commands] Split Cooldown state processing to two different functions.
This allows us to check if we are rate limited without
creating a new cool-down window for the command.
2017-10-03 03:57:06 -04:00
10696a275b [commands] Have (bot_)has_permissions provide better failure responses 2017-08-30 23:20:59 -04:00
a7f846b37f [commands] Fix Command.root_parent not properly working. 2017-07-19 05:14:23 -04:00
bcaee518a1 [commands] Remove support for pass_context=False in Command. 2017-07-18 17:58:38 -04:00
ad20e3066e [commands] Add parameter that failed in fall-back BadArgument error. 2017-06-26 18:13:46 -04:00
3618f51f97 [commands] Ensure that Context.command is the command in Command.can_run
Previously, Context.command was not guaranteed to be the actual command
being checked if it can run. This could be troublesome when
implementing help commands or when using the default help command.

This new change allows at least for the guarantee that Context.command
to be technically correct in Command.can_run.
2017-06-21 02:30:24 -04:00
7d001ef46e [commands] Try to use the proper name when conversion fails. 2017-06-17 21:16:10 -04:00
5e6491c3fe [commands] Allow inline advanced converters via classmethods.
That way you don't need to have, e.g. Foo and FooConverter and can
do it inline via Foo instead.
2017-06-01 03:32:18 -04:00
f588876587 Use Python3Lexer instead of PythonLexer for pygments. 2017-05-22 07:21:23 -04:00
b81fbb5a7f [commands] Add Context.reinvoke and Command.root_parent
Context.reinvoke would be the new way to bypass checks and cooldowns.
However, with its addition comes a change in the invocation order of
checks, callbacks, and cooldowns. While previously cooldowns would
trigger after command argument parsing, the new behaviour parses
cooldowns before command argument parsing.

The implication of this change is that Context.args and Context.kwargs
will no longer be filled properly.
2017-05-19 21:33:39 -04:00
c3e39cd722 [commands] Fix Context.command_failed from being incorrect.
When used, it would be set to False after the invoke was done. Ideally
it should report to False during invoke but True during any error
case.
2017-05-18 20:48:38 -04:00
c1130d2879 [commands] Update check examples to work with rewrite. 2017-05-15 02:52:20 -04:00
b44bba6ee6 First pass at documentation reform. 2017-05-12 20:14:34 -04:00
d7478425ca [commands] Converter.convert is always a coroutine.
Along with this change comes with the removal of Converter.prepare and
adding two arguments to Converter.convert, the context and the argument.

I suppose an added benefit is that you don't have to do attribute
access since it's a local variable.
2017-05-10 21:30:41 -04:00
a2c9cefac9 [commands] Re-order error handler arguments.
They now have Context as the first argument to be consistent with other
context-passing functions.
2017-05-10 17:49:42 -04:00