This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
|
||||
var collection *mgo.Collection
|
||||
|
||||
var logsCollection *mgo.Collection
|
||||
|
||||
// Character is a common data model representing an RP character or NPC.
|
||||
type Character struct {
|
||||
ID string `json:"id" bson:"_id"`
|
||||
@@ -155,9 +157,31 @@ func ListIDs(ids ...string) ([]Character, error) {
|
||||
}
|
||||
|
||||
// ListFilter lists all logs matching the filters.
|
||||
func ListFilter(ids []string, nicks []string, names []string, author *string, search *string) ([]Character, error) {
|
||||
func ListFilter(ids []string, nicks []string, names []string, author *string, search *string, logged *bool) ([]Character, error) {
|
||||
query := bson.M{}
|
||||
|
||||
if logged != nil {
|
||||
loggedIDs := make([]string, 0, 64)
|
||||
err := logsCollection.Find(bson.M{"characterIds": bson.M{"$ne": nil}}).Distinct("characterIds", &loggedIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(ids) > 0 {
|
||||
newIds := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
for _, loggedID := range loggedIDs {
|
||||
if id == loggedID {
|
||||
newIds = append(newIds, id)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
ids = newIds
|
||||
} else {
|
||||
ids = loggedIDs
|
||||
}
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
query["_id"] = bson.M{"$in": ids}
|
||||
}
|
||||
@@ -256,5 +280,7 @@ func init() {
|
||||
if err != nil {
|
||||
log.Fatalln("init common.characters:", err)
|
||||
}
|
||||
|
||||
logsCollection = db.C("logbot3.logs")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user