bot.go 788 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package bridge
  2. import (
  3. "maunium.net/go/mautrix/id"
  4. )
  5. func (b *Bridge) updateBotProfile() {
  6. cfg := b.Config.Appservice.Bot
  7. // Set the bot's avatar.
  8. if cfg.Avatar != "" {
  9. var err error
  10. var mxc id.ContentURI
  11. if cfg.Avatar == "remove" {
  12. err = b.bot.SetAvatarURL(mxc)
  13. } else {
  14. mxc, err = id.ParseContentURI(cfg.Avatar)
  15. if err == nil {
  16. err = b.bot.SetAvatarURL(mxc)
  17. }
  18. }
  19. if err != nil {
  20. b.log.Warnln("failed to update the bot's avatar: ", err)
  21. }
  22. }
  23. // Update the bot's display name.
  24. if cfg.Displayname != "" {
  25. var err error
  26. if cfg.Displayname == "remove" {
  27. err = b.bot.SetDisplayName("")
  28. } else {
  29. err = b.bot.SetDisplayName(cfg.Displayname)
  30. }
  31. if err != nil {
  32. b.log.Warnln("failed to update the bot's display name", err)
  33. }
  34. }
  35. }