kord icon indicating copy to clipboard operation
kord copied to clipboard

Common ReactionEvent interface

Open MayaChen350 opened this issue 7 months ago • 11 comments

I added an interface for ReactionAddEvent and ReactionRemoveEvent to remove code duplication and allow better Generics

Thing is, in one of my projects, I ended up doing a class for both of them because they're not bound by anything I could use as generic.

/** Abstraction class making using both type of events easier by sharing common properties and methods. **/
class ReactionEvent(
    private val addEvent: ReactionAddEvent? = null,
    private val removeEvent: ReactionRemoveEvent? = null
) {
    val emoji = addEvent?.emoji ?: removeEvent!!.emoji
    val guild = addEvent?.guild ?: removeEvent!!.guild
    suspend fun getMessage() = addEvent?.getMessage() ?: removeEvent!!.getMessage()
    suspend fun getUserAsMember() = addEvent?.getUserAsMember() ?: removeEvent!!.getUserAsMember()
    suspend fun getUser() = addEvent?.getUser() ?: removeEvent!!.getUser()
    suspend fun getRole(id: Snowflake) =
        addEvent?.getGuildOrNull()?.getRole(id) ?: removeEvent!!.getGuildOrNull()!!.getRole(id)
}

So basically, with that PR I'm grouping both Reaction events classes together to make things easier with an interface Also I removed what I thought was unnecessary to keep after since both ReactionAddEvent and ReactionRemoveEvent had very similar code

Pretty simple, but efficient hopefully!

MayaChen350 avatar May 23 '25 18:05 MayaChen350

For some reason I can't approve this PR for the CI, but you need to run gradlew apiDump

DRSchlaubi avatar May 23 '25 19:05 DRSchlaubi

Is it a binary incompatible change to move functions to a parent class?

DRSchlaubi avatar May 23 '25 22:05 DRSchlaubi

I don't think so, but just to make sure, what do you mean by that?

MayaChen350 avatar May 23 '25 22:05 MayaChen350

that code compiled against a previous version will continue to work

and it is a change since the function signature changes, in this case there should be a deprecated version on the class, however that will make migrating kinda hard

/cc @lukellmann

DRSchlaubi avatar May 23 '25 22:05 DRSchlaubi

Actually now that I think about it, I think the signatures would change since they're linked to the interface now but still are actually linked to the class somehow? Would they be the same as before if the methods would just be overriding the interface's instead?

MayaChen350 avatar May 23 '25 22:05 MayaChen350

Nah prvsly it was called ReactionAddEvent.x and now it's ReactionEvent.x

DRSchlaubi avatar May 23 '25 22:05 DRSchlaubi

Is it a binary incompatible change to move functions to a parent class?

no, it isn't

lukellmann avatar May 24 '25 10:05 lukellmann

and it is a change since the function signature changes, in this case there should be a deprecated version on the class, however that will make migrating kinda hard

the signature does not include the class the method is in

lukellmann avatar May 24 '25 10:05 lukellmann

Is it a binary incompatible change to move functions to a parent class?

no, it isn't

why did I belive AI

DRSchlaubi avatar May 24 '25 11:05 DRSchlaubi

Hi? This was kinda left out idk

MayaChen350 avatar Jun 26 '25 04:06 MayaChen350

I can see that this repo is able to make PRs rot for 3 years but I don't know

My PR didn't seem like such a breaking change. It's almost ridiculous that it has been ignored for that long

If this has been fixed, or if this PR has become useless/impossible to merge now, I guess this PR can at least be closed

MayaChen350 avatar Nov 03 '25 04:11 MayaChen350