368 Commits

Author SHA1 Message Date
Dante Dam
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
Hornwitser
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
Hornwitser
633192b3cd [lint] Replace equality comparisons to singletons
Restrict the values accepted by comparisons with booleans to be actual
booleans.

Minor breaking of undocumented behaviour in permissions; the value to
set bits to must be booleans (as indicated by the type error thrown).
2018-11-24 22:17:57 -05:00
Hornwitser
fa46b07db1 [lint] Rename exception variables to exc
Use the more explicit (and common) exc instead of e as the variable
holding the exception in except handlers.
2018-11-24 22:17:57 -05:00
Rapptz
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
Rapptz
095f0ec2fc Optimise some member and user related routines.
* Skip user update if possible
* Drop copy.copy in favour of manual copy

Credit to Hornwitser for these findings.
2018-09-24 22:50:05 -04:00
Rapptz
3d03dbc451 Change internal role storage in Guild to a dict instead of a list.
This adds the following APIs:

* Guild.get_role

This removes the following APIs:

* Guild.role_hierarchy

To compensate for the removed APIs, Guild.roles is now a sorted list
based on hierarchy. The first element will always be the @everyone
role.

This speeds up access at the cost of some memory, theoretically.
2018-09-24 21:08:48 -04:00
Jeremy Zhang
d092c6635b Fix webhook_update from code review 2018-09-15 18:28:57 -04:00
Jeremy Zhang
17f9916b03 Simple parser for WEBHOOKS_UPDATE 2018-09-15 18:28:57 -04:00
Bryan Forbes
b6824c073e Ensure large guilds are properly appended to the ready state guild list 2018-08-28 23:50:55 -04:00
Hornwitser
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
Hornwitser
119c5a0618 [lint] Remove unused variables
Left over from various refactoring and rewrites.
2018-08-22 21:43:51 -04:00
Hornwitser
d58fc0ccee [lint] Remove unused imports
Left over from various refactoring and rewrites.
2018-08-22 21:43:50 -04:00
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