565 Commits

Author SHA1 Message Date
Rapptz
d14bffcd96 Rename InvaldiDestination to a generic ClientException. 2015-10-27 19:02:12 -04:00
Rapptz
6ae6bd8e6d Remove InvalidEventName exception due to it being unused 2015-10-27 18:03:51 -04:00
Rapptz
dd2e08e185 Add support for passing in Object to methods. 2015-10-27 17:39:51 -04:00
Rapptz
a0073c734e Split data classes into more files. 2015-10-27 16:23:20 -04:00
Rapptz
616f2bb4e9 Remove the name from logging.
Fixes #28.
2015-10-25 23:17:02 -04:00
Rapptz
60dfd04439 Check if member is in list for GUILD_MEMBER_REMOVE. 2015-10-25 23:08:06 -04:00
Rapptz
2938d0cfcf Don't update member.roles in add/remove_roles. 2015-10-24 23:36:12 -04:00
Rapptz
5efddaf35d Support unavailable servers. 2015-10-24 05:10:58 -04:00
Rapptz
f018895f2c Fix documentation warnings. 2015-10-22 22:20:36 -04:00
Rapptz
6981c51e0a Change default parameter to None for Client.set_channel_permissions 2015-10-22 22:20:35 -04:00
Rapptz
6f76a5ab33 Add Client.delete_channel_permissions
Fixes #18
2015-10-22 22:20:35 -04:00
Rapptz
ec5b7bb493 Add Client.set_channel_permissions 2015-10-22 22:20:34 -04:00
Hornwitser
320cd39b6a Print to stderr in on_error
Apparently the clever hack for logging in on_error was not so clever
after all.  If logging isn't configured, by the logging modules
definition of not configured, which is root logger not having an
Handlers attached, it will call logging.basicConfig().  Which messes up
setups that define handlers for other loggers than the root logger.

Going directly to the root logger rather than using the broken
convenience methods for logger is not an option either, as logger before
Python 3.2 does not have lastResort on the root logger, and prints an
error when invoked without any handlers.

Resolve by printing tracebacks to stderr by default in on_error.
2015-10-22 22:07:50 +02:00
Rapptz
ce9a8ff75b Add note for edit_role about custom RGB colours. 2015-10-21 20:38:28 -04:00
Rapptz
d2741ca38a Better detection for the everyone role. Fixes #23. 2015-10-21 20:27:08 -04:00
Rapptz
edd3d47220 Add Client.replace_roles 2015-10-21 19:46:33 -04:00
Rapptz
6bb6a0a0a7 Add Client.add_roles and Client.remove_roles 2015-10-21 19:44:37 -04:00
Hornwitser
9ab1d041d4 Log to root logger by default in on_error
Change the default implementation of on_error to log to the root logger
instead of discord.client and clarify that the exception is being
ignored.  This ensures that a message will be output to standard error
in case the logging module has not been configured.

Also removes the argument printing for the default on_error, this is due
to them often being too long, that they could cause another exception to
be thrown, and because it sometimes causes sensitive information to be
output such as Discord tokens and session ids.  It was also possible for
the length to get in the megabyte range with exceptions thrown by
on_socket_raw_receive in READY events.
2015-10-21 01:03:25 +02:00
Rapptz
77253d7717 Fix Client.create_invite invalid method call issue. 2015-10-20 15:59:45 -04:00
Rapptz
0e106cd8c4 Change default limit for Client.logs_from to 100. 2015-10-19 08:31:28 -04:00
Rapptz
e2af5d545a Add Client.create_role to create a server-wide role. 2015-10-17 17:54:16 -04:00
Rapptz
84e9300a3d Change Client.edit_role to be less stateful. 2015-10-17 17:53:55 -04:00
Rapptz
1080941e5e on_socket_response now handles non-op 0 websocket messages. 2015-10-16 18:49:55 -04:00
Hornwitser
023e0eb1d5 Use compact encoding for json on websocket
Remove extra whitespace from json encoding used when sending messages on
the websocket.
2015-10-16 16:20:04 -04:00
Hornwitser
07adb330db Add events for sniffing the WebSocket data
Add on_socket_raw_receive and on_socket_raw_send events for sniffing the
data being received and sent on the websocket. Useful for debugging and
logging websocket messages received and sent on the link to Discord's
servers.
2015-10-16 16:20:04 -04:00
Rapptz
411b477a02 Separate colour tuple into its own class.
Also enumerate all the constant colours that Discord currently
supports.
2015-10-16 07:48:50 -04:00
Rapptz
ab2512785b Handle VOICE_STATE_UPDATE websocket events.
This adds a lot of new attributes into the Member class
such as giving a voice_channel that the user is currently connected
to. Initially there was a plan to have a voice_members attribute
in the Channel class but this proved to be difficult when it came to
actually removing users from the voice channel as the response would
return channel_id as null.

