package log import ( "git.aiterp.net/rpdata/api/internal/store" "github.com/globalsign/mgo" "github.com/globalsign/mgo/bson" ) var unknownConnection *mgo.Collection // An UnknownNick is a nick found by the character list updater that // does not exist. The score is the number of logs that nick was in, meaning // nicks with a higher score should be a high priority to be matched with // a character. type UnknownNick struct { Nick string `bson:"_id" json:"nick"` Score int `bson:"score" json:"score"` } // UnknownNicks gets all the unknown nicks from the last search. func UnknownNicks() ([]UnknownNick, error) { nicks := make([]UnknownNick, 0, 256) err := unknownConnection.Find(bson.M{}).Sort("-score").All(&nicks) return nicks, err } func addUnknownNick(nick string) error { _, err := unknownConnection.UpsertId(nick, bson.M{"$inc": bson.M{"score": 1}}) return err } func clearUnknownNicks() error { _, err := unknownConnection.RemoveAll(bson.M{}) return err } func init() { store.HandleInit(func(db *mgo.Database) { unknownConnection = db.C("logbot3.unknown_nicks") }) }