Skip to content

Commit

Permalink
added global_name to user object (#1506)
Browse files Browse the repository at this point in the history
Co-authored-by: Ashish Jhanwar <[email protected]>
  • Loading branch information
ashishjh-bst and ashishjh-bst authored May 29, 2023
1 parent b205165 commit 2dc23b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 174 deletions.
5 changes: 5 additions & 0 deletions lib/discordgo/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type User struct {
// The user's username.
Username string `json:"username"`

// The user's display name on discord
Globalname string `json:"global_name"`

// The hash of the user's avatar. Use Session.UserAvatar
// to retrieve the avatar itself.
Avatar string `json:"avatar"`
Expand Down Expand Up @@ -46,6 +49,8 @@ func (u *User) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
return DecodeSnowflake(&u.ID, dec)
case "username":
return dec.String(&u.Username)
case "global_name":
return dec.String(&u.Globalname)
case "avatar":
return dec.String(&u.Avatar)
case "locale":
Expand Down
174 changes: 0 additions & 174 deletions logs/plugin_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,6 @@ func HandleGC(evt *eventsystem.EventData) {
}
}

// type UsernameListing struct {
// gorm.Model
// UserID int64 `gorm:"index"`
// Username string
// }

// type NicknameListing struct {
// gorm.Model
// UserID int64 `gorm:"index"`
// GuildID string
// Nickname string
// }

func CheckUsername(exec boil.ContextExecutor, ctx context.Context, usernameStmt *sql.Stmt, user *discordgo.User) error {
var lastUsername string
row := usernameStmt.QueryRow(user.ID)
Expand Down Expand Up @@ -553,130 +540,6 @@ func CheckNickname(exec boil.ContextExecutor, ctx context.Context, nicknameStmt
return err
}

// func CheckNicknameBulk(gDB *gorm.DB, guildID int64, members []*discordgo.Member) {

// ids := make([]int64, 0, len(members))
// for _, v := range members {
// ids = append(ids, v.User.ID)
// }

// rows, err := gDB.CommonDB().Query(
// "select distinct on(user_id) nickname,user_id from nickname_listings where user_id = ANY ($1) AND guild_id=$2 order by user_id,id desc;", pq.Int64Array(ids), guildID)
// if err != nil {
// logger.WithError(err).Error("Failed querying current nicknames")
// }

// // Value is wether the nickname was identical
// queriedUsers := make(map[int64]bool)

// for rows.Next() {
// var nickname string
// var userID int64
// err = rows.Scan(&nickname, &userID)
// if err != nil {
// logger.WithError(err).Error("Error while scanning")
// continue
// }

// for _, member := range members {
// if member.User.ID == userID {
// if member.Nick == nickname {
// // Already have the last username tracked
// queriedUsers[userID] = true
// } else {
// queriedUsers[userID] = false
// logger.Debug("CHANGED Nick: ", nickname, " : ", member.Nick)
// }

// break
// }
// }
// }
// rows.Close()

// for _, member := range members {
// unchanged, queried := queriedUsers[member.User.ID]
// if queried && unchanged {
// continue
// }

// if !queried && member.Nick == "" {
// // don't need to be putting this in the database as the first record for the user
// continue
// }

// logger.Debug("User changed nickname, new: ", member.Nick)

// listing := NicknameListing{
// UserID: member.User.ID,
// GuildID: discordgo.StrID(guildID),
// Nickname: member.Nick,
// }

// err = gDB.Create(&listing).Error
// if err != nil {
// logger.WithError(err).Error("Failed setting nickname")
// }
// }

// }
// func CheckUsernameBulk(gDB *gorm.DB, users []*discordgo.User) {

// ids := make([]int64, 0, len(users))
// for _, v := range users {
// ids = append(ids, v.ID)
// }

// rows, err := gDB.CommonDB().Query(
// "select distinct on(user_id) username,user_id from username_listings where user_id = ANY ($1) order by user_id,id desc;", pq.Int64Array(ids))
// if err != nil {
// logger.WithError(err).Error("Failed querying current usernames")
// }

// unchangedUsers := make(map[int64]bool)

// for rows.Next() {
// var username string
// var userID int64
// err = rows.Scan(&username, &userID)
// if err != nil {
// logger.WithError(err).Error("Error while scanning")
// continue
// }

// // var foundUser *discordgo.User
// for _, user := range users {
// if user.ID == userID {
// if user.Username == username {
// // Already have the last username tracked
// unchangedUsers[userID] = true
// }

// break
// }
// }
// }
// rows.Close()

// for _, user := range users {
// if unchanged, ok := unchangedUsers[user.ID]; ok && unchanged {
// continue
// }

// logger.Debug("User changed username, new: ", user.Username)

// listing := UsernameListing{
// UserID: user.ID,
// Username: user.Username,
// }

// err = gDB.Create(&listing).Error
// if err != nil {
// logger.WithError(err).Error("Failed setting username")
// }
// }
// }

var (
evtChan = make(chan interface{}, 1000)
evtChanGC = make(chan *LightGC)
Expand Down Expand Up @@ -849,43 +712,6 @@ type LightGC struct {
func EvtProcesserGCs() {
for {
<-evtChanGC

// tx := common.GORM.Begin()

// conf, err := GetConfig(gc.GuildID)
// if err != nil {
// logger.WithError(err).Error("Failed fetching config")
// continue
// }

// started := time.Now()

// users := make([]*discordgo.User, len(gc.Members))
// for i, m := range gc.Members {
// users[i] = m.User
// }

// if conf.NicknameLoggingEnabled {
// CheckNicknameBulk(tx, gc.GuildID, gc.Members)
// }

// if conf.UsernameLoggingEnabled {
// CheckUsernameBulk(tx, users)
// }

// err = tx.Commit().Error
// if err != nil {
// logger.WithError(err).Error("Failed committing transaction")
// continue
// }

// if len(gc.Members) > 100 {
// logger.Infof("Checked %d members in %s", len(gc.Members), time.Since(started).String())
// // Make sure this dosen't use all our resources
// time.Sleep(time.Second * 25)
// } else {
// time.Sleep(time.Second * 15)
// }
}
}

Expand Down

0 comments on commit 2dc23b3

Please sign in to comment.