Replies: 1 comment 1 reply
-
I'm not really a fan of using checks along side with events. The use cases for it are rather slim in my opinion and don't add too much compared to actually inlining it with the callback body. If someone had something that was done repeatedly in the callback body then they are free to use an actual pure decorator to do this. Part of the reason I'm subscribing to this event object design is a reason not mentioned: it allows me to move some of this stuff over to native code where it's easier to construct these objects and blast them to Python. Adding checks into the mix for this complicates that design space a bit more for me. Passing the class to the decorator rather than operating on using names constitutes as a rather hard breaking change that would be non-trivial to migrate to. While I am a proponent of doing breaking changes I also don't want to overly break all clients. This approach would also need to be adapted for the events defined within the class pattern which I think is better and allows for cleaner code. The name approach allows for seamless overriding of defaults, for example a user right now is able to override |
Beta Was this translation helpful? Give feedback.
-
A class per event type
I'm thinking about how dpy 2.0 is planned to use a single event payload object for all events. I noticed that Telethon does a similar thing:
Here events.NewMessage implements a base class for all event types.
We don't need the constructor parameters for NewMessage so we can get rid of the nested class too, which, in d.py might look like this:
(It's also assumed that by the time 2.0 is finalized, so will Discord's new reply system 😛)
I like this approach for a few reasons:
Bot.dispatch
is currently undocumented because namespace collisions between dpy events and user-defined events are undesired. Classes are namespaced by their module which neatly solves this issue.Bot.listen
could have a signature specified as follows:Sadly
event: GuildLeave
also passes mypy on the last line, so eh, this isn't too worth considering.include_socket_response=True
in order to allow event handlers to opt-in to using undocumented or unsupported gateway features.Checks for events
Features such as
@commands.is_owner
do not need to be unique to Commands. Caveat: I do not have any good motivating use cases for reusable checks on event handlers.Beta Was this translation helpful? Give feedback.
All reactions