97 Commits

Author SHA1 Message Date
Rapptz
a7f846b37f [commands] Fix Command.root_parent not properly working. 2017-07-19 05:14:23 -04:00
Rapptz
bcaee518a1 [commands] Remove support for pass_context=False in Command. 2017-07-18 17:58:38 -04:00
Rapptz
ad20e3066e [commands] Add parameter that failed in fall-back BadArgument error. 2017-06-26 18:13:46 -04:00
Rapptz
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
Rapptz
7d001ef46e [commands] Try to use the proper name when conversion fails. 2017-06-17 21:16:10 -04:00
Rapptz
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
Rapptz
f588876587 Use Python3Lexer instead of PythonLexer for pygments. 2017-05-22 07:21:23 -04:00
Rapptz
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
Rapptz
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
Rapptz
c1130d2879 [commands] Update check examples to work with rewrite. 2017-05-15 02:52:20 -04:00
Rapptz
b44bba6ee6 First pass at documentation reform. 2017-05-12 20:14:34 -04:00
Rapptz
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
Rapptz
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
Rapptz
c20ba51e28 [commands] Export is_nsfw check. 2017-05-05 20:21:28 -04:00
Rapptz
c8937ed2aa [commands] Add is_nsfw check. 2017-05-01 22:36:22 -04:00
Rapptz
b6ac856868 [commands] Allow loading cogs from folders.
Internally, instead of using module objects just use the `__module__`
attribute which is the same thing. From preliminary testing this seems
to work fine with both regular one-file-per-cog approaches and the
folder cog approach.

Fixes #126.
2017-04-21 18:57:28 -04:00
Rapptz
5c5e7ae1d6 [commands] Add is_owner check and Bot.is_owner. 2017-03-27 06:55:21 -04:00
Rapptz
afb64fb5e3 [commands] Remove Command.no_pm for commands.guild_only check.
This is a breaking change. The original purpose of no_pm has been
mainly a legacy aspect. They came from a time before checks were a
generalised concept and were never removed. A check is the proper way
to do its behaviour.
2017-03-26 21:41:34 -04:00
Rapptz
9885a946e1 More robust cleanup for Client.run.
This should prevent asyncio.CancelledError from being propagated more
and suppressed "Task was destroyed but was pending!" warnings when
doing graceful closes outside of using a KeyboardInterrupt.

To make clean up a bit more robust, also add signal handlers
for POSIX systems.
2017-03-24 20:27:30 -04:00
Rapptz
31a7093433 [commands] Fix minor spacing issue in Command.signature 2017-03-21 15:36:52 -04:00
Rapptz
3087600c8d [commands] Add Command.signature
This replaces HelpFormatter.get_command_signature for the most part.
2017-03-21 00:46:13 -04:00
Rapptz
fe588a4d52 [commands] Change GroupMixin.commands to all_commands
This is a breaking change as GroupMixin.commands now returns a set
of unique Command objects.
2017-03-21 00:46:12 -04:00
Rapptz
6166cbc2e7 [commands] Add commands.clean_content converter. 2017-02-13 22:15:39 -05:00
Rapptz
e10cae5dbc [commands] Allow converters to be instantiated.
This allows for you to create converters that can have varying
behaviour using the converter's __init__ instead of having to do a
meta-class based approach to get around the fact that __init__ is part
of the interface.

To make up for the lack of __init__, a new method Converter.prepare was
added to do the work that __init__ used to do.
2017-02-13 21:05:25 -05:00
Rapptz
bf11bb4b4f [commands] Add cog local error handlers via __error. 2017-02-12 15:48:18 -05:00
Rapptz
7bc3750c27 [commands] Add param attribute to MissingRequiredArgument
This should allow easier querying on what argument is missing.

Fixes #470.
2017-02-12 13:53:49 -05:00
Rapptz
47ef657fbd Implement async checks. Fixes #380. 2017-02-12 12:13:23 -05:00
Michael Van Buren
84dfd7b3e3 [commands] Add Command.usage argument to override argument display. 2017-02-10 03:35:25 -05:00
Rapptz
f8d19ae7ba [commands] Better support for retrieving children commands.
* GroupMixin.get_command now supports fully qualified names
* Add GroupMixin.walk_commands to get an iterator of all commands.
2017-02-06 21:04:33 -05:00
Rapptz
1c49374210 [commands] Implement before and after invoke command hooks.
Fixes #464.
2017-01-27 18:53:21 -05:00
Rapptz
12c1cd9b14 [commands] Add cog local checks via __local_check 2017-01-26 05:49:24 -05:00
Rapptz
ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
Rapptz
ea72d5e63d [commands] Guarantee that local error handler is called before generic. 2017-01-15 21:55:50 -05:00
Rapptz
695b62ccd3 [commands] Make Command a descriptor for #426. 2017-01-13 20:34:00 -05:00
Rapptz
3f06cf9e81 [commands] Don't use removed is_private attribute in core decorators. 2017-01-03 20:17:58 -05:00
Rapptz
20ddc9f14f [commands] Remove send_ utility functions. 2017-01-03 09:52:04 -05:00
Rapptz
406984af2e [commands] First pass in making commands ext work again. 2017-01-03 09:52:03 -05:00
Rapptz
d1d54a468a Rename Server to Guild everywhere. 2017-01-03 09:51:54 -05:00
Rapptz
b8909ae389 [commands] Properly propagate CommandError derived exceptions.
If a command or a group raised a CommandError derived exception it
would be wrapped into CommandInvokeError. This fixes this case so it
raises the original exception instead.
2016-12-17 14:44:36 -05:00
Rapptz
b0509a6910 [commands] Cooldowns don't trigger due to user usage error.
Fixes #325
2016-09-08 07:13:22 -04:00
Dan Hess
b7ffbca0c7 [commands] Added a method to reset command cooldown. 2016-09-08 07:02:33 -04:00
Rapptz
1a186c5a55 [commands] Fix cooldown decorator to work regardless of order. 2016-07-22 18:37:23 -04:00
Rapptz
cd0de57d13 [commands] Implement a command cooldown system.
The way the command cooldown works is using a windowed way of doing it.
That is, if we have a cooldown of 2 commands every 30 seconds then if we
do a single command, we have 30 seconds to do the second command or else
we will get rate limited. This more or less matches the common
expectations on how cooldowns should be.

These cooldowns can be bucketed up to a single dimension of depth for
a per-user, per-guild, or per-channel basis. Of course, a global bucket
is also provided. These cannot be mixed, e.g. no per-channel per-user
cooldowns.

When a command cooldown is triggered, the error handlers will receive a
an exception of type CommandOnCooldown with proper information regarding
the cooldown such as retry_after and the bucket information itself.
2016-07-22 18:05:38 -04:00
Rapptz
1500001b04 [commands] Fix error in converters in a private message context.
I was referencing a member function that did not actually exist. So I
ported it over to a free function that could be used.
2016-07-02 23:39:29 -04:00
Rapptz
4d71b3fe7d [commands] Do not lower-case the function name for default command names
There are some badlets out there that apparently violate PEP-8.
2016-07-01 22:12:57 -04:00
Rapptz
a2b053a517 [commands] Make GroupMixin.remove_command return None.
This is for cases where the command has been removed already. This will
make the function have a somewhat no exception guarantee.
2016-06-30 15:15:49 -04:00
Rapptz
6556392a9c [commands] Fix error where consume rest would not work.
I didn't end up refactoring this piece of work out.
2016-06-23 20:17:19 -04:00
Rapptz
629c24339b [commands] Fix bug that made functions stop working as converters. 2016-06-23 18:36:41 -04:00
Rapptz
e64eb08c92 [commands] Port special cased discord converters to commands.Converter 2016-06-22 20:05:37 -04:00
Rapptz
880ca3162e [commands] Add commands.Converter base for converts with context.
This allows users to implement converters that work similar to the ones
special cased by the `discord` classes.
2016-06-22 19:06:25 -04:00