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
Expose flags on MessageEdit so you can suppress embeds on other messages #973
Conversation
Also fix typo in the message flags enum
I wasn't sure if this was going to work but the documentation says: > The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string. Therefore, if Flags is unmodified it will be omitted.
I think the null value here may be triggering the "Cannot edit a message authored by another user"
Stops the gofmt error
message.go
Outdated
// Deprecated: use MessageFlagsSuppressEmbeds | ||
const ( | ||
MessageFlagsSupressEmbeds MessageFlags = 1 << 2 | ||
) | ||
|
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 think it would be best to just put it right after the corrected constant.
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.
The reason I put it separate was because of a gofmt error in the previous build
0.06s$ diff <(gofmt -d .) <(echo -n)
1,14d0
< diff -u message.go.orig message.go
< --- message.go.orig 2021-07-22 08:05:45.890441692 +0000
< +++ message.go 2021-07-22 08:05:45.890441692 +0000
< @@ -172,8 +172,8 @@
<
< // Valid MessageFlags values
< const (
< - MessageFlagsCrossPosted MessageFlags = 1 << 0
< - MessageFlagsIsCrossPosted MessageFlags = 1 << 1
< + MessageFlagsCrossPosted MessageFlags = 1 << 0
< + MessageFlagsIsCrossPosted MessageFlags = 1 << 1
< // Deprecated: use MessageFlagsSuppressEmbeds
< MessageFlagsSupressEmbeds MessageFlags = 1 << 2
< MessageFlagsSuppressEmbeds MessageFlags = 1 << 2
The command "diff <(gofmt -d .) <(echo -n)" exited with 1.
Between messing up the spacing or extracting it to a separate section I chose the latter.
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.
Just put it at the end of the section, like that
const (
...
// TODO: remove when compatibility is not required
MessageFlagsSupressEmbeds MessageFlags = 1 << 2
)
message.go
Outdated
@@ -204,9 +209,10 @@ type MessageSend struct { | |||
// is also where you should get the instance from. | |||
type MessageEdit struct { | |||
Content *string `json:"content,omitempty"` | |||
Components []MessageComponent `json:"components"` | |||
Components []MessageComponent `json:"components,omitempty"` |
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 was intentional, to allow users to remove components from messages.
Also it would be probably better to move this into a separate 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.
I had to add this to make it work. Before I added it, Discord would give an error about "Cannot edit a message authored by another user"
This seems to be mutually exclusive with your current requirements, so I don't know what to do about that.
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.
While it's related to SuppressEmbeds
flag, the issue existed before, so I think it would be better to resolve this in a separate PR.
Sorry it took a long time |
Also, please note the conflicts |
I've made a couple of changes myself, to speed up the process. |
This pull request exposes the flags member of the MessageEdit struct so you can suppress embeds on other people's messages.
I've tested it and it works with the following code:
Additionally, I wanted to include a convenience function for suppressing embeds on a message like so:
However, that wouldn't work.
Since the MessageEdit struct knows nothing about the message it's editing and it's not connected to a session, I'm not sure how you would like to handle this.
Should it not be included?
Should the MessageEdit include a reference to the Session that created it?
I also changed two more things. First, I noticed a typo in the enum so I marked that member as deprecated (not sure if that works?) and included a fixed one with the same value.
I also had to make Components omitempty on the MessageEdit struct or Discord would give an error about "Cannot edit a message authored by another user"