refactor: update checkDiffSteamGameStatus to return a map for game statuses and add getAllSteamID function for retrieving all Steam IDs; enhance help messages for binding and unbinding Steam accounts
This commit is contained in:
@@ -247,9 +247,9 @@ func checkSteamGameStatus(steamID []string) (string, error) {
|
||||
return gameStatusList, nil
|
||||
}
|
||||
|
||||
func checkDiffSteamGameStatus(steamID []string, lastTimeStat map[string]string) (string, error) {
|
||||
func checkDiffSteamGameStatus(steamID []string, lastTimeStat map[string]string) (map[string]string, error) {
|
||||
if len(steamID) == 0 {
|
||||
return "疑似没人在玩游戏", nil
|
||||
return nil, nil
|
||||
}
|
||||
var glbErr error
|
||||
var writeMutex sync.Mutex
|
||||
@@ -311,21 +311,18 @@ func checkDiffSteamGameStatus(steamID []string, lastTimeStat map[string]string)
|
||||
}
|
||||
wg.Wait()
|
||||
if glbErr != nil {
|
||||
return "", glbErr
|
||||
return nil, glbErr
|
||||
}
|
||||
gameStatusListStr := ""
|
||||
gameStatusListStr := map[string]string{}
|
||||
for _, userState := range Players {
|
||||
if lastTimeStat[userState.SteamID] == userState.GameID {
|
||||
continue
|
||||
}
|
||||
if userState.ToGameStatus() != "" {
|
||||
gameStatusListStr += userState.ToGameStatus() + "\n"
|
||||
gameStatusListStr[userState.SteamID] = userState.ToGameStatus()
|
||||
}
|
||||
lastTimeStat[userState.SteamID] = userState.GameID
|
||||
}
|
||||
if gameStatusListStr != "" {
|
||||
gameStatusListStr = gameStatusListStr[:len(gameStatusListStr)-1]
|
||||
}
|
||||
return gameStatusListStr, nil
|
||||
}
|
||||
|
||||
@@ -374,3 +371,17 @@ func getAllGroupID() ([]int64, error) {
|
||||
}
|
||||
return groupIDs, nil
|
||||
}
|
||||
|
||||
func getAllSteamID() ([]string, error) {
|
||||
tx, err := sqlite3.GetTran()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var steamIDs []string
|
||||
err = tx.Select(&steamIDs, "SELECT steamid FROM steam_user")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return steamIDs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user