Commit Graph

151 Commits

Author SHA1 Message Date
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
1fba1b06fa Rewrite HTTP handling significantly.
This should have a more uniform approach to rate limit handling. Instead
of queueing every request, wait until we receive a 429 and then block
the requesting bucket until we're done being rate limited. This should
reduce the number of 429s done by the API significantly (about 66% avg).

This also consistently checks for 502 retries across all requests.
2016-06-12 20:33:09 -04:00
41a2b5ed73 Actually read from the voice websocket & fix heartbeat.
This change makes it so that the buffer doesn't fill and the voice server drops the socket.

Also, use correct interval for voice websocket heartbeat.
2016-06-05 21:18:36 -07:00
f6fa1e837a Actually use v4 gateway and fixes thanks to Jake. 2016-06-02 07:32:35 -04:00
8638ff4414 Update voice client main ws references when reconnecting. 2016-06-01 05:20:22 -04:00
e0a91df32b Add RESUME support. 2016-06-01 05:13:15 -04:00
e66b2dce88 Rename threading internal variable conflict. 2016-05-13 20:24:45 -04:00
0c8d5ee863 Force encoding of text retrieval functions to use utf-8.
Closes #207
2016-05-10 19:52:34 -04:00
3feba5d1bb Add Game.type and Game.url attributes to change streaming status. 2016-05-06 16:38:22 -04:00
701720a0f8 Add a TimeoutError if VoiceClient.connect fails. 2016-05-06 13:30:44 -04:00
570ccbf753 Suppress ConnectionClosed on sending in the main websocket. 2016-05-06 13:19:41 -04:00
d9c780b8a8 Working multi-server voice support. 2016-05-01 20:54:13 -04:00
c1b5a52823 Refactor voice websocket into gateway.py 2016-04-27 18:36:24 -04:00