-
-
Notifications
You must be signed in to change notification settings - Fork 315
Add Inline Replies in response to #676 #704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add ReferencedMessage Property to DiscordMessage - Extracted Method Populating DiscordMessage in OnMessageCreateEventAsync - Populated the ReferencedMessage Property when it wasn't null in DiscordMessage.
…cessary files, but the reference is serialized no matter what, making it impossible to actually send regular messages.
… bit unclean. I'll clean it up hopefully
…great, but it's something.
…replies without having to duplicate a class. Also removes the need for casting. Thanks, Wam <3 I'm tired lmao
… which defaults to false, as per the API.
…Reference, as it previously attempted to send a null channel id otherwise, causing the API to treat it as a reply, throwing a 400 in response.
- Fix nit in naming which used underline case instead of camel case - Allow for reference messages to update their user and member as well - Add Reply MessageType to MessageType enum - Extract message population from PrepareMessage to a helper method which can then be used for both the Message and the ReferencedMessage
| public Task<DiscordMessage> RespondAsync(string content = null, bool isTTS = false, DiscordEmbed embed = null, IEnumerable<IMention> mentions = null) | ||
| => this.Message.RespondAsync(content, isTTS, embed, mentions); | ||
| public Task<DiscordMessage> RespondAsync(string content = null, bool isTTS = false, DiscordEmbed embed = null, | ||
| IEnumerable<IMention> mentions = null, ulong? message_id = null, bool mention = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I said to include a message id rather than a full message object, but looking back I am not sure that was a good idea on my part. I think this should be changed to a DiscordMessage object, but any opinions against this are welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run into a lot of cases where I have a message ID from somewhere else (eg. a database lookup) and don't have a full DiscordMessage object on hand. At the moment it seems the only way to create a DiscordMessage object is to get it through the REST client, which would make an unnecessary API call just to get a wrapped object.
(I would also welcome ways to create the model objects from other data sources but that's way out of scope for this PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're able to get it from the DiscordClient's message cache though right? The main reason I am against just using IDs is due to consistency because most of our other methods require a full object. IDs would also still be able to be used with the DiscordRestClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if it's a message that's not in the message cache. I turn the message cache off entirely in my bot because it's more or less useless at scale, and it frequently deals with messages that are old enough to be long out of the cache anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. We'll have to rework how we handle passing complete objects to REST, but that would be out of scope for this PR.
DSharpPlus/Clients/DiscordClient.cs
Outdated
| public Task<DiscordMessage> SendMessageAsync(DiscordChannel channel, string content = null, bool isTTS = false, | ||
| DiscordEmbed embed = null, IEnumerable<IMention> mentions = null, ulong? replyMessageId = null, bool mention = false) | ||
| => this.ApiClient.CreateMessageAsync(channel.Id, content, isTTS, embed, mentions, replyMessageId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't use the mention bool here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops
| /// <exception cref="Exceptions.BadRequestException">Thrown when an invalid parameter was provided.</exception> | ||
| /// <exception cref="Exceptions.ServerErrorException">Thrown when Discord is unable to process the request.</exception> | ||
| public Task<DiscordMessage> SendMessageAsync(string content = null, bool tts = false, DiscordEmbed embed = null, IEnumerable<IMention> mentions = null) | ||
| public Task<DiscordMessage> SendMessageAsync(string content = null, bool tts = false, DiscordEmbed embed = null, IEnumerable<IMention> mentions = null, ulong? message_id = null, bool mention = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the name doesn't match the conventions used elsewhere in the file
I'm pretty sure this is the case in other places I just didn't look long enough to find all of them.
|
This is a chonker, so I'll be reviewing this one around Christmas, I'd like a summary of answers to the following questions:
|
…uest. Creating a message reference will return null if the channel's Id is null Added replies to uploading files
…uest. Creating a message reference will return null if the channel's Id is null Added replies to uploading files
Co-authored-by: Prof Doofenshmirtz <jmm15f@acu.edu>
| /// Message when a user replies to another user | ||
| /// </summary> | ||
| Reply = 19, | ||
| Reply = 19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I really forget about this? 🤦🏽♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait I didn't even author this. I'm blind
| }; | ||
|
|
||
| var channel = client.InternalGetCachedChannel(channelId); | ||
| if (channelId.HasValue) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check doesn't make sense, and a message reference can still be built with a message id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait is the channel Id nullable? I guess I didn't check, or misread what you said when I asked when about how to go about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- channel_id is optional when creating a reply, but will always be present when receiving an event/response that includes this data model.
If it's null, assume it's the message's own channel ID.
| /// <summary> | ||
| /// Gets the Reply Message ID. | ||
| /// </summary> | ||
| public ulong? ReplyID { get; private set; } = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReplyId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been completed
| /// <param name="messageID">The ID of the message to reply to.</param> | ||
| /// <param name="mention">If we should mention the user in the reply.</param> | ||
| /// <returns></returns> | ||
| public DiscordMessageBuilder WithReply(ulong messageID, bool mention = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
messageId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been completed
|
Does it not print that exception to the console? Looks like the debugger output to me (it's showing threads starting and stopping), and even in Rider the debugger output simply says an exception happens, but the stack trace is in the console |
- Always provide mentions, defaulting to an empty array - Role mentions go based off `mention_roles` supplied by Discord - Message builder now supplies a `RepliedUserMention` if set to mention, which may or may not be necessary. - Added a test command to validate that mentions are preserved and `Mentioned______` only returns mentions that discord identifies (that is, mentions that "ping"). This should address a long-time bug introduced by DSharpPlus#704, which was not fixed in 932, nor identified in DSharpPlus#837.
* Fix reply mention oddities * Leave it to me to almost ship a faulty PR * Fix replies with other people * Fix role mentions * Apply accessor and add space * Fix replies - Always provide mentions, defaulting to an empty array - Role mentions go based off `mention_roles` supplied by Discord - Message builder now supplies a `RepliedUserMention` if set to mention, which may or may not be necessary. - Added a test command to validate that mentions are preserved and `Mentioned______` only returns mentions that discord identifies (that is, mentions that "ping"). This should address a long-time bug introduced by #704, which was not fixed in 932, nor identified in #837. * Revert to Mentions.All and merge origin into local
* Add ReferencedMessage's to DiscordMessage - Add ReferencedMessage Property to DiscordMessage - Extracted Method Populating DiscordMessage in OnMessageCreateEventAsync - Populated the ReferencedMessage Property when it wasn't null in DiscordMessage. * Added `message_reference` to `RestChannelPayloads.cs`, and updated necessary files, but the reference is serialized no matter what, making it impossible to actually send regular messages. * Got replies to work by casting to the appropriate type, though it's a bit unclean. I'll clean it up hopefully * Just wanted to make sure I committed what I currently have. It ain't great, but it's something. * Made `InternalDiscordMessageReference#ChannelId` nullable to support replies without having to duplicate a class. Also removes the need for casting. Thanks, Wam <3 I'm tired lmao * Fixed a param not being nullable ulong, and added toggleable mention, which defaults to false, as per the API. * add `NullValueHandling.Ignore` to channelId in InternalDiscordMessageReference, as it previously attempted to send a null channel id otherwise, causing the API to treat it as a reply, throwing a 400 in response. * Add way for referenced messages to be referenced from cache * Add Reference Messages to GetMessageAsync and GetMessages - Fix nit in naming which used underline case instead of camel case - Allow for reference messages to update their user and member as well - Add Reply MessageType to MessageType enum - Extract message population from PrepareMessage to a helper method which can then be used for both the Message and the ReferencedMessage * Correct "this" usage and null checks * Move Populate methods to the DiscordClient class * Changed the message reference creation behavior as per @Neuheit's request. Creating a message reference will return null if the channel's Id is null Added replies to uploading files * Changed the message reference creation behavior as per @Neuheit's request. Creating a message reference will return null if the channel's Id is null Added replies to uploading files * Update DSharpPlus/Enums/MessageType.cs Co-authored-by: Prof Doofenshmirtz <jmm15f@acu.edu> * Removed value check on channelId when constructing a new DiscordMessage reference * Reapply Replies with new Message Builder * Tweak message_create and message_update events to not blow up * Suggestion made by @Kiritsu * Fixed excessive whitespace. Co-authored-by: jmmarsde <jmmarsde@ncsu.edu> Co-authored-by: Prof Doofenshmirtz <jmm15f@acu.edu> Co-authored-by: fireflamemm <johnswork15@gmail.com> Co-authored-by: Neuheit <38368299+Neuheit@users.noreply.github.com> Co-authored-by: Jeffrey Ladd <jladd@Jeffreyladd.net>
* Fix reply mention oddities * Leave it to me to almost ship a faulty PR * Fix replies with other people * Fix role mentions * Apply accessor and add space * Fix replies - Always provide mentions, defaulting to an empty array - Role mentions go based off `mention_roles` supplied by Discord - Message builder now supplies a `RepliedUserMention` if set to mention, which may or may not be necessary. - Added a test command to validate that mentions are preserved and `Mentioned______` only returns mentions that discord identifies (that is, mentions that "ping"). This should address a long-time bug introduced by #704, which was not fixed in 932, nor identified in #837. * Revert to Mentions.All and merge origin into local

Summary
Addresses #676. Adds Inline Replies to messages.
Details
In order to address recent changes to the Discord API which added inline replies this PR is to add replies for use by the client. This also adds a way to parse the payloads from Discord which contain ReferencedMessage which is the official way to get messages in V8. In V6 this requires using the Reference to get the message. This PR also adds the message replied to into the cache if it isn't already there.
Changes proposed
Notes
N/A