Commit Graph
181 Commits
Author SHA1 Message Date
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
Hornwitser d58fc0ccee [lint] Remove unused imports
Left over from various refactoring and rewrites.
2018-08-22 21:43:50 -04:00
Rapptz 5ae9ea26b1 Disable compression for websockets.
Increase of RAM and CPU doesn't give me much benefit I feel.
2018-06-10 18:37:51 -04:00
Rapptz c67d95327e Remove dead package references. 2018-06-10 18:16:40 -04:00
Rapptz f25091efe1 Drop support for Python 3.4 and make minimum version 3.5.2. 2018-06-10 18:10:00 -04:00
Rapptz a425bd91be Fix invalid close errors on websockets 4.x
Fixes #1110
2018-03-06 00:15:36 -05:00
Rapptz f8f8f418f3 Split Game object to separate Activity subtypes for Rich Presences.
This is a massive breaking change.

* All references to "game" have been renamed to "activity"
* Activity objects contain a majority of the rich presence information
* Game and Streaming are subtypes for memory optimisation purposes for
  the more common cases.
* Introduce a more specialised read-only type, Spotify, for the
  official Spotify integration to make it easier to use.
2018-03-05 11:15:49 -05:00
BeatButton 9d3d8e0f0a Fix websockets 4.0 support 2018-02-12 00:20:18 -05:00
Tobotimus 3112e1c17e Add intersphinx 2018-01-06 17:23:59 -05:00
Rapptz 47a58d354d Reimplement zlib streaming.
This time with less bugs. It turned out that the crash was due to a
synchronisation issue between the pending reads and the actual shard
polling mechanism.

Essentially the pending reads would be cancelled via a simple bool but
there would still be a pass left and thus we would have a single
pending read left before or after running the polling mechanism and
this would cause a race condition.

Now the pending read mechanism is properly waited for before returning
control back to the caller.
2017-10-14 21:19:46 -04:00
Rapptz 92a37c2e4f Revert "Implement zlib streaming for the gateway."
This reverts commit 462191a08b.
2017-10-14 15:22:39 -04:00
Rapptz 462191a08b Implement zlib streaming for the gateway. 2017-10-12 22:53:20 -04:00
Rapptz deaba1f5ab Use time.monotonic instead of time.time for heartbeat code. 2017-08-19 22:15:29 -04:00
Rapptz 0f7482ed6e Add Client.latency, AutoShardedClient.latency and latencies.
This should allow an easier way to query the Discord protocol gateway
latency, defined by the difference HEARTBEAT_ACK between and the last
sent HEARTBEAT.
2017-08-15 23:41:11 -04:00
Rapptz de65f7309b Add heartbeat_timeout to the Client options.
This setting configures how long before a timeout event is emitted
internally and disconnects the websocket. Since some users were
experiencing issues with the gateway not responding, this should help
mitigate the issue for those with poor PCs.
2017-08-08 21:12:04 -04:00
Rapptz ceafae0ab2 Add DiscordWebSocket.latency to measure discord heartbeat latency. 2017-08-08 20:35:42 -04:00
Rapptz 4ee90cd6e4 Fix missing lazy logging format calls.
Not sure how I missed these.
2017-06-24 20:52:19 -04:00
Rapptz b06899e7d4 Defer logging formatting until the logger is actually called.
This would cause unnecessary format calls even if you didn't have
logging enabled.
2017-06-09 18:53:24 -04:00
Rapptz 3436792614 Allow setting a presence upon logging in. 2017-05-20 15:19:47 -04:00
Rapptz df90aaa610 Rename internal ConnectionState attribute to have an underscore.
Some people like to use that variable name apparently.

See #568 and #569.
2017-05-16 20:20:39 -04:00
Rapptz e445fa9335 Wait 5 seconds before attempting to RESUME during INVALIDATE_SESSION. 2017-04-22 21:34:56 -04:00
Rapptz 3cfebc4605 Timeout when doing initial connection. 2017-04-22 02:18:35 -04:00
Rapptz 1fc08bc5a2 Remove unused imports. 2017-04-18 04:22:35 -04:00
Rapptz 3b1b26ffb1 Re-implement voice sending.
This is a complete redesign of the old voice code.

A list of major changes is as follows:

* The voice websocket will now automatically reconnect with
  exponential back-off just like the regular Client does.
* Removal of the stream player concept.
* Audio now gracefully pauses and resumes when a disconnect is found.
* Introduce a discord.AudioSource concept to abstract streams
* Flatten previous stream player functionality with the
  VoiceClient, e.g. player.stop() is now voice_client.stop()
* With the above re-coupling this means you no longer have to
  store players anywhere.
* The after function now requires a single parameter, the error,
  if any existed. This will typically be None.

A lot of this design is experimental.
2017-04-18 03:49:48 -04:00
Rapptz ac90159c72 Improve logging in more places.
This shows the Shard ID in more places, along with a gateway trace and
session ID. Also helps show the RESUME/IDENTIFY/RESUMED/READY flow a
bit more instead of it looking like the connection has zombied out.
2017-04-12 19:43:47 -04:00
Rapptz 1b3234ab64 Add info logging for close codes we cannot handle. 2017-02-24 17:23:46 -05:00
Rapptz a6b180b5ad Don't RESUME when given sharding related close codes. 2017-02-15 17:58:57 -05:00
Rapptz ced064d08c Add missing continue statement in gateway futures. 2017-02-08 20:30:09 -05:00
Rapptz ecab8399ff Handle HEARTBEAT_ACK 2017-02-08 07:23:09 -05:00
Rapptz dc486980f8 Rewrite RESUME logic to be more in line with what is requested.
Apparently we should always try to RESUME first and if we get
INVALIDATE_SESSION then we should IDENTIFY instead. This is the
preferred way to do RESUMEs.
2017-02-08 04:37:16 -05:00
Rapptz b876133e87 Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
2017-01-25 21:38:50 -05:00
Rapptz ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
Rapptz 4bc6625739 Add AutoShardedClient.change_presence. 2017-01-08 01:51:10 -05:00
Rapptz b5bed9ef33 Change the way shards are launched in AutoShardedClient. 2017-01-08 01:31:46 -05:00