Commit Graph

142 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
b88cc8156c Accidentally left a print statement. 2017-07-05 00:48:27 -04:00
3bd0c2120c Implement a LRU cache for private channels.
Another fix related to the discord issue[1].

[1]: https://github.com/hammerandchisel/discord-api-docs/issues/184
2017-07-04 20:02:17 -04:00
169f3a8322 Don't unnecessarily re-create private channels.
New API change[1] will make it so CHANNEL_CREATE will keep getting
sent for private channels, so might as well avoid the overhead of
constantly creating the channel if we can avoid it.

[1]: https://github.com/hammerandchisel/discord-api-docs/issues/184
2017-07-04 20:02:11 -04:00
c1dad43f9d Downgrade PartialReactionEmoji to str in non-raw reaction events. 2017-06-09 22:01:31 -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
d239cc2666 Implement "partial" message events.
These are events that get triggered regardless of the state of the
message cache. Useful for getting data from before the bot was booted.
2017-06-09 18:36:59 -04:00
a47ded6e49 Don't expose Client.messages
Not entirely sure why it was exposed in the first place. Most uses with
it essentially boiled down to mis-usage when they meant to use the
/messages endpoint (via Client.logs_from or Messageable.history) or
complaining about the partial data woes that came from it.
2017-05-26 07:17:52 -04:00
5a56e3fda1 Don't dispatch on_voice_state_update when Member is not found. 2017-05-22 22:28:19 -04:00
3436792614 Allow setting a presence upon logging in. 2017-05-20 15:19:47 -04:00
1626ade67d Split on_channel_pins_update as well. 2017-05-05 21:37:38 -04:00
322c70fda9 Rework some events to make more sense.
This is a breaking change.

1. Change on_guild_emojis_update to have 3 arguments.
    - The first parameter is now the guild object
2. Remove on_channel_create, on_channel_delete, and on_channel_update
	- They are now split into two.
	- on_guild_channel_[create|delete|update]
	- on_private_channel_[create|delete|update]
3. Change on_member_ban to allow User.
    - (member) -> (guild, user)
    - user can also be a Member
2017-05-05 20:47:25 -04:00
c9565e57d3 Make sure that the chunker task only runs once. 2017-05-01 22:34:24 -04:00
10453d6718 Add Client.get_emoji to get an Emoji from an ID. 2017-04-30 02:53:05 -04:00
92d55077aa Don't set VoiceClient.channel to None when VOICE_STATE_UPDATE says so.
Sometimes VOICE_STATE_UPDATE gives us a channel_id: null payload and
we would end up clearing the VoiceClient.channel state along with
it.
2017-04-26 04:52:49 -04:00
1519a6fefa Fix some linting errors. 2017-04-22 04:50:31 -04:00
f9c2ac9d25 Better handling of VOICE_SERVER_UPDATE.
This now sort of respects "Awaiting Endpoint..." waiting. I haven't
actually tested out this case since it's hard to get it. However this
new code does work with the regular connection flow.
2017-04-18 19:05:34 -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
38fd0928df Don't clear state when READY is reached for auto sharded clients. 2017-04-16 02:32:23 -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
982308da3c Use global user cache to fetch reaction event data.
Also make sure it isn't dispatched unless the data meets the integrity
checks (i.e. not None).
2017-04-09 21:37:49 -04:00
bcfb31779d Fix KeyError in certain logging cases. 2017-04-07 23:22:44 -04:00
7f58853e3a Keep track of Emoji instances myself.
WeakValueDictionary cleans up too late and brings too little benefit.
Also clean up the state when the first READY is encountered for
AutoShardedClient and when any READY is encountered in regular Client.
2017-03-29 04:36:06 -04:00
cac84e517b Always overwrite Emoji references in the state.
There is potential that when recreating the Emoji list in the
GUILD_EMOJIS_UPDATE event would just fetch from cache and the element
in cache having an out of date Guild reference. This Guild reference
will be kept alive for longer than it should be.

By always overwriting the Emoji reference, this problem goes away.
2017-03-26 18:43:57 -04:00
aef170d7e0 Fix memory leak by holding on to Emoji references weakly.
The library had a memory leak in the case using the global emoji cache.
When the bot would leave the guild, the Emoji would maintain a strong
reference to the Guild keeping them alive along with the entire state
associated with it.
2017-03-24 21:46:32 -04:00
46951e27f7 Revert "Reference the ConnectionState by weakref."
This reverts commit 730a0e2d53.
2017-03-24 21:44:33 -04:00
730a0e2d53 Reference the ConnectionState by weakref instead of a strong reference.
Hopefully this means when the bot has some lingering object for
whatever reason, the memory doesn't double due to it having a strong
reference to an outdated connection state.
2017-03-22 00:02:50 -04:00
a0cdb19c5f Eventual consistency fixes. 2017-03-21 03:16:30 -04:00
9c6d9f1a84 Remove call handling for now. 2017-03-13 17:07:33 -04:00
ead18e3948 Fix issue with members not copying correctly. 2017-03-05 07:48:15 -05:00
e78a5c0643 Remove remaining voice_member tracking. 2017-02-28 18:29:27 -05:00
f6fcb62c7b Check for PrivateChannel before GuildChannel in Client.get_channel 2017-02-25 20:56:09 -05:00
29f676c42e Wrap asyncio.wait into a saner alternative that raises TimeoutError.
Fixes #494
2017-02-25 00:03:43 -05:00
b8727fd463 Fix Client.emojis returning a list of IDs. 2017-02-21 08:38:06 -05:00
0dac5e3139 Add Client.emojis to get all emojis.
This removes the older get_all_emojis generator.
2017-02-10 16:43:33 -05:00
554ae196d3 Add missing int casts in many different events in the state.
Also remove redundant role parsing in Member._update_roles.
2017-01-28 08:14:43 -05:00
b876133e87 Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
2017-01-25 21:38:50 -05:00
e1aaf74fa7 Add option to disable auto member chunking. 2017-01-23 07:07:42 -05:00
d206ee792b Fix issue with user bots chunking unavailable guilds. 2017-01-21 16:25:51 -05:00
ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
4c981ee631 Add support for relationships. 2017-01-20 19:28:43 -05:00
fa384f2114 Make ClientUser separate from a regular User.
This removes Client.edit_profile in favour of ClientUser.edit.
2017-01-19 19:37:11 -05:00
f465f88d81 Reimplement Guild.me property without patching it in. 2017-01-18 19:54:47 -05:00
c635ce2526 Simple parser for CHANNEL_PINS_UPDATE 2017-01-09 03:52:44 -05:00
92c1637921 Allow overriding the shard_ids used for initial shard launch. 2017-01-08 02:05:21 -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
d54d7f7ac0 Fix variable shadowing in READY parsing. 2017-01-05 07:03:56 -05:00
808a05ff2d Move global user cache to a WeakValueDictionary. 2017-01-04 05:16:59 -05:00
c863d93f69 Fix bug that made member roles go missing. 2017-01-03 20:17:58 -05:00
7690455b21 Make User and Member messageable. 2017-01-03 09:52:12 -05:00