|
@@ -1,7 +1,6 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "errors"
|
|
|
"fmt"
|
|
|
"regexp"
|
|
|
"sync"
|
|
@@ -250,32 +249,24 @@ func (puppet *Puppet) UpdateAvatar(info *discordgo.User) bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-func (puppet *Puppet) getUserInfo(source *User, info *discordgo.User) (*discordgo.User, error) {
|
|
|
- if info != nil && len(info.Username) > 0 && len(info.Discriminator) > 0 {
|
|
|
- return info, nil
|
|
|
- }
|
|
|
-
|
|
|
- if puppet.Name == "" || source == nil {
|
|
|
- return nil, errors.New("puppet has no name or source is nil")
|
|
|
- }
|
|
|
-
|
|
|
- puppet.log.Debug().
|
|
|
- Str("source_user", source.DiscordID).
|
|
|
- Msg("Fetching info through user to update puppet")
|
|
|
- return source.Session.User(puppet.ID)
|
|
|
-}
|
|
|
-
|
|
|
func (puppet *Puppet) UpdateInfo(source *User, info *discordgo.User) {
|
|
|
puppet.syncLock.Lock()
|
|
|
defer puppet.syncLock.Unlock()
|
|
|
|
|
|
- info, err := puppet.getUserInfo(source, info)
|
|
|
- if err != nil {
|
|
|
- puppet.log.Warn().Err(err).Str("source_user", source.DiscordID).Msg("Failed to fetch info through user")
|
|
|
- return
|
|
|
+ if info == nil || len(info.Username) == 0 || len(info.Discriminator) == 0 {
|
|
|
+ if puppet.Name != "" || source == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var err error
|
|
|
+ puppet.log.Debug().Str("source_user", source.DiscordID).Msg("Fetching info through user to update puppet")
|
|
|
+ info, err = source.Session.User(puppet.ID)
|
|
|
+ if err != nil {
|
|
|
+ puppet.log.Error().Err(err).Str("source_user", source.DiscordID).Msg("Failed to fetch info through user")
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- err = puppet.DefaultIntent().EnsureRegistered()
|
|
|
+ err := puppet.DefaultIntent().EnsureRegistered()
|
|
|
if err != nil {
|
|
|
puppet.log.Error().Err(err).Msg("Failed to ensure registered")
|
|
|
}
|
|
@@ -297,12 +288,6 @@ func (puppet *Puppet) UpdateContactInfo(source *User, info *discordgo.User) bool
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- info, err := puppet.getUserInfo(source, info)
|
|
|
- if err != nil {
|
|
|
- puppet.log.Error().Err(err).Str("source_user", source.DiscordID).Msg("Failed to fetch info through user")
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
contactInfo := map[string]any{
|
|
|
"com.beeper.bridge.identifiers": []string{
|
|
|
fmt.Sprintf("discord:%s#%s", info.Username, info.Discriminator),
|
|
@@ -313,7 +298,7 @@ func (puppet *Puppet) UpdateContactInfo(source *User, info *discordgo.User) bool
|
|
|
"com.beeper.bridge.is_bridge_bot": false,
|
|
|
"com.beeper.bridge.is_bot": info.Bot,
|
|
|
}
|
|
|
- err = puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
|
|
+ err := puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
|
|
if err != nil {
|
|
|
puppet.log.Warn().Err(err).Msg("Failed to store custom contact info in profile")
|
|
|
return false
|