130 Commits

Author SHA1 Message Date
Nadir Chowdhury
63ec23bac2
Code optimisations and refactoring via Sourcery 2021-02-24 21:26:51 -05:00
Riley Shaw
fafc3d9185
Fix ZeroDivisionError in DiscordVoiceWebSocket.average_latency 2021-02-18 06:53:08 -05:00
Nihaal Sangha
69bdc3a184
Change copyright year to present 2021-01-15 05:28:11 -05:00
Rapptz
5c868ed871 Fix SyntaxError from PR implementing presences in member querying 2021-01-01 09:37:47 -05:00
Nadir Chowdhury
59c11e71a2
Implement presences for Guild.query_members 2020-12-31 13:50:22 -05:00
Rapptz
2509ca6a82 Add internal method to check if the websocket is currently ratelimited 2020-10-17 22:51:29 -04:00
Rapptz
21ed9f61d2 Fix disconnect when trying to move to another voice channel.
Not overly proud of this implementation but this allows the library
to differentiate between a 4014 that means "move to another channel" or
"move nowhere". Sometimes the VOICE_STATE_UPDATE comes before the
actual websocket disconnect so special care had to be taken in that
case.

Fix #5904
2020-10-17 22:01:57 -04:00
Rapptz
6bae52f4bb Check for zombie connections through last received payload
The previous code would check zombie connections depending on whether
HEARTBEAT_ACK was received. Unfortunately when there's exceeding
backpressure the connection can terminate since the HEARTBEAT_ACK is
buffered very far away despite it being there, just not received yet.
2020-09-23 03:21:18 -04:00
Rapptz
af8fc32329 Use a lock for the gateway rate limiter.
This will allow for higher concurrency in AutoSharded situations where
I can mostly "fire and forget" the chunk requests.
2020-09-23 03:21:17 -04:00
Rapptz
5fe998ac19 Heartbeats bypass the rate limits for gateway 2020-09-23 03:21:17 -04:00
Rapptz
930761e058 Rewrite chunking to work with intents.
This slows down chunking significantly for bots in a large number of
guilds since it goes down from 75 guilds/request to 1 guild/request.
However the logic was rewritten to fire the chunking request
immediately after receiving the GUILD_CREATE rather than waiting for
all the guilds in the ready stream before doing it.
2020-09-23 03:21:16 -04:00
Rapptz
ec7b8edcc2 Add more close codes that can't be handled for reconnecting. 2020-09-23 03:21:16 -04:00
Rapptz
e7db9cfdf7 Handle gateway rate limits by using a rate limiter.
With the new chunking changes this will become necessary and we don't
want to disconnect from having too many outwards requests.
2020-09-23 03:21:15 -04:00
Rapptz
a6381dcf77 Add support for guild intents 2020-09-23 03:21:15 -04:00
Rapptz
e3922e24d9 Correct some protocol errors in v4 of voice gateway 2020-09-23 03:20:35 -04:00
Rapptz
f8808dba9b Guard uses of the keep alive thread in case they're None
Fixes #5800
2020-09-09 21:18:41 -04:00
Rapptz
5dd8e372e4 Terminate connection if a close code couldn't be handled 2020-08-06 09:25:01 -04:00
Rapptz
3a1a215f8b Propagate manual close codes to socket subclass
aiohttp seems to not set it during its state machine flow
2020-08-05 04:27:11 -04:00
jack1142
bd9821320e Use a subclass rather than monkey-patching for the websocket 2020-07-25 09:59:40 -04:00
Rapptz
e0660ef8a6 Add a timeout for receiving websocket messages. 2020-07-25 09:59:40 -04:00
Rapptz
e2f42597a5 Handle Connection Reset by Peer connection errors.
This should work both on Windows and on Linux.

Apparently these types of blips are considered normal for Discord. So
rather than letting the reconnect logic handler expect these to be
catastrophic, it should handle it specially so it doesn't waste an
IDENTIFY for what ultimately should just be a small networking blip.

