FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implemented new DiscordMessage properties by sh30801 · Pull Request #472 · DSharpPlus/DSharpPlus · GitHub

Implemented new DiscordMessage properties - #472

Merged
Emzi0767 merged 17 commits into
DSharpPlus:masterfrom
sh30801:NewMessageTypes
Oct 24, 2019
Merged

Emzi0767 merged 17 commits into
DSharpPlus:masterfrom
sh30801:NewMessageTypes

Conversation

sh30801 commented Sep 26, 2019 •
edited
Loading

Copy link
Copy Markdown
Contributor

Summary

Implemented support for several new DiscordMessage properties in addition to creating/moving a few files. This addresses issue #436.

Details

I added reference to the new activity, application, and message_reference properties sent. These objects were also each given their own class and properties.

I also added 5 new message types, that involve messages sent with nitro boosting and news channel updates to the MessageType enum, and moved the enum from the DiscordMessage class to it's own separate file inside of the Enums folder.

Changes proposed

  • Added 3 new properties to the DiscordMessage class.
  • Each of these properties were given their own class, for support with their properties.
  • Added 5 new message types
  • Moved the MessageTypes enum into the Enums folder.

Note

In terms of the Author property not being handled properly, I didn't find it necessary to change because there is a property to check whether the message is a webhook or not.

uwx commented Sep 26, 2019 •
edited
Loading

Copy link
Copy Markdown
Contributor

Thanks lad but just a few things:

  • DiscordMessageApplication: shouldn't this just be an instance of Application? If not, perhaps Application should inherit from it, and it should be untied from messages (it has the more complete definition)
  • DiscordMessageApplication: does not correctly initialize the Discord property.
  • DiscordMessageReference: is there no better way to expose this? We want to avoid exposing solely IDs. Guilds and channels can be looked up on the client with 100% guarantee (unless you count guilds in different shards). DISREGARD THAT, I SUCK COCKS Messages may or may not be looked up from the cache.

Copy link
Copy Markdown
Contributor

Guilds and channels can be looked up on the client with 100% guarantee

Is that true here? Can message references not reference guilds the current user isn’t a part of?

uwx commented Sep 26, 2019

Copy link
Copy Markdown
Contributor

Guilds and channels can be looked up on the client with 100% guarantee

Is that true here? Can message references not reference guilds the current user isn’t a part of?

You raise a great point, I did not take that into consideration.

sh30801 commented Sep 26, 2019

Copy link
Copy Markdown
Contributor Author

Thanks lad but just a few things:

* DiscordMessageApplication: shouldn't this just be an instance of Application? If not, perhaps Application should inherit from it, and it should be untied from messages (it has the more complete definition)

I don't feel it should inherit from DiscordApplication because there would be many properties that wouldn't get used if it is sent as a message property.

* DiscordMessageApplication: does not correctly initialize the Discord property.

How so?

* DiscordMessageReference: is there no better way to expose this? We want to avoid exposing solely IDs. Guilds and channels can be looked up on the client with 100% guarantee (unless you count guilds in different shards). Messages may or may not be looked up from the cache.

I thought about this, but I chose to keep these just as IDs because the client would need to be in the same server as the original message (for a news channel) in order for it not to be null. Maybe when more guilds have access to news channels it would make sense but I just don't see the point of adding it when news channels are still experimental.

uwx commented Sep 26, 2019

Copy link
Copy Markdown
Contributor

I don't feel it should inherit from DiscordApplication because there would be many properties that wouldn't get used if it is sent as a message property.

I meant to inherit them the other way around.

How so?

All SnowflakeObject types must initialize the client property, via the constructor. At least for now, the deserializer cannot do this.

I thought about this, but I chose to keep these just as IDs because the client would need to be in the same server as the original message (for a news channel) in order for it not to be null. Maybe when more guilds have access to news channels it would make sense but I just don't see the point of adding it when news channels are still experimental.

Not null - skeleton objects should be used instead. That's how it works elsewhere in the lib.

sh30801 commented Sep 26, 2019

Copy link
Copy Markdown
Contributor Author

I don't feel it should inherit from DiscordApplication because there would be many properties that wouldn't get used if it is sent as a message property.

I meant to inherit them the other way around.

How so?

All SnowflakeObject types must initialize the client property, via the constructor. At least for now, the deserializer cannot do this.

I thought about this, but I chose to keep these just as IDs because the client would need to be in the same server as the original message (for a news channel) in order for it not to be null. Maybe when more guilds have access to news channels it would make sense but I just don't see the point of adding it when news channels are still experimental.

Not null - skeleton objects should be used instead. That's how it works elsewhere in the lib.

Ah I see, I'll edit those then.

sh30801 commented Sep 26, 2019

Copy link
Copy Markdown
Contributor Author

So for creating the skeleton objects, should I just always return a skeleton object for the message references? Or should I try to search through the message, guild, and channel caches and return the full object if it's there, and if not then return a skeleton object?

Copy link
Copy Markdown
Contributor

DiscordMessageApplication is the correct way of handling this, though I only glanced at the solution.

Guilds are, like everything in Discord, not 100% guaranteed, particularly in sharded scenarios.

As far as message reference goes, I think you should just make it an object with supplied data and optionally a method to fetch the message. No real point in doing much beyond that.

sh30801 commented Sep 26, 2019 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

I just wrote this in the constructor to fetch those objects from the cache or just create new objects. Don't really know how to test this without a news channel though:

internal DiscordMessageReference()
        {
            if (this.guildId.HasValue && this.client._guilds.TryGetValue(this.guildId.Value, out var g))
                this.Guild = g;

            else this.Guild = new DiscordGuild
            {
                Id = this.guildId.Value
            };

            var channel = this.client.InternalGetCachedChannel(this.channelId);

            if (channel == null)
                this.Channel = new DiscordChannel
                {
                    Id = this.channelId,
                    GuildId = this.guildId.Value
                };

            else this.Channel = channel;

            if (messageId.HasValue && this.client.MessageCache.TryGet(m => m.Id == messageId.Value && m.ChannelId == channelId, out var msg))
                this.Message = msg;

            else this.Message = new DiscordMessage
            {
                Id = this.messageId.Value,
                ChannelId = this.channelId
            };
        }

Since it's not tested I think just creating skeleton objects would be the safest option. What do you all think?

Copy link
Copy Markdown
Contributor

Since it's not tested I think just creating skeleton objects would be the safest option. What do you all think?

This looks fine, but be sure to set the .Discord property of these skeleton objects, and add them to their appropriate parent objects. Dwarfed entities aren't a fun time

sh30801 commented Sep 26, 2019

Copy link
Copy Markdown
Contributor Author

Yeah good point

…ageApplication, also rewrote DiscordMessageReference to be able to search the cache, and if no results found return a skeleton object with the provided data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL