Skip to content

Commit

Permalink
Adding the factoid's creator and a list of its editors to the JSON da…
Browse files Browse the repository at this point in the history
…tabase.
  • Loading branch information
ljharb committed Sep 23, 2012
1 parent 808ed52 commit f713fb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/factoidserv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ var FactoidServer = module.exports = function(filename) {
};


FactoidServer.prototype.learn = function(key, value) {
FactoidServer.prototype.learn = function(key, value, username) {

var db = this.db.object.factoids;

var popularity = 0;
var creator = username;
var editors = [];
key = key.toLowerCase();

if (typeof db[key] !== "undefined") {
if (typeof db[key].alias !== "undefined") {
return this.learn(db[key].alias, value);
return this.learn(db[key].alias, value, username);
}
creator = db[key].creator;
editors = db[key].editors || [];
editors.push(username);
popularity = db[key].popularity || 0;
}

db[key] = {value: value, popularity: popularity};
db[key] = {value: value, popularity: popularity, creator: creator, editors: editors};
this.db.activity();
};

Expand Down
4 changes: 2 additions & 2 deletions shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var Shared = module.exports = {

/* Setting the text of a factoid */
if (operation === "=") {
this.factoids.learn(factoid, value);
this.factoids.learn(factoid, value, context.sender);
context.channel.send_reply(context.sender, "Learned `"+factoid+"`.");
return;

Expand All @@ -139,7 +139,7 @@ var Shared = module.exports = {
if (old === result) {
context.channel.send_reply(context.sender, "Nothing changed.");
} else {
this.factoids.learn(factoid, result);
this.factoids. learn(factoid, result, context.sender);
context.channel.send_reply(context.sender, "Changed `"+factoid+
"` to: "+result);
}
Expand Down

0 comments on commit f713fb1

Please sign in to comment.