GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

  1. package log
  2. import (
  3. "git.aiterp.net/rpdata/api/internal/store"
  4. "github.com/globalsign/mgo"
  5. "github.com/globalsign/mgo/bson"
  6. )
  7. var unknownConnection *mgo.Collection
  8. // An UnknownNick is a nick found by the character list updater that
  9. // does not exist. The score is the number of logs that nick was in, meaning
  10. // nicks with a higher score should be a high priority to be matched with
  11. // a character.
  12. type UnknownNick struct {
  13. Nick string `bson:"_id" json:"nick"`
  14. Score int `bson:"score" json:"score"`
  15. }
  16. // UnknownNicks gets all the unknown nicks from the last search.
  17. func UnknownNicks() ([]UnknownNick, error) {
  18. nicks := make([]UnknownNick, 0, 256)
  19. err := unknownConnection.Find(bson.M{}).Sort("-score").All(&nicks)
  20. return nicks, err
  21. }
  22. func addUnknownNick(nick string) error {
  23. _, err := unknownConnection.UpsertId(nick, bson.M{"$inc": bson.M{"score": 1}})
  24. return err
  25. }
  26. func clearUnknownNicks() error {
  27. _, err := unknownConnection.RemoveAll(bson.M{})
  28. return err
  29. }
  30. func init() {
  31. store.HandleInit(func(db *mgo.Database) {
  32. unknownConnection = db.C("logbot3.unknown_nicks")
  33. })
  34. }