Commit Graph

53 Commits

Author SHA1 Message Date
5c7df3d943 Bump waiting time of GUILD_CREATE stream by number of shards waited.
2 seconds might be too short and cause it to finish waiting while other
shards are still IDENTIFYing.
2020-01-28 23:56:46 -05:00
6071607176 Bump copyright year to 2020
Closes #2510
2020-01-19 20:03:00 -05:00
5f7a97ff96 Document BaseActivity 2020-01-14 22:09:24 -05:00
42a084028c Expose _ActivityTag as BaseActivity to easily refer to. 2020-01-14 20:56:00 -05:00
4ef0fb0d95 Fix more deprecation warnings 2019-11-20 03:04:04 -05:00
a6f61dcbde Fix all deprecation warnings for 3.8 2019-11-20 02:30:19 -05:00
34b93c757c docs: Fix minor typo 2019-06-12 00:47:42 -04:00
3c9bcc2851 Improve documentation 2019-06-07 19:27:46 -04:00
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
186d9a7f9c Use a regular boolean instead of asyncio.Event for close status. 2019-04-25 01:57:32 -04:00
61ee88b0fc Fix oversight where on_disconnect did not get called on WS termination. 2019-04-08 07:45:05 -04:00
fb02191b80 Organise documentation 2019-03-19 08:24:42 -04:00
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
e89e7dfe93 Add support for multiple activities 2018-11-24 22:36:52 -05:00
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
51d626eabe [lint] Remove redundant paranthesis
Remove redundant parenthisis around await expressions.  Left over from
f25091ef.
2018-11-24 22:17:58 -05:00
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
e29e3438ec Don't try to close shards if there are none yet. 2018-09-26 02:19:42 +09:00
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
a4d1599ce9 Change docstrings to raw-strings 2018-09-14 22:55:27 -04:00
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
119c5a0618 [lint] Remove unused variables
Left over from various refactoring and rewrites.
2018-08-22 21:43:51 -04:00
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
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
3112e1c17e Add intersphinx 2018-01-06 17:23:59 -05:00
542924d5df Fixed a zero division error when accessing latencies
When accessing the latencies property on an AutoShardedClient when none of shards are ready, we get a ZeroDivisionError. An example of this can be seen here.
```py
class StatsBot(commands.AutoShardedBot):
    def __init__(self):
        super().__init__(command_prefix=None)
        self._add_commands()

    def _add_commands(self):
        '''Adds commands automatically'''
        for name, attr in inspect.getmembers(self):
            if isinstance(attr, commands.Command):
                self.add_command(attr)
```

When iterating through this custom client's it accesses the latencies property when no shards are ready, therefore it raises the error. A quick fix for this would be to return None if no shards are ready.
2017-11-12 16:58:30 -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
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
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
e557f69c83 Make sure that websockets.connect is a coroutine.
In 3.5.0 and 3.5.1 asyncio.ensure_future requires a Future or a
coroutine otherwise a TypeError is raised. The issue is that the
websockets.connect call is an awaitable rather than a coroutine.

asyncio.ensure_future did not gain support for awaitables until 3.5.2.
This patch allows 3.5.0 and 3.5.1 to connect regardless of their python
version.
2017-05-09 20:35:18 -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
d534a0989e Properly cleanup of VoiceClients in cache. 2017-04-18 04:09:33 -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
cadf6960b7 Use create_future wrapper for initially created Future. 2017-04-12 19:55:01 -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
e5c5695399 Proper recursion when launching shards. 2017-04-07 23:23:48 -04:00
fd62c8a4f1 Aggregate shard closing futures instead of doing them sequentially. 2017-03-21 03:52:24 -04:00
5461bfb475 Check if we're closed before attempting to do a reconnect. 2017-03-21 03:32:09 -04:00
58fa5fdc9a Add experimental reconnection logic. 2017-02-15 19:10:32 -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
e77012f4d9 Make all public is_ functions into methods instead of properties. 2017-01-29 20:53:17 -05:00
e1aaf74fa7 Add option to disable auto member chunking. 2017-01-23 07:07:42 -05:00
ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
898a05d5ea Fix AutoShardedClient docstring. 2017-01-16 16:37:53 -05:00
93d267cd2b Remove extraneous prints. 2017-01-08 02:08:38 -05:00
92c1637921 Allow overriding the shard_ids used for initial shard launch. 2017-01-08 02:05:21 -05:00