Unsplit fetching user info from Puppet.UpdateInfo
This commit is contained in:
39
puppet.go
39
puppet.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -250,32 +249,24 @@ func (puppet *Puppet) UpdateAvatar(info *discordgo.User) bool {
|
|||||||
return true
|
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) {
|
func (puppet *Puppet) UpdateInfo(source *User, info *discordgo.User) {
|
||||||
puppet.syncLock.Lock()
|
puppet.syncLock.Lock()
|
||||||
defer puppet.syncLock.Unlock()
|
defer puppet.syncLock.Unlock()
|
||||||
|
|
||||||
info, err := puppet.getUserInfo(source, info)
|
if info == nil || len(info.Username) == 0 || len(info.Discriminator) == 0 {
|
||||||
if err != nil {
|
if puppet.Name != "" || source == nil {
|
||||||
puppet.log.Warn().Err(err).Str("source_user", source.DiscordID).Msg("Failed to fetch info through user")
|
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
puppet.log.Error().Err(err).Msg("Failed to ensure registered")
|
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
|
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{
|
contactInfo := map[string]any{
|
||||||
"com.beeper.bridge.identifiers": []string{
|
"com.beeper.bridge.identifiers": []string{
|
||||||
fmt.Sprintf("discord:%s#%s", info.Username, info.Discriminator),
|
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_bridge_bot": false,
|
||||||
"com.beeper.bridge.is_bot": info.Bot,
|
"com.beeper.bridge.is_bot": info.Bot,
|
||||||
}
|
}
|
||||||
err = puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
err := puppet.DefaultIntent().BeeperUpdateProfile(contactInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.log.Warn().Err(err).Msg("Failed to store custom contact info in profile")
|
puppet.log.Warn().Err(err).Msg("Failed to store custom contact info in profile")
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user