Discord-Net-Labs / Discord.Net-Labs

An experimental fork of Discord.Net that implements the newest discord features for testing and development to eventually get merged into Discord.Net
https://labs.discordnet.dev
MIT License
156 stars 42 forks source link

Fixed Integration model from GuildIntegration and added INTEGRATION gateway events #453

Closed FeroxFoxxo closed 2 years ago

FeroxFoxxo commented 2 years ago

This PR introduces the INTEGRATION_CREATED, INTEGRATION_UPDATED and INTEGRATION_DELETED events.

It also fixes some rather big changes to the integration model, which I assume is due to a change in the object being sent by Discord? I noticed GuildIntegration referenced a lot in the code, rather than Integration.

Since the integration part of the API isn't used like, at all, I'm not sure if anyone would be affected by these changes, but nevertheless, they are breaking! Although looking at the old models I don't think they've even worked in the past few years..-

Some questions, as this is my first PR:

I can add caching of integrations, but as this is not sent to the client on the GUILD_CREATE event, we would have to run a second RESTful request on getting this information, say; if the integration intent is enabled. As such, this is a point that should probably be discussed further, and thus I'm currently returning a guild object, the id of the integration, and the optional id of the application on the INTERACTION_DELETED event, as this information isnt stored anywhere.

Secondly, I saw that Optional<ulong> threw an error for RoleId in the Integration model I had made, as Discord returns null for this in the JSON on INTEGRATION_CREATION. Is this a bug on our side, by means of a JSON type converter, or the API? The API does state this can be optional, hence why I used the related Optional<> type. The issue stems from reader.value being null on the ulong type converter that Optional runs. By any means, I have since changed this to ulong? in my push here.

Thirdly, is there a way to modify integrations anymore? I can't seem to find it in the docs, although it seems it was once supported as a part of the GuildIntegration class that we were using prior...

Note: there are two separate types of integrations sent in the integration object: Discord and Twitch/Others. Discord integrations do not contain a big chunk of fields in Integration, hence why there are so many optional fields, as is specified per the Discord API docs. I also noticed the docs had stated the IntegrationAccount as returning a string for its ID. This is due to platforms like YouTube, whose support was added in 2020, not using ints to store IDs like Twitch does, and this code being untouched since 2016.

There may be some bugs as this is my first large PR, so bear with me :P

csmir commented 2 years ago

Please rebase this PR towards dnet main, this will not be merged into dnet from labs.

FeroxFoxxo commented 2 years ago

Closing to rebase to DNET!