move id to idx

This commit is contained in:
Chris Sexton 2012-08-29 10:24:34 -04:00
parent 92ddfa3b6f
commit 24a879285e
2 changed files with 13 additions and 5 deletions

View File

@ -15,8 +15,8 @@ import (
// factoid stores info about our factoid for lookup and later interaction // factoid stores info about our factoid for lookup and later interaction
type Factoid struct { type Factoid struct {
_id bson.ObjectId `bson:"_id"` Id bson.ObjectId `bson:"_id"`
Id int Idx int
Trigger string Trigger string
Operator string Operator string
FullText string FullText string
@ -85,8 +85,8 @@ func (p *FactoidPlugin) learnFact(message bot.Message, trigger, operator, fact s
id := int(funcres["retval"].(float64)) id := int(funcres["retval"].(float64))
newfact := Factoid{ newfact := Factoid{
_id: bson.NewObjectId(), Id: bson.NewObjectId(),
Id: id, Idx: id,
Trigger: trigger, Trigger: trigger,
Operator: operator, Operator: operator,
FullText: full, FullText: full,
@ -129,6 +129,14 @@ func (p *FactoidPlugin) sayFact(message bot.Message, fact Factoid) {
} }
} }
// update fact tracking
fact.LastAccessed = time.Now()
fact.AccessCount += 1
err := p.Coll.UpdateId(fact.Id, fact)
if err != nil {
fmt.Printf("Could not update fact.\n")
fmt.Printf("%#v\n", fact)
}
p.LastFact = fact p.LastFact = fact
} }

View File

@ -83,7 +83,7 @@ func (p *RememberPlugin) Message(message bot.Message) bool {
id := int(funcres["retval"].(float64)) id := int(funcres["retval"].(float64))
fact := Factoid{ fact := Factoid{
Id: id, Idx: id,
Trigger: trigger, Trigger: trigger,
Operator: "reply", Operator: "reply",
FullText: msg, FullText: msg,