114 Commits

Author SHA1 Message Date
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
Hornwitser
ed76151c70 Warn on high latency and blocking heartbeat
Add warnings for when the heartbeat is blocked for a long time and when
the websocket latency is excessively high.  These indicate problems with
blocking the event loop and/or insufficient computing resources to keep
up with the demand.
2019-01-28 22:22:53 -05:00
Imayhaveborkedit
9c5259afd7 Update voice code to vws V4
- Update internals to be compatible with v4
- Adds multiple encryption mode support.  Previously only `xsalsa20_poly1305` was supported.  Now `xsalsa20_poly1305_suffix` is also supported.
  Note: There is no (nice) way to manually select a mode.  The user needn't worry about this however.
- Fixed speaking state bug.  When you disconnected from a voice channel while a bot was playing, upon reconnect you would be unable to hear the bot.  This was caused by bots not sending their speaking state while transmitting.  Bots will now set their speaking state properly when transmitting.  
  Note: This does not account for sending actual silence, the speaking indicator will still be active.
2019-01-28 22:22:52 -05:00
Hornwitser
883ae8fe80 Fix accidental regression of 9bc48b2 in fa46b07
Occured due to difficult to spot difference in git merge when rebasing
the lint changes.
2019-01-28 22:22:51 -05:00
Dante Dam
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
CraftSpider
068d953b42 Add override to close() method to the websocket subclass.
This makes it so that _keep_alive is stopped no matter which closing
method is called
2018-12-14 18:59:28 -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
34fd266cf9 [lint] Do log formating lazily
Convert log("fmt" % args) to log("fmt", args) as the latter is lazy and
does not do the formating if the string is never logged.
2018-11-24 22:17:58 -05:00
Hornwitser
51d626eabe [lint] Remove redundant paranthesis
Remove redundant parenthisis around await expressions.  Left over from
f25091ef.
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
Hornwitser
a71b3b5fa0 [lint] Limit unneccessarily broad except clauses
Add exception qualifier(s) to bare except clauses swallowing exceptions.
2018-11-24 22:17:57 -05: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
orlnub123
bd467085bf Fix latency being able to be negative 2018-08-24 21:57:26 -04:00
orlnub123
9bc48b21f5 Fix send_as_json not dispatching socket_raw_send 2018-08-23 20:45:47 -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