214 Commits

Author SHA1 Message Date
apple502j
cb43e19bea Fix TypeError in chunker 2020-05-23 21:56:27 -04:00
iomintz
755ab28311
state: use bytes.hex() instead of binascii.hexlify().decode() 2020-05-10 20:07:22 -05:00
Rapptz
13a3f760e6 Fix timeout issues with fetching members via query_members
This uses the nonce field to properly disambiguate queries. There's
also some redesigning going on behind the scenes and minor clean-up.
Originally I planned on working on this more to account for the more
widespread chunking changes planned for gateway v7 but I realized that
this would indiscriminately slow down everyone else who isn't planning
on working with intents for now.

I will work on the larger chunking changes in the future, should time
allow for it.
2020-05-10 19:35:45 -04:00
Rapptz
0d5e6e213c Decrement Guild.member_count even if member is not cached
Fix #4021
2020-04-19 18:22:41 -04:00
apple502j
14f80fce45 Fix PartialEmoji.url.read for reactions 2020-04-18 19:34:41 +09:00
Rapptz
8874aa3dd2 Move log levels around to make INFO a little less noisy 2020-04-06 05:22:57 -04:00
NCPlayz
c8f32f3151 animated key is never given to reaction_remove(_emoji) 2020-04-06 04:58:27 -04:00
Rapptz
d853a57e86 Rename allowed mention parameters to allowed_mentions 2020-04-04 13:22:51 -04:00
Rapptz
041785937e Add support for configuring allowed mentions per message or bot wide. 2020-04-04 07:40:51 -04:00
Rapptz
5c7df3d943 Bump waiting time of GUILD_CREATE stream by number of shards waited.
2 seconds might be too short and cause it to finish waiting while other
shards are still IDENTIFYing.
2020-01-28 23:56:46 -05:00
Rapptz
6071607176 Bump copyright year to 2020
Closes #2510
2020-01-19 20:03:00 -05:00
Rapptz
87f9dcff9c Add support for clearing a specific reaction.
Closes #2440
2020-01-17 19:53:28 -05:00
Rapptz
7b2c01c48a Add support for on_invite_create and on_invite_delete 2020-01-17 19:20:53 -05:00
Rapptz
42a084028c Expose _ActivityTag as BaseActivity to easily refer to. 2020-01-14 20:56:00 -05:00
Rapptz
cd9135b082 Rewrite on_ready delay to actually make sense and prevent heavy sleep 2020-01-14 19:52:06 -05:00
NCPlayz
f95ccf53e0 Fix issue with shard_ready not dispatching when not fetching offline 2020-01-14 19:39:34 -05:00
NCPlayz
bb71f14ce3 Add RawReactionActionEvent.member 2019-12-17 23:59:59 -05:00
Rapptz
a6f61dcbde Fix all deprecation warnings for 3.8 2019-11-20 02:30:19 -05:00
Rapptz
45f342ff79 Fix regression with references being overwritten from the cache.
A proper fix for this would be to just request presence information
as well since the chunk request would probably be more up to date than
the current cache. However this delta requires a little bit more work
and will be done later.
2019-11-20 01:41:23 -05:00
Rapptz
15f0b000e1 Move PartialEmoji over to a new namespace to avoid circular imports 2019-11-20 00:50:19 -05:00
Rapptz
d8e47b08a2 Manually trigger GC in cases of large deallocations. 2019-11-18 19:24:33 -05:00
Rapptz
89bfd9cc20 animation field in reaction objects are not consistently available 2019-11-15 04:37:39 -05:00
Rapptz
5d7cf56d7f Actually add things to the message cache. 2019-08-27 18:36:40 -04:00
Lorenzo
828e8189d3 Fix _get_message returning the message cache. 2019-08-27 17:44:22 -04:00
Rapptz
cf79816c5d Allow disabling the message cache with max_messages=None
This also changes the default to 1000 instead of 5000 since it can
take some time for small bots to cycle through the default and they
make up the majority of it.
2019-08-27 04:50:50 -04:00
Rapptz
f513d831d1 Add RawReactionActionEvent.event_type attribute.
This helps differentiate between reaction removal or addition.
2019-08-11 19:11:22 -04:00
Rapptz
93f719aeb7 Proper boolean check for caching members. 2019-07-15 08:26:22 -04:00
Rapptz
5b2f630848 Add Guild.query_members to fetch members from the gateway. 2019-07-15 07:56:48 -04:00
Rapptz
bc352f0e50 Allow complete disabling of the member cache. 2019-07-11 00:49:30 -04:00
Rapptz
7b8d50a988 Add support for guild subscriptions. 2019-07-10 04:51:27 -04:00
Rapptz
2c16e43e8a Fix regression with unresolved channels due to reordering.
Channels are meant to fallback to Object if the message is out of
order. Somewhere along the commit line this got removed despite the
issue still existing.
2019-06-29 19:41:38 -04:00
Rapptz
7e2da1c93b Publicly expose a type property for all channels.
Fix #2185
2019-06-09 00:23:22 -04:00
Rapptz
991140eebe Replace Enum with an internal one for significant speed improvements.
This has been a massive pain point for me personally due to the poor
design of the Enum class leading to the common use cases used in the
library being significantly slow. Since this Enum is not public facing
in terms of *creation*, I can only implement the APIs that are used
when *accessing* them.

This Enum is a drop-in replacement to the pre-existing enum.Enum class
except it comes with significant speed-ups. Since this is a lot to go
over, I will let the numbers speak for themselves:

In [4]: %timeit enums.try_enum(enums.Status, 'offline')
263 ns ± 34.3 ns per loop (7 runs, 1000000 loops each)
In [5]: %timeit NeoStatus.try_value('offline')
134 ns ± 0.859 ns per loop (7 runs, 10000000 loops each)

In [6]: %timeit enums.Status.offline
116 ns ± 0.378 ns per loop (7 runs, 10000000 loops each)
In [7]: %timeit NeoStatus.offline
31.6 ns ± 0.327 ns per loop (7 runs, 10000000 loops each)

In [8]: %timeit enums.Status.offline.value
382 ns ± 15.2 ns per loop (7 runs, 1000000 loops each)
In [9]: %timeit NeoStatus.offline.value
65.5 ns ± 0.953 ns per loop (7 runs, 10000000 loops each)

In [10]: %timeit str(enums.Status.offline)
630 ns ± 14.8 ns per loop (7 runs, 1000000 loops each)
In [11]: %timeit str(NeoStatus.offline)
253 ns ± 3.53 ns per loop (7 runs, 1000000 loops each)

In [12]: %timeit enums.Status('offline')
697 ns ± 8.42 ns per loop (7 runs, 1000000 loops each)
In [13]: %timeit NeoStatus('offline')
182 ns ± 1.83 ns per loop (7 runs, 10000000 loops each)
2019-06-09 00:06:34 -04:00
Rapptz
f84219c2b2 Improve performance of parsing MESSAGE_UPDATE and MESSAGE_CREATE events
Embed edits are no longer special cased in the dispatch code, which
could lead to on_message_edit being called more often than it used to
be called. I am not sure on the general impact on that being removed.

Fixes #2195
2019-06-07 22:18:01 -04:00
Rapptz
00a0856cc4 Use a dict instead of getattr for parsing events.
Probably not a significant difference but might as well use it here.
The basic idea is to cache the getattr calls instead of repeatedly
doing it (since they're around 105ns on my machine). The dictionary
lookup is about 41ns on my machine.

The next step in speeding up library code some more should be in
the parser bodies themselves but that's a problem to tackle another
day.
2019-05-29 01:22:53 -04:00
Vexs
82a39eb148 Add cached_message to on_raw_message_edit event
Also add documentation for this behavior
2019-05-09 05:53:56 -04:00
Rapptz
f9e95a35f9 Fix USER_UPDATE changes not triggering for member instances.
Also add a ClientUser.locale attribute.
2019-04-28 06:36:12 -04:00
Rapptz
f8999b63ae Fix long-standing issue with user updates not dispatching properly.
This fix is long coming. For a long time due to the addition of a
global user cache, the on_member_update event would only have the
updated user in the very first dispatch due to a quirk in the reference
only being updated once.

In order to fix this issue two things had to change:

1. There had to be a new event, `on_user_update` to complement
   the equivalent member event.
2. Unnecessary copies of User had to be removed to compensate for the
   performance hit from the diffing.

While doing these two fixes I also re-evaluated some more unnecessary
copies done during the PRESENCE_UPDATE to add member case while
fetch_offline_members=False is set or due to chunking issues. The
number of copies was brought down from 2 to 1, discounting the original
Member creation. Unsure on the benefits of this one, however.

N.B: this doesn't change the pre-existing behaviour of on_member_update
2019-04-08 07:45:04 -04:00
Rapptz
1a9726087a GUILD_MEMBER_UPDATE no longer does actual user updates.
This had been delegated to PRESENCE_UPDATE a long time ago,
unfortunately.
2019-04-08 06:34:28 -04:00
Vexs
9591b00dcf Redesign bulk delete events
Change `parse_message_delete_bulk` to not dispatch individual
`message_delete` events, and instead `bulk_message_delete`. Also make
`raw_bulk_message` delete and `raw_message_delete` have message
objects attached.

Fixes #1807
2019-04-06 19:18:06 -04:00
NCPlayz
be227ebcf0 Redesign asset retrieval in the library.
Most assets now return a new class named `Asset`. This allows for the
assets to be consistently saved via a `save` method instead of special
casing for `Attachment`.

`AppInfo` is no longer a namedtuple it is a fully documented dataclass,
as well as having the state attached to it.

Fixes #1997
2019-04-06 19:12:50 -04:00
Rapptz
b41a29a889 Get cached message in reverse order for improved performance.
Most embed-only edits happen for the newest message.
2019-03-23 00:57:50 -04:00
Rapptz
35c0476dbb Add TextChannel.last_message_id and TextChannel.last_message 2019-03-20 22:30:23 -04:00
Rapptz
73aca4d4d3 Expose Embed.from_data as Embed.from_dict
This is a breaking change.
2019-03-13 06:02:56 -04:00
CraftSpider
8e97a0a248 Log unknown channel warning in WEBHOOK_UPDATE 2019-02-18 03:47:57 -05:00
CraftSpider
e920fe9a56 Add guild_integrations_update event 2019-02-18 03:47:56 -05:00
Dante Dam
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
Hornwitser
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
Hornwitser
633192b3cd [lint] Replace equality comparisons to singletons
Restrict the values accepted by comparisons with booleans to be actual
booleans.

Minor breaking of undocumented behaviour in permissions; the value to
set bits to must be booleans (as indicated by the type error thrown).
2018-11-24 22:17:57 -05:00
Hornwitser
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