This also makes it less noisy for the end-user as these complaints
happen from time to time.
2020-07-25 09:59:40 -04:00
Rapptz
8070d39a23 Add shard related connection and resume events.
These include:
* on_shard_resumed
* on_shard_connect
* on_shard_disconnect
2020-07-25 09:59:39 -04:00
Rapptz
394b514cc9 Add before_identify_hook to have finer control over IDENTIFY syncing 2020-07-25 09:59:39 -04:00
Rapptz
058a1e608b Fix voice websocket connections 2020-07-25 09:59:38 -04:00
Rapptz
b8154e365f Rewrite gateway to use aiohttp instead of websockets 2020-07-25 09:59:38 -04:00
Rapptz
3afbbf5e47 Can't use %d in here 2020-07-25 09:59:37 -04:00
Rapptz
ba35c2b9bf Add shard ID to keep alive logger messages 2020-07-25 09:59:37 -04:00
Rapptz
09ecb16680 Rewrite of AutoShardedClient to prevent overlapping identify
This is experimental and I'm unsure if it actually works
2020-07-25 09:59:37 -04:00
Tarek
a972c95f12 Add user_ids fields for query_members 2020-05-29 23:24:07 -04: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
11211d48eb Bump blocking threshold from 5 seconds to 10 seconds 2020-04-14 04:22:05 -04:00
Rapptz
d6be6adf8b Add traceback to debug blocking issues 2020-04-14 04:21:20 -04:00
Rapptz
8874aa3dd2 Move log levels around to make INFO a little less noisy 2020-04-06 05:22:57 -04:00
Rapptz
7433cf3b16 Fix VoiceClient.average_latency erroring when heartbeat is None 2020-04-06 04:58:27 -04:00
Fwf
fa34d357a1 Added VoiceClient.latency and VoiceClient.average_latency
This also implements the heartbeating a bit more consistent to the
official Discord client.
2020-04-04 03:00:27 -04:00
Rapptz
403651a144 Change default close code to 4000 instead of 1000.
This prevents our sessions from being invalidated by Discord which
caused a lot of failures when resuming. This caused an unnecessary
amount of IDENTIFYs to happen depending on the circumstances.

Closes #2631

See also discord/discord-api-docs#1472
2020-04-04 01:42:08 -04:00
Rapptz
b9e6ed28a4 Downgrade unknown event logging to DEBUG rather than WARNING
It's too noisy
2020-01-26 09:22:42 -05:00
Rapptz
6071607176 Bump copyright year to 2020
Closes #2510
2020-01-19 20:03:00 -05:00
Rapptz
42a084028c Expose _ActivityTag as BaseActivity to easily refer to. 2020-01-14 20:56:00 -05:00
Rapptz
ec4962a14c Wait 5 seconds before IDENTIFYing with an invalidated session. 2019-12-17 23:34:49 -05:00
Lorenzo
1b9108ffd7
The port is a big endian unsigned short.
See https://github.com/discordapp/discord-api-docs/pull/1244
2019-12-06 19:33:15 +01:00
Rapptz
c62b6c3e88 Fix more deprecation warnings for 3.8 2019-11-26 05:19:11 -05:00
Rapptz
4ef0fb0d95 Fix more deprecation warnings 2019-11-20 03:04:04 -05:00
Jake
8fdcb4de3b
use proper ip for endpoint ip 2019-07-17 13:27:37 -07:00
Rapptz
5b2f630848 Add Guild.query_members to fetch members from the gateway. 2019-07-15 07:56:48 -04:00
Rapptz
7b8d50a988 Add support for guild subscriptions. 2019-07-10 04:51:27 -04:00
NCPlayz
3c9bcc2851 Improve documentation 2019-06-07 19:27:46 -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
Rapptz
919dbcafb3 Consistent use of __all__ to prevent merge conflicts. 2019-04-20 17:20:58 -04:00
NCPlayz
fb02191b80 Organise documentation 2019-03-19 08:24:42 -04:00