Skip to content

Fixed Mentions in Updated Messages#1327

Merged
OoLunar merged 1 commit into
DSharpPlus:masterfrom
DWaffles:message-update-mentions-fix
Jun 17, 2022
Merged

Fixed Mentions in Updated Messages#1327
OoLunar merged 1 commit into
DSharpPlus:masterfrom
DWaffles:message-update-mentions-fix

Conversation

@DWaffles

Copy link
Copy Markdown
Contributor

Summary

This bug was brought up by Link#8313 in the Discord. Under some conditions an updated message would not properly reflect the json sent by Discord when it came to mentions.

This happened whenever a message was cached, as the returned message would not use the mention data sent by Discord. If a message was not cached, or the message cache was disabled, then the message returned was simply the updated message from Discord and would have correct mentions.

Note that other properties that can change in an update can also suffer this same fate if the data is not accessed. Obviously. (Also note I did not test other properties, but I did test this PR.)

Changes

  • Message returned by OnMessageUpdateEventAsync() now copies it's mentions from the data Discord sends.
  • Some extra comments because I get paid nothing by the line.

Test code used:

private async Task Discord_MessageUpdated(DiscordClient sender, MessageUpdateEventArgs args)
{
    StringBuilder builder = new();
    builder.AppendLine($"Message.MentionedUsers.Count    : {args.Message.MentionedUsers.Count}");
    builder.AppendLine($"Message.MentionedChannels.Count : {args.Message.MentionedChannels.Count}");
    builder.AppendLine($"Message.MentionedRoles.Count    : {args.Message.MentionedRoles.Count}");
    builder.AppendLine($"Message.MentionEveryone.Count   : {args.Message.MentionEveryone}");

    await args.Channel.SendMessageAsync(new DiscordMessageBuilder().WithContent(builder.ToString()).WithReply(args.Message.Id));
}

"Definitely a user error" - @OoLunar

In MessageUpdatedEvent, the returned (updated) message now correctly pulls information on mentions from the information given from Discord.
@OoLunar

OoLunar commented Jun 17, 2022

Copy link
Copy Markdown
Contributor

"Definitely a user error" - @OoLunar

I was referring to the usage of the D#+ documentation bot 😤

@OoLunar OoLunar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

message._attachments.AddRange(event_message._attachments);
message.Pinned = event_message.Pinned;
message.IsTTS = event_message.IsTTS;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you clearing then adding? Couldn't you get away with setting the property, or is it readonly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep consistency with the previous code mostly honestly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I suppose

@OoLunar

OoLunar commented Jun 17, 2022

Copy link
Copy Markdown
Contributor

image
Waffles has yet to confirm whether the PR is tested but I'm going to merge it anyways

@OoLunar OoLunar merged commit aabff10 into DSharpPlus:master Jun 17, 2022
@DWaffles

Copy link
Copy Markdown
Contributor Author

image
Waffles has yet to confirm whether the PR is tested but I'm going to merge it anyways

This PR thread is not suitable to express my rage and anger.

OoLunar pushed a commit that referenced this pull request Oct 3, 2024
In MessageUpdatedEvent, the returned (updated) message now correctly pulls information on mentions from the information given from Discord.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants