Skip to content
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

messages: Support silent flag #161

Open
InterLinked1 opened this issue Sep 7, 2023 · 12 comments
Open

messages: Support silent flag #161

InterLinked1 opened this issue Sep 7, 2023 · 12 comments
Labels
enhancement New feature or request

Comments

@InterLinked1
Copy link
Contributor

Describe the feature

I use this library for an IRC relay (bot), and it would be helpful to be able to use the @silent feature that seems to exist now, particularly for IRC join/part/quit messages, to avoid notifying everyone on Discord when these events happen, as there are currently a lot of complaints about this.

The message flag is documented here: https://github.com/discord/discord-api-docs/pull/5894/files

I confirmed by analyzing the network requests that the only different when using this feature is the flag is indeed set to 4096 (1 << 12), as opposed to 0, so this appears to be correct.

It appears that this would be the right place to add the flag: https://github.com/Cogmasters/concord/blob/master/gencodecs/api/channel.PRE.h#L30

I'm less certain about how the flag would be used. The only place I see any flags being used is here:

.flags = DISCORD_MESSAGE_EPHEMERAL // 1 << 6

However, I would think that flags would need to be provided in create_message, e.g. here:

discord_create_message(struct discord *client,

Since I don't see this, would the ability to specify flags when sending a message need to be added as well, or is the other example the proper way to send messages if flags need to be added? I'm less sure about this, otherwise I think this should be a fairly straightforward addition.

@InterLinked1 InterLinked1 added the enhancement New feature or request label Sep 7, 2023
@ThePedroo
Copy link
Contributor

I'm sorry for the delay.

If I'm not wrong, the discord_create_message structure has a flag option.

But we are indeed missing 2 flags: SUPPRESS_NOTIFICATIONS, the one you're looking, and IS_VOICE_MESSAGE.

Soon I'll be creating a PR to add both.

@ThePedroo
Copy link
Contributor

Hey. I'm sorry for the delay. I came with some updates.

I'm developing a branch updating all codecs, update/gencodecs branch, you may want to give it a try. I added the flag you wanted. I also must warn that it's an experimental branch, so it may have some bugs, but I highly doubt. Thanks!

@InterLinked1
Copy link
Contributor Author

Hey. I'm sorry for the delay. I came with some updates.

I'm developing a branch updating all codecs, update/gencodecs branch, you may want to give it a try. I added the flag you wanted. I also must warn that it's an experimental branch, so it may have some bugs, but I highly doubt. Thanks!

Thanks! I took a look at that latest commit there, but I don't see anything related to this flag there. Do you mind pointing out where to look for that? Just want to look at what's added and then go ahead and add some code to interface with it.

@ThePedroo
Copy link
Contributor

Sure! A tip is that anything related to the structs of Discord API responses will be found in gencodecs folder

Specifically, the flag you're searching is in api/channel.PRE.h, line 273

@InterLinked1
Copy link
Contributor Author

InterLinked1 commented Jan 31, 2024

I tried it and it didn't appear to work, but I might have done something wrong, and I'm not sure if other stuff needs to be updated.

struct discord_create_message params = {
			.content = mbuf,
			.message_reference = &(struct discord_message_reference) {
				.message_id = 0,
				.channel_id = cp->channel_id,
				.guild_id = cp->guild_id,
				.fail_if_not_exists = false,
			},
			.components = NULL,
		};

params.flags = DISCORD_MESSAGE_SUPPRESS_NOTIFICATIONS;

I looked at the documentation, and found this: https://cogmasters.github.io/concord/structdiscord__create__message.html#a3c7adafb00478f6e77360e428d2951c2

Message flags combined as a bitfield (only SUPPRESS_EMBEDS can be set)

Is this still correct? Does that function need to be updated or does the documentation need to be updated?

(I've also confirmed via HTTP debug that "flags" is 0 in the payload)

@ThePedroo
Copy link
Contributor

ThePedroo commented Jan 31, 2024

Are you sure you it's properly installed? I can't reproduce using the same code:

image

Not related but: If you set message_id to 0, it won't have any effect.

EDIT: You're mostly looking at the wrong flag too, there are 2 flags.

@InterLinked1
Copy link
Contributor Author

Are you sure you it's properly installed? I can't reproduce using the same code:

It's properly install, the flag itself is available as the code compiles.

Not related but: If you set message_id to 0, it won't have any effect.

Hmm, well that's probably it, then I always set message_id to 0. I thought that was just to ensure it's not a reply in thread to something on Discord, per the docs? Am I missing something? I'm just trying to post normal messages.

EDIT: You're mostly looking at the wrong flag too, there are 2 flags.

Hmm, I'm only seeing one... would you mind elaborating? Thanks!

@ThePedroo
Copy link
Contributor

Oh, I may have been a little superficial with my "won't have any effect" -- with that I mean you won't reference any message.

Hmm, I'm only seeing one... would you mind elaborating? Thanks!

Yes, follow the JSON from the screenshot I sent you:

{"id":"1202079666543013899","type":0,"content":"Hey!","channel_id":"1171670935691075614","author":{"id":"1038648927693590619","username":"PerformanC","avatar":"e56cb550dc19470d708f5e190620fcdc","discriminator":"0871","public_flags":0,"premium_type":0,"flags":0,"bot":true,"banner":null,"accent_color":null,"global_name":null,"avatar_decoration_data":null,"banner_color":null},"attachments":[],"embeds":[],"mentions":[],"mention_roles":[],"pinned":false,"mention_everyone":false,"tts":false,"timestamp":"2024-01-31T02:35:26.064000+00:00","edited_timestamp":null,"flags":4096,"components":[],"referenced_message":null}

If we take to a JSON viewer, we can see there is a flag on author, and one at the root of the json:

image

@InterLinked1
Copy link
Contributor Author

If we take to a JSON viewer, we can see there is a flag on author, and one at the root of the json:

Ah, I see what you mean. Yeah, both those flags are 0 for me.

Do you mind posting a code snippet you have that generated the result in the screenshot? I can probably work it out from there.

@ThePedroo
Copy link
Contributor

ThePedroo commented Jan 31, 2024

I made a gist with the code -- I didn't change the position of where the flags is set, but you can built-in it to the struct

@InterLinked1
Copy link
Contributor Author

I made a gist with the code -- I didn't change the position of where the flags is set, but you can built-in it to the struct

Okay, it works! Typically user error, the code I thought was running was not actually the code that was running...

It's working as expected and I'll leave this branch running and see if I notice anything strange, but looks good so far - thanks!

@ThePedroo
Copy link
Contributor

Nice to hear, feel free to report any issue on its PR, #169. :)

I'll keep this open till it's merged on dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants