Commit Graph

163 Commits

Author SHA1 Message Date
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
c67d95327e Remove dead package references. 2018-06-10 18:16:40 -04:00
f25091efe1 Drop support for Python 3.4 and make minimum version 3.5.2. 2018-06-10 18:10:00 -04:00
a425bd91be Fix invalid close errors on websockets 4.x
Fixes #1110
2018-03-06 00:15:36 -05:00
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
9d3d8e0f0a Fix websockets 4.0 support 2018-02-12 00:20:18 -05:00
3112e1c17e Add intersphinx 2018-01-06 17:23:59 -05:00
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
92a37c2e4f Revert "Implement zlib streaming for the gateway."
This reverts commit 462191a08b.
2017-10-14 15:22:39 -04:00
462191a08b Implement zlib streaming for the gateway. 2017-10-12 22:53:20 -04:00
deaba1f5ab Use time.monotonic instead of time.time for heartbeat code. 2017-08-19 22:15:29 -04:00
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
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
ceafae0ab2 Add DiscordWebSocket.latency to measure discord heartbeat latency. 2017-08-08 20:35:42 -04:00
4ee90cd6e4 Fix missing lazy logging format calls.
Not sure how I missed these.
2017-06-24 20:52:19 -04:00
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
3436792614 Allow setting a presence upon logging in. 2017-05-20 15:19:47 -04:00
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
e445fa9335 Wait 5 seconds before attempting to RESUME during INVALIDATE_SESSION. 2017-04-22 21:34:56 -04:00
3cfebc4605 Timeout when doing initial connection. 2017-04-22 02:18:35 -04:00
1fc08bc5a2 Remove unused imports. 2017-04-18 04:22:35 -04:00
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
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
1b3234ab64 Add info logging for close codes we cannot handle. 2017-02-24 17:23:46 -05:00
a6b180b5ad Don't RESUME when given sharding related close codes. 2017-02-15 17:58:57 -05:00
ced064d08c Add missing continue statement in gateway futures. 2017-02-08 20:30:09 -05:00
ecab8399ff Handle HEARTBEAT_ACK 2017-02-08 07:23:09 -05:00
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
b876133e87 Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
2017-01-25 21:38:50 -05:00
ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
4bc6625739 Add AutoShardedClient.change_presence. 2017-01-08 01:51:10 -05:00
b5bed9ef33 Change the way shards are launched in AutoShardedClient. 2017-01-08 01:31:46 -05:00
20041ea756 Implement AutoShardedClient for transparent sharding.
This allows people to run their >2,500 guild bot in a single process
without the headaches of IPC/RPC or much difficulty.
2017-01-07 23:19:39 -05:00
98b981848d Move message creation to a factory method inside ConnectionState. 2017-01-03 09:52:10 -05:00
79a49f9145 Absolute import some circular dependencies to appease Python 3.4. 2017-01-03 09:52:02 -05:00
d1d54a468a Rename Server to Guild everywhere. 2017-01-03 09:51:54 -05:00
6306fc08db Discard null sequences in the gateway.
This was forbidding the Discord gateway from allowing us to RESUME
properly, causing an over-abundance of READY being called.
2016-12-16 18:29:29 -05:00
98d8c855d8 Fix typo in change_presence validation message 2016-10-15 15:54:50 -07:00
7272190e2d Add support for "Do Not Disturb" and "Invisible" statuses.
This deprecates Client.change_status in favour of the newer and more
correct Client.change_presence.
2016-09-26 19:55:42 -04:00
fc1155c160 Remove unused endpoints.py file. 2016-09-25 21:54:38 -04:00
a23e51f6c4 Fix gateway code to work with websockets 3.2. 2016-08-25 17:09:34 -04:00
0b6e74ebec Ensure that keep alive threads are closed when a websocket closes.
The library worked with the assumption that whenever the recv call for
the websocket would lead to a closure, the close method would be called
to signal closure and as a result our close method would be called.

This assumption turned out to be false as the websockets library would
instead call an internal function named close_connection instead. So to
solve our problem we need to override this function instead of close.
2016-08-21 11:45:41 -04:00
0c95edab8c Handle receiving HEARTBEAT opcode. 2016-07-30 13:03:22 -04:00
ddd3fd0a3d Begin working on gateway v6 changes.
The first batch of changes are related to channel types and group
direct messages. Support these first so READY begins parsing.
2016-07-13 00:10:16 -04:00
e600abbbab Ignore HEARTBEAT_ACK for now to disable the noisy logging. 2016-06-27 21:32:43 -04:00
abf9be5f7d Guild Sharding support 2016-06-26 14:47:16 -04:00
8b3617111a Support for v5 Gateway. 2016-06-22 05:00:08 -04:00
92fe4daa86 Attempt resume when we receive a 1001. 2016-06-16 19:13:13 -04:00
aecf0daf33 Fix sed error involved in creation of voice websocket. 2016-06-12 21:16:57 -04:00
dbd3147059 Support more close codes for RESUME. 2016-06-12 20:48:23 -04:00