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

fix: make execute_webhook supports avatar #428

Merged
merged 2 commits into from
Jun 23, 2022
Merged

fix: make execute_webhook supports avatar #428

merged 2 commits into from
Jun 23, 2022

Conversation

yuto0214w
Copy link
Contributor

  1. It wasn't possible to edit webhook to change avatar, so edited it to use wh.avatar
  2. This will override message.author.username if wh.name present

@braindigitalis
Copy link
Contributor

braindigitalis commented Jun 21, 2022

This works, we should avoid calling json::parse on the object unless absolutely neccessary and you didnt have support for uploaded avatars:

	if (!thread_name.empty() || wh.image_data || !wh.avatar.empty() || !wh.name.empty()) { // only use json::parse if one of the optional parameters is set
		json j = json::parse(m.build_json(false));
		if (!thread_name.empty()) {
			j["thread_name"] = thread_name;
		}
		if (!wh.avatar.empty()) {
			j["avatar_url"] = wh.avatar;
		} else if (wh.image_data) {
			j["avatar_url"] = *image_data;
		}
		if (!wh.name.empty()) {
			j["username"] = wh.name;
		}
		body = j.dump();
	}

The formatting of your code is really odd and not in line with the coding style guide: https://dpp.dev/coding-standards.html

Please change your code to fit the style guide and implement the missing features as above, and i'd be happy to merge it in. :)

@yuto0214w
Copy link
Contributor Author

Thanks for the feedback.
Fixed code style.
But for support of uploading avatar, as avatar_url only accepts http(s), it isn't possible to do like so other than modifying webhook.

@braindigitalis
Copy link
Contributor

no pretty sure you can send a base64 encoded image in the image data, rather than a remote URL, same as when modifying webhook

@yuto0214w
Copy link
Contributor Author

I tested dozen times, and read documentation but I couldn't seem to upload avatar without modifying webhook.
But as webhook avatar url format is https://cdn.discordapp.com/avatars/:id/:hash.png, I still don't think it's possible to do

@braindigitalis
Copy link
Contributor

but those are user avatars, how do you get one uploaded to use it?

@braindigitalis braindigitalis merged commit e9c4ed7 into brainboxdotcc:dev Jun 23, 2022
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