Skip to content

Conversation

@Fmstrat
Copy link

@Fmstrat Fmstrat commented Dec 10, 2025

Adds the ability for a user to specify the path to a custom avatar image.

  • Supports user.avatar in config.yml
    • Old configs that do not have the avatar key in user will continue to work due to Option use (avoids breaking change)
  • Includes env support for BAIBOT_USER_AVATAR

Enhancement to cover: #28

Comment on lines +14 to +16
# An optional path to a 768x768 PNG to be used as a custom avatar image.
# Leave empty to use the default.
avatar:
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things:

  • I suppose other image resolutions are also OK. It doesn't need to be 768x768. It's just what the default avatar image is like, but anything else is OK. Still, having a somewhat high-res image is probably sensible

  • I suppose PNG is a requirement right now, because of the LOGO_MIME_TYPE constant. With some extra work, we may be able to get rid of it

  • avatar_path may be a better name for this setting, if this will deal with filesystem paths only

  • if we'll be adding other avatar-related options, it may be better to expand this section and have sub-keys.

    Example other options:

    • avatar.manage = true|false (allows people to the bot to not touch the currently-configured avatar)
    • avatar.path = ... (file path)
    • avatar.source = ... (a more generic name than path, so it would also allow handling of both file paths and MXC URIs). One could potentially specify the avatar using something like mxc://example.com/... in which case we won't be doing upload_avatar(), but rather set_avatar_url()
    • avatar.mime_type = ... (potentially allowing for non-PNG images to be used). This may be unnecessary if we can do some-detection

I suppose this complicates things a lot, but also covers a bunch of additional use-cases and makes this feature complete.

Comment on lines +320 to +330
let logo_bytes: Option<Vec<u8>> = if self.inner.config.user.avatar.is_none() {
Some(LOGO_BYTES.to_vec())
} else {
let avatar_path = self.inner.config.user.avatar.as_ref().unwrap();
match fs::read(avatar_path) {
Ok(bytes) => Some(bytes),
Err(_e) => {
Some(LOGO_BYTES.to_vec())
}
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

As it is right now, all if code paths return Some stuff, so there's no need to have logo_bytes be a Option.

If it's just Vec<u8> code below can remain as it was before.

That said, if we introduce additional avatar options (as discussed in my other comment in this review), then this may change.

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