Add warnings for when the heartbeat is blocked for a long time and when
the websocket latency is excessively high. These indicate problems with
blocking the event loop and/or insufficient computing resources to keep
up with the demand.
Add long_description_content_type in setup.py, fix incorrectly
matched up title underlines in README.rst, and fix incorrect entry in
MANIFEST.in that was forgotten when the README was renamed in 06296bf.
Remove the old and slow Member._copy implementation that was left over
by accident in 095f0ec. Since it was defined later it overrode the new
implementation and rendered it moot.
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).
Use bare raise statement when reraising the exception that occured, and
remove unused exception variables. Also remove a pointless exception
handler in discord.opus.
The method log of Logger has never been documented as being a part of
the standard logging module. It was renamed to warning when the module
was included in the standard library, but the old name was kept for
backward compatibility.
Change the behaviour of handling iterable command_prefix types to not
silently ignore falsy prefixes and unify behaviour for all iterable
types. Add special handling of a possible TypeError in both get_prefix
and get_context for when the prefix is a different type from what is
expected.
Fix the name for the other's type when raising TypeError being
incorrectly written as __class__name instead of __class__.__name__ in
the is_subset and is_superset methods of the Permissions class. This
was introduced at the creation of these methods in 21c88cf.
Logging in with an invalid token would throw a TypeError due to improper
passing of arguments to HTTPClient._token. Fix by properly passing the
keyword only bot argument.
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.
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.
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.
Change the description of on_error to reflect that exceptions are logged
and not output by default. Add a note about not configuring logging
causing exceptions to be silently ignored in handlers in the API. And
add some more explanations and a simpler configuration example to the
logging description.
Without setting up the logging module, a god number of error conditions
and warnings will never be output by the library. This is a common
pitfall to forget and it's not documented good enough the consequences
of not setting up the logging module when developing applications with
this library.
Check and handle login failure in the examples provided for using this
library. This is a common error condition that should be handled by any
script using this library.
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.
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.
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.
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.
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.
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.
_keep_alive_handler would set up another keep alive after the first one
by creating a new threading.Timer object, but Client would only keep
track of the first timer object. Thus casing the keep alive to continue
running after Client.logout calls cancel() on it's timer object, as it
no longer references the actual timer object waiting for the keep alive.
Fix by replacing _keep_alive_handler with a threading.Thread subclass
that sends keep_alives of the given interval and exits when its stop
event is set.