Commit Graph

864 Commits

Author SHA1 Message Date
00e30f3106 [commands] Shield against dictionary resize in Bot.close 2016-12-17 21:18:48 -05:00
fc1a7183a0 [commands] Unload all cogs when gracefully exiting bot. 2016-12-17 14:47:29 -05:00
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
6d88024f0f [commands] Add special extension function 'teardown' for clean-up.
This is to support people who want to clean up some external resource
that the extension is maintaining outside of a cog, where __unload
should be used instead.

The callable is the antipode of 'setup' and takes the same sole
parameter, the bot, after all commands, events, and cogs have been
unloaded.

Fixes #405.
2016-12-17 14:15:11 -05:00
bafaf72c89 [commands] Unload all extensions when gracefully closing bot. 2016-12-17 14:15:10 -05:00
b1117262da [commands] Run global checks in help formatter.
Help formatter was not checking global bot-level checks, resulting in
showing commands a user did not have permission for with
show_check_failure disabled.
2016-12-16 14:39:25 -05:00
6f2603c049 [commands] Remove slots on Context.
This is to allow people to set temporary local variables by injecting
them directly into the context via some decorator or some other
mechanism. Contexts are not kept alive long enough to warrant being
slotted.
2016-11-22 19:57:19 -05:00
25c262461e [commands] Fix mistake in Paginator error message. 2016-10-03 13:27:02 +02:00
8f0d16629f [commands] Fix Paginator still allowing lines which are too long. 2016-10-03 00:32:12 -04:00
7c0be1cade [commands] Raise exception if Paginator gets a line that is too big.
Fixes #340
2016-09-26 23:26:26 -04:00
967d43c35b [commands] Allow coroutine functions in Bot.command_prefix 2016-09-17 15:01:56 -04:00
152b3a1125 [commands] Default converters now take in IDs to match against. 2016-09-09 06:53:22 -04:00
b0509a6910 [commands] Cooldowns don't trigger due to user usage error.
Fixes #325
2016-09-08 07:13:22 -04:00
b7ffbca0c7 [commands] Added a method to reset command cooldown. 2016-09-08 07:02:33 -04:00
1e9251cfef [commands] Delete module when it does not have a setup function. 2016-08-10 15:11:45 -04:00
a55e1241a7 [commands] Add missing inspect import in converter.py 2016-08-04 21:39:44 -04:00
c72c23278d [commands] Add custom emoji converter. 2016-07-31 22:39:45 -07:00
3ec9b7fb97 [commands] Make HelpFormatter ignore hidden commands for max_width. 2016-07-30 13:27:41 -04:00
1a186c5a55 [commands] Fix cooldown decorator to work regardless of order. 2016-07-22 18:37:23 -04:00
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
5010e7dc55 [commands] Add UserInputError into the exception hierarchy.
This is for exceptions that are inherently based on user errors and not
permission based. e.g. passing incorrect number of arguments, too many
arguments, or an invalid argument. CommandNotFound is not classified
under this since it isn't inherently a user input error in all cases.

Some invalid commands can simply be due to an odd bot prefix. It would
also diminish the usefulness of the new parent class if CommandNotFound
was included.
2016-07-21 23:53:16 -04:00
cd87f247d3 [commands] Make Bot.check decorator an actual decorator. 2016-07-08 04:29:11 -04:00
1aaeeff02b [commands] Added missing parenthesis in examples 2016-07-08 04:29:05 -04:00
166d8257ec [commands] Refactor pagination into its own class.
This change allows users to more easily create their own formatters
without having to reinvent the pagination logic themselves. Hopefully
this makes it less of a pain for people to create custom help pages.
2016-07-05 21:44:14 -04:00
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
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
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
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
629c24339b [commands] Fix bug that made functions stop working as converters. 2016-06-23 18:36:41 -04:00
e64eb08c92 [commands] Port special cased discord converters to commands.Converter 2016-06-22 20:05:37 -04:00
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
324d10c9d9 [commands] Add Command.ignore_extra attribute to ignore extra arguments
This allows you to strictly require a number of arguments. The default
behaviour in this case is still `True`, since it would be a breaking
change otherwise and is a sane default. However if someone would want
to set this to `False`, they would receive an exception of type
`TooManyArguments` if too many arguments are passed to a command.

Hopefully this removes the uses of `ctx.message.content == 'stuff'`
inside commands.
2016-06-20 21:38:17 -04:00
adbf2c720f [commands] Add the concept of global checks.
Global checks are checks that are executed before regular per-command
checks except done to every command that the bot has registered. This
allows you to have checks that apply to every command without having to
override `on_message` or appending the check to every single command.
2016-06-19 22:15:11 -04:00
6f173cc095 [commands] Add delete_after keyword argument to utility functions.
This includes things like `Bot.say`, `Bot.upload`, `Bot.whisper`,
and `Bot.reply`.
2016-06-19 19:43:49 -04:00
183e7341f6 [commands] Add Context.cog property. 2016-06-16 05:42:28 -04:00
4dbac9423d [commands] Only show CommandNotFound on non-empty commands. 2016-06-14 01:35:35 -04:00
5f9ed8c9d2 [commands] Make the CommandError required argument optional again. 2016-06-10 23:50:17 -04:00
bde266bbb9 [commands] Fix @everyone elevation in the default help command. 2016-06-10 21:31:11 -04:00
1228159f30 [commands] Fix bug with Context.command not updating in groups.
This happened when `invoke_without_command` was set to True.
2016-06-10 21:05:42 -04:00
74cfc53bc8 [commands] Make it so CommandError does not contain @everyone mentions.
Mitigates some permission elevation issues.
2016-06-10 20:40:35 -04:00
43bbecd519 [commands] Exceptions raised while invocation raise CommandInvokeError.
This change should make it a bit more intuitive to get the original
exception without having the gotcha of checking ``isinstance`` inside
the error handler.
2016-06-10 20:32:05 -04:00
a0f37f8e85 [commands] Fix issue with proper local error handlers not beign called. 2016-06-10 01:07:03 -04:00
b9c7b05176 [commands] Unify Command.handle_local_error into general dispatcher. 2016-06-05 00:35:27 -04:00
661645ac97 [commands] Add Command.qualified_name to get the full command name.
This also sets `__str__` to do the same thing.
2016-06-04 22:31:00 -04:00
37dfe38af5 [commands] Fix bug where Context.command would not update. 2016-06-04 22:29:50 -04:00
9d9a20c128 [commands] Fix bug where subgroups would be repeatedly called.
This happened due to not resetting the `invoked_subcommand` state
tracking. Since the `invoked_subcommand` was not reset, it would always
assume that it was valid and repeatedly call it when passed invalid
subcommands/arguments.
2016-06-04 22:04:05 -04:00
24a9da04db [commands] Cleanup Command.invoke code due to exception propagation. 2016-06-04 21:41:01 -04:00
33a69681fc [commands] Dispatch command_error on command exec error.
Provide fallback on_command_error - will only fire if no cog handlers and
no local handler.
Propagate exceptions in checks and argument parsing to bot.
2016-06-04 21:22:10 -04:00
20e86973ea [commands] Delete frame objects when done using them. 2016-05-31 23:22:53 -04:00
3c8fcd3584 [commands] Add support for self-bots. 2016-05-31 20:30:17 -04:00