Fixes #16.
2015-10-15 01:37:55 -04:00
Rapptz
4ff7d22edd Handle GUILD_ROLE_UPDATE websocket events. 2015-10-15 01:37:55 -04:00
Rapptz
16a20e5f2f Handle GUILD_ROLE_DELETE websocket events. 2015-10-15 01:37:54 -04:00
Rapptz
9235a34916 Handle GUILD_ROLE_CREATE websocket events. 2015-10-15 01:37:54 -04:00
Rapptz
4ec052a35c Check if the server is valid during GUILD_MEMBER_REMOVE. 2015-10-15 01:37:53 -04:00
Rapptz
a130706f23 Add Client.change_status. 2015-10-14 18:54:45 -04:00
Rapptz
0b27044252 Client.send_file now properly closes the file-object. 2015-10-13 06:16:29 -04:00
Rapptz
c64420f9d3 Add role colour and hoisting to edit_role. 2015-10-13 05:39:59 -04:00
Rapptz
8b03918c3d Client.send_message can now accept a string ID as the destination. 2015-10-13 05:39:58 -04:00
littleyoshi4
1b6fe0466d Added send_file method. 2015-10-11 21:51:10 -05:00
Rapptz
6074fe0783 Client.register now takes an invite URL or class. 2015-10-11 07:28:55 -04:00
Rapptz
03d477edd8 edit_profile now returns True or False depending on success. 2015-10-11 06:42:41 -04:00
Rapptz
66c39b6151 Remove get_channel from __getattr__ in Client. 2015-10-11 05:35:10 -04:00
Rapptz
ceb9eb07d8 Use v3 of the Discord API. 2015-10-11 05:15:57 -04:00
Hornwitser
68c3fde089 Make event based handlers first class
Change Client.event decorator to assign the event handler function to
the instance it self and levarage dispatch to handle calling these
event.  Remove old _invoke_event method.
2015-10-06 19:09:16 +02:00
Hornwitser
74a06e0b79 Change behaviour of on_error
Change how the old style on_error event is called to match the new style
on_error event.  Both are now called in case an exception is raised in
an user defined event handler, and will by default print the arguments
of the event tha raised the exception and the traceback for the
exception.  In addition, overridding the on_error handler supresses this
behaviour.
2015-10-06 19:09:16 +02:00
Hornwitser
d044d7b781 Add client register API
When clicking on an invite link without having a Discord account it's
possible to create an unclaimed account for joining the conversation
quickly.  Add register() method to Client that performs and invite based
registration of an unclaimed account.
2015-10-06 19:09:16 +02:00
Hornwitser
5e952015a6 Reconnect when WebSocket dies
Check if the WebSocket connection was supposed to terminate and
reconnect to the gateway if this is not the case.
2015-10-06 19:09:16 +02:00
Hornwitser
247d1f9ed4 Make dispatch multithreading safe
Guard the execution of dispatch with a recursive thread lock.  This is
needed to make a thread safe way to send events to Client objects.  Note
that the only thread safe method is dispatch, everything else is unsafe
to call from another thread, as the thead handling the Client object
could be modifying arbitrary structures at any time.  In addition this
only keeps nasal demons away, and does not solve any of the difficult
syncronization issues that might be present.
2015-10-06 19:09:16 +02:00
Hornwitser
5e671a0d0d Move socket and connection state out of Client
Move the socket message handling and Discord connection state tracking
out of the Client class.  The WebSocket class handles the ws4py based
WebSocket to Discord, maintains the keepalive and dispatches
socket_<events> based on activity.  The ConnectionSTate class maintains
the state associated with the WebSocket connection with Discord.  In a
reconnect and switch gateway scenario this state can be kept for a
faster and less disruptive recovery.
2015-10-06 19:09:09 +02:00
Hornwitser
c47e31c82e Add new event system
Add event system based on a public dispatch method in Client.  The new
event system bases itself on two types of events, internal event
handlers and user defined event handlers.  Internal event handlers begin
with 'handle_', and user defined events begin with 'on_'.  Events are
dispatched with dispatch(event_name, *args).  The Client class should be
subclassed and the on_<event> handlers defined in it for responding to
events.  The handle_<event> handlers can the overridden to override the
behaviour of the Client class, though this is not recommended.

The subclassing method allows separation of the instance of the client
and the code that handles it.  (i.e. you don't need the instance of the
client object to define event handlers for it).  Though, the old method
of using the event decorator from the instance will still be supported.
2015-10-06 17:34:23 +02:00
Rapptz
8c1aa2ccc5 Fix bug with mentions not working. 2015-10-02 21:35:16 -04:00
Rapptz
ba62bc414e Check for 2xx range instead of specific status codes. 2015-10-02 18:37:10 -04:00
Rapptz
94e6b4a8ef Fix server attribute not being set in GUILD_MEMBER_ADD. 2015-10-02 15:58:23 -04:00