Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #247 from JustHumanz/userChecker
Browse files Browse the repository at this point in the history
User checker
  • Loading branch information
JustHumanz authored Feb 3, 2022
2 parents 730946b + 02a3a26 commit e1ee55e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
CheckServerCount = "@every 0h10m0s"
CheckPayload = "@every 1h30m0s"
PilotGetGroups = "@every 1h0m0s"
CheckUser = "0 1 * * *"

//Time
AddUserTTL = 5 * time.Hour
Expand Down
30 changes: 30 additions & 0 deletions pkg/database/generaldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -932,3 +933,32 @@ func (i *LiveStream) RemoveCache(Key string) error {
}
return nil
}

func GetAllUser() []string {
var (
UserID []string
)
rows, err := DB.Query(`SELECT DiscordID FROM Vtuber.User where Human=1 group by DiscordID;`)
if err != nil {
log.Error(err)
}

defer rows.Close()
for rows.Next() {
id := ""
err = rows.Scan(&id)
if err != nil {
log.Error(err)
}
UserID = append(UserID, id)
}
return UserID
}

func DeleteDeletedUser(users []string) {
sqlq := fmt.Sprintf(`Delete FROM User where DiscordID in ('%s')`, strings.Join(users, "','"))
_, err := DB.Query(sqlq)
if err != nil {
log.Error(err)
}
}
40 changes: 40 additions & 0 deletions service/utility/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,46 @@ func main() {
log.Info("Done")
})

c.AddFunc(config.CheckUser, func() {
log.Info("Start check deleted user")
UsersDeleted := []string{}
Users := database.GetAllUser()
for _, v := range Users {
User, err := Bot.User(v)
if err != nil {
log.Error(err, v)
}
if strings.HasPrefix(User.Username, "Deleted") {
log.WithFields(log.Fields{
"userId": v,
}).Info("User not found or user deleted ther account")
UsersDeleted = append(UsersDeleted, v)
}
}

log.Info("Start deleting user ", UsersDeleted)
database.DeleteDeletedUser(UsersDeleted)
})

log.Info("Start check deleted user")
UsersDeleted := []string{}
Users := database.GetAllUser()
for _, v := range Users {
User, err := Bot.User(v)
if err != nil {
log.Error(err, v)
}
if strings.HasPrefix(User.Username, "Deleted") {
log.WithFields(log.Fields{
"userId": v,
}).Info("User not found or user deleted ther account")
UsersDeleted = append(UsersDeleted, v)
}
}

log.Info("Start deleting user ", UsersDeleted)
database.DeleteDeletedUser(UsersDeleted)

go pilot.RunHeartBeat(gRCPconn, "Utility")
runfunc.Run(Bot)
}

0 comments on commit e1ee55e

Please sign in to comment.