1575 Commits

Author SHA1 Message Date
Rapptz
99b1390e5a [commands] Elaborate more on disallowed types in Greedy and Optional 2018-09-24 23:39:25 -04:00
Rapptz
2721689254 Optimise tight loops in DiscordGateway.received_message
* type(x) is y is faster than isinstance(x, y)
* Re-arrange if-statements for common statements
* Drop handler getattr for most events that don't  use it
2018-09-24 23:22:49 -04:00
Rapptz
095f0ec2fc Optimise some member and user related routines.
* Skip user update if possible
* Drop copy.copy in favour of manual copy

Credit to Hornwitser for these findings.
2018-09-24 22:50:05 -04:00
Rapptz
95d8bb2e85 Change internal representation of roles in Member and Emoji.
Introduce a new internal type, SnowflakeList, which has better memory
footprint over a regular list or set of roles. It is suspected that
there will be a 9x reduction of memory for every Emoji instance and a
48 byte saving per Member instance. However, these savings will
probably only be evident on larger bots.

As a consequence of this change, Member.roles is now computed lazily.

Currently I am not sure if I want to do the initial sorting on the
SnowflakeList for Member, as this comes with a O(n log n) cost when
creating a Member for little purpose since SnowflakeList.has is not
overly relied on. If CPU time becomes an issue this might change.
2018-09-24 22:19:42 -04:00
Rapptz
3d03dbc451 Change internal role storage in Guild to a dict instead of a list.
This adds the following APIs:

* Guild.get_role

This removes the following APIs:

* Guild.role_hierarchy

To compensate for the removed APIs, Guild.roles is now a sorted list
based on hierarchy. The first element will always be the @everyone
role.

This speeds up access at the cost of some memory, theoretically.
2018-09-24 21:08:48 -04:00
Rapptz
12cb074316 Take the default role property into account when comparing roles. 2018-09-24 20:19:47 -04:00
Rapptz
418048b98a [commands] Fix up Greedy documentation a bit. 2018-09-24 04:22:09 -04:00
Rapptz
21cb700d2c Forgot to add these images. 2018-09-24 04:06:34 -04:00
Rapptz
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
Rapptz
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
zephyrkul
8ef509883a [commands] Properly parse bool when inside a typing.Union 2018-09-20 23:58:34 -04:00
Vexs
262c0d3a9e Correct note note about editing emoji in Guild.create_custom_emoji.
Remove incorrect note; extension of #1575
2018-09-20 23:45:15 -04:00
MusicOnline
9af0e54cd3 Correct ClientException message raised in invocation hooks.
For when the hooks are not coroutines.
2018-09-20 23:43:07 -04:00
MusicOnline
2c1ba84346 Add colour attribute for BaseUser 2018-09-16 22:46:05 +08:00
Episword
53433bca48 Translate some more files to Japanese 2018-09-15 18:28:57 -04:00
Jeremy Zhang
d092c6635b Fix webhook_update from code review 2018-09-15 18:28:57 -04:00
Jeremy Zhang
17f9916b03 Simple parser for WEBHOOKS_UPDATE 2018-09-15 18:28:57 -04:00
Rapptz
51a03d96e0 Update Japanese string dump. 2018-09-15 09:54:32 -04:00
Rapptz
5c24e69cf2 Fix up the Sphinx strings causing warnings. 2018-09-15 09:54:00 -04:00
Rapptz
0352c80a17 Add support for Discord's slow mode.
Adds the following:

* `slowmode_delay` for `TextChannel.edit`
* `slowmode_delay` attribute for `TextChannel`
2018-09-14 22:55:29 -04:00
Tarek1337
21309c2d72 Removed inaccurate note on emoji.py
In the docs, it says ``Note that bot accounts can only edit custom emojis they own.``

But after testing a bit. My bot was able to edit emojis in any guild that had the permissions `manage_roles`. Even if the bot didn't own the guild. Or was the original emoji uploader.

And I don't see any mentions of this in the API server or in the documentation. So I'm unsure how this ended up in here. It's possible I am misunderstanding the whole note. My bad if that's the case.
2018-09-14 22:55:28 -04:00
ItWasAllIntended
134bc21fda Update PyNaCl dependency to one that works with 3.7
This also adds the 3.7 classifier as with this there are no 3.7 issues
2018-09-14 22:55:28 -04:00
BeatButton
a4d1599ce9 Change docstrings to raw-strings 2018-09-14 22:55:27 -04:00
Toby Harradine
5131acd675
Bump aiohttp contraint to <3.5.0
New version contains many bugfixes, a couple new features and seemingly no breaking changes (for this lib's purposes at least).

Relevant changes: https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst#340-2018-08-25
2018-09-06 01:28:59 +10:00
bmintz
00a659c652 [docs] sort the VoiceRegions
having them appear in the docs ordered by their internal number
is not useful to the user. Sorting them by name
allows one to more quickly locate a voice region in the docs.
2018-08-30 19:20:11 -04:00
bmintz
1d65d6993a document HypeSquadHouse and Profile.hypesquad_houses 2018-08-30 19:20:10 -04:00
Carl Groth
3ccbda928e Fix PartialEmoji._as_reaction() for emojis the bot can't see
If the bot has access to the emoji, you can pass anything for its name
and it will work fine. The name is only required to be correct when
adding a reaction where you do not have access to the emoji,
all other cases ignore the name.
2018-08-30 18:33:51 -04:00
zephyrkul
b9ef80b0d0 [commands] Prepend mention prefixes in commands.when_mentioned_or 2018-08-28 23:50:57 -04:00
Chris
15ca9294e1 Fix typo in on_raw_reaction_add event. 2018-08-28 23:50:56 -04:00
Bryan Forbes
d7218259aa Call Http.start_group() in ClientUser.create_group() 2018-08-28 23:50:55 -04:00
Bryan Forbes
b6824c073e Ensure large guilds are properly appended to the ready state guild list 2018-08-28 23:50:55 -04:00
Bryan Forbes
b3bfec9119 Fix CallMessage.duration calculation 2018-08-28 23:50:54 -04:00
Episword
427d0aae86 Finished index.po translation. 2018-08-28 23:50:53 -04:00
Hornwitser
cd218fa6a7 Remove Reaction.users "Python 3.4 usage" section
Remove nonsensical "Python 3.4" usage section from Reaction.users().
Left behind from f25091ef.
2018-08-28 23:50:52 -04:00
Bryan Forbes
deda5c4e97 Fix behavior of reaction type-conversion 2018-08-25 14:38:19 -05:00
orlnub123
bd467085bf Fix latency being able to be negative 2018-08-24 21:57:26 -04:00
Mitchell Ferree
6d57ddf11b
Correct Member.__hash__
Make Member.__hash__ just use whatever its User object's hash impl is.
2018-08-23 19:10:29 -06:00
orlnub123
9bc48b21f5 Fix send_as_json not dispatching socket_raw_send 2018-08-23 20:45:47 -04:00
SilicalNZ
52e8c06aed
Fix typo in core.Command docstring 2018-08-24 06:24:04 +12:00
Rapptz
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
mental
ee57e89488 Added hypesquad house functionality 2018-08-22 22:01:19 -04:00
Toby Harradine
dace5aeaee Move conditional RTD dependencies to 'docs' extra 2018-08-22 21:57:27 -04:00
Ben Mintz
be7ea2678b Bot.unload_extension: don't remove commands from no module
Fixes unload_extension in the case of a command added via eval
2018-08-22 21:56:41 -04:00
Bryan Forbes
ef89d3aa22 Add support for converters working with PEP-563 2018-08-22 21:53:47 -04:00
Hornwitser
c557ee33ca [lint] Fix types used for __slots__ and __all__
Stay consistent with the rest of the library and use lists for module
__all__ values and tuples for class __slots__ attributes.
2018-08-22 21:43:55 -04:00
Hornwitser
d20772c680 [lint] Replace deprecated Logger function warn
The method log of Logger has never been documented as being a part of
the standard logging module.  It was renamed to warning when the module
was included in the standard library, but the old name was kept for
backward compatibility.
2018-08-22 21:43:54 -04:00
Hornwitser
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
Hornwitser
3679819c53 [lint] Remove unnecessary lambdas
Lambdas of the form `lambda x: func(x)` are redundant.
2018-08-22 21:43:52 -04:00
Hornwitser
119c5a0618 [lint] Remove unused variables
Left over from various refactoring and rewrites.
2018-08-22 21:43:51 -04:00
Hornwitser
d58fc0ccee [lint] Remove unused imports
Left over from various refactoring and rewrites.
2018-08-22 21:43:50 -04:00