This commit is contained in:
shoopea 2019-05-25 16:59:14 +08:00
parent 8ac2f43bd8
commit b7d466779a
2 changed files with 10 additions and 9 deletions

View File

@ -101,6 +101,8 @@ func main() {
logOnError(err, "Caching castles") logOnError(err, "Caching castles")
err = loadObjGuild() err = loadObjGuild()
logOnError(err, "Caching guilds") logOnError(err, "Caching guilds")
err = loadObjUser()
logOnError(err, "Caching user")
// Registering bot // Registering bot
b, err := tb.NewBot(tb.Settings{ b, err := tb.NewBot(tb.Settings{

17
obj.go
View File

@ -8,6 +8,7 @@ import (
var ( var (
cacheObjCastle map[string]ChatWarsCastle cacheObjCastle map[string]ChatWarsCastle
cacheObjGuild map[string]ChatWarsGuild cacheObjGuild map[string]ChatWarsGuild
cacheObjUser map[string]ChatWarsUser
) )
func getObjTypeId(objId int64) (int64, error) { func getObjTypeId(objId int64) (int64, error) {
@ -444,28 +445,26 @@ func getObjUserID(s string) int64 {
func loadObjUser() error { func loadObjUser() error {
var ( var (
id int64 id int64
tag string
name string name string
) )
cacheObjUser = make(map[string]ChatWarsGuild) cacheObjUser = make(map[string]ChatWarsUser)
users, err := db.Query(`SELECT og.obj_id, og.tag, og.name FROM obj_guild og;`) users, err := db.Query(`SELECT ou.obj_id, ou.name FROM obj_user ou;`)
if err != nil { if err != nil {
return err return err
} }
defer users.Close() defer users.Close()
for users.Next() { for users.Next() {
err = users.Scan(&id, &tag, &name) err = users.Scan(&id, &name)
if err != nil { if err != nil {
return err return err
} }
g := new(ChatWarsUser) u := new(ChatWarsUser)
g.ObjID64 = id u.ObjID64 = id
g.Tag = tag u.Name = name
g.Name = name cacheObjUser[tag] = *u
cacheObjUser[tag] = *g
} }
return nil return nil