155 Commits

Author SHA1 Message Date
Rapptz
351bb1927a Fix crashing with wonky TYPING_START events.
Fixes #1439
2018-07-20 04:15:58 -04:00
khazhyk
9d301f7cae Store guild, unavailable tuple in ready as well
This should fix userbots.

Fixes: 74380cd ("don't drop guild_available/join before ready")
2018-06-30 23:26:33 -07:00
khazhyk
74380cd72a don't drop guild_available/join before ready
large guilds that recieved GUILD_CREATE events prior to READY would
never dispatch guild_available/join. This is inconsistent with
smaller guilds and makes these events unreliable. Dispatch the
"delayed" guilds after they've been chunked, prior to ready.
2018-06-29 21:48:31 -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
6b75179c1f Remove emojis from cache if they're removed from a guild. 2018-05-19 17:07:45 -04:00
Rapptz
56650ae7c2 Change raw events to use slotted data models instead of parameters.
This allows for internal changes in Discord to not cause a breaking
change every time something changes.

Also implements #1214 which adds guild_id to every event where
applicable.

This is a breaking change.
2018-04-14 02:23:38 -04:00
Rapptz
3cb6ac152e Userbots do not have a DM cache cap limit. 2018-04-02 00:42:14 -04: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
Rapptz
1c215cfbbe Don't cache webhook users.
Fixes #1101
2018-02-24 17:37:37 -05:00
Gorialis
04d9dd9c0d Change PartialReactionEmoji to PartialEmoji, add a PartialEmojiConverter 2018-01-06 17:32:25 -05:00
Rapptz
53b4890435 Add category support.
This adds:

* CategoryChannel, which represents a category
* Guild.by_category() which traverses the channels grouping by category
* Guild.categories to get a list of categories
* abc.GuildChannel.category to get the category a channel belongs to
* sync_permissions keyword argument to abc.GuildChannel.edit to sync
  permissions with a pre-existing or new category
* category keyword argument to abc.GuildChannel.edit to move a channel
  to a category
2017-09-13 09:44:36 -04:00
Rapptz
1367877d36 Fix crashing for now when a category is created.
A full implementation will come later.
2017-09-08 21:30:25 -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
b88cc8156c Accidentally left a print statement. 2017-07-05 00:48:27 -04:00
Rapptz
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
Rapptz
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
Rapptz
c1dad43f9d Downgrade PartialReactionEmoji to str in non-raw reaction events. 2017-06-09 22:01:31 -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
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
Rapptz
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
Rapptz
5a56e3fda1 Don't dispatch on_voice_state_update when Member is not found. 2017-05-22 22:28:19 -04:00
Rapptz
3436792614 Allow setting a presence upon logging in. 2017-05-20 15:19:47 -04:00
Rapptz
1626ade67d Split on_channel_pins_update as well. 2017-05-05 21:37:38 -04:00
Rapptz
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
Rapptz
c9565e57d3 Make sure that the chunker task only runs once. 2017-05-01 22:34:24 -04:00
Rapptz
10453d6718 Add Client.get_emoji to get an Emoji from an ID. 2017-04-30 02:53:05 -04:00
Rapptz
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
Rapptz
1519a6fefa Fix some linting errors. 2017-04-22 04:50:31 -04:00
Rapptz
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
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
38fd0928df Don't clear state when READY is reached for auto sharded clients. 2017-04-16 02:32:23 -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
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
Rapptz
bcfb31779d Fix KeyError in certain logging cases. 2017-04-07 23:22:44 -04:00
Rapptz
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
Rapptz
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
Rapptz
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
Rapptz
46951e27f7 Revert "Reference the ConnectionState by weakref."
This reverts commit 730a0e2d5375a5c49bcc2a146f0cde1e7dc85f24.
2017-03-24 21:44:33 -04:00
Rapptz
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
Rapptz
a0cdb19c5f Eventual consistency fixes. 2017-03-21 03:16:30 -04:00
Rapptz
9c6d9f1a84 Remove call handling for now. 2017-03-13 17:07:33 -04:00
Rapptz
ead18e3948 Fix issue with members not copying correctly. 2017-03-05 07:48:15 -05:00
Rapptz
e78a5c0643 Remove remaining voice_member tracking. 2017-02-28 18:29:27 -05:00
Rapptz
f6fcb62c7b Check for PrivateChannel before GuildChannel in Client.get_channel 2017-02-25 20:56:09 -05:00
Rapptz
29f676c42e Wrap asyncio.wait into a saner alternative that raises TimeoutError.
Fixes #494
2017-02-25 00:03:43 -05:00
Rapptz
b8727fd463 Fix Client.emojis returning a list of IDs. 2017-02-21 08:38:06 -05:00
Rapptz
0dac5e3139 Add Client.emojis to get all emojis.
This removes the older get_all_emojis generator.
2017-02-10 16:43:33 -05:00
Rapptz
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
Rapptz
b876133e87 Add compatibility shim for asyncio.Future creation.
Should provide better support for uvloop.
2017-01-25 21:38:50 -05:00