Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Allow participants to opt-out and opt-in for data collection during a…
Browse files Browse the repository at this point in the history
… testday (#46)
  • Loading branch information
galgeek authored and whimboo committed Jan 15, 2015
1 parent f8e779c commit c94db45
Showing 1 changed file with 49 additions and 41 deletions.
90 changes: 49 additions & 41 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ var ircServer = config.server,
timerID = 0,
topic = "",
topic_backup = "",
lastQuit = {},
optOut = [],
metrics = {
greetedName: [],
greetedNumber: 0,
firebotBugs:[],
usersTalked: {},
activeUsers: {},
hourUTC: {},
optOutTotal: 0,
},
help = { ":help" : "This is Help! :)",
":bug" : "Learn how to report a bug",
":qmo" : "Learn about Quality at Mozilla",
":sumo" : "Learn about Support at Mozilla",
":etherpad" : "View the Test Day etherpad",
":helpers" : "View Test Day helpers, and request help with :helpers request",
":schedule" : "View the Test Day schedule"
":schedule" : "View the Test Day schedule",
":optout" : "Opt out from Test Day data collection for your nick",
":optin" : "Opt in (default) to Test Day data collection for your nick"
},
adminhelp = { ":adminhelp" : "This is Admin Help! :)",
":addAdmin" : ":addAdmin <nickname> as a Test Day admin",
Expand All @@ -51,13 +52,11 @@ var ircServer = config.server,
function resetData() {
admins = config.admins;
helpers = config.helpers;
lastQuit = {};
metrics = {
greetedName: [],
greetedNumber: 0,
firebotBugs:[],
usersTalked: {},
activeUsers: {},
hourUTC: {},
optOutTotal: 0,
start: startTime.toUTCString(),
end: endTime.toUTCString(),
etherpad: etherpad,
Expand Down Expand Up @@ -88,17 +87,6 @@ client.addListener('topic', function (aChannel, aChannelTopic, aNick) {
}
});

client.addListener('join', function(aChannel, who){
if (testDay){ // record stats only on test days
if (who !== nick){
if (!lastQuit[who]){
metrics.greetedName.push(who);
metrics.greetedNumber +=1;
}
}
}
});

client.addListener('message', function(from, to, message) {
var intro;

Expand Down Expand Up @@ -185,17 +173,48 @@ client.addListener('message', function(from, to, message) {
client.say(to, intro + scheduleTimes);
}

if (message.search('[!:]optout') === 0) {
if (optOut.indexOf(from) === -1) {
optOut.push(from);
metrics.optOutTotal += 1;
if (from in metrics.activeUsers) {
delete metrics.activeUsers[from];
}
}
client.say(from, "You’ve opted out of Test Day data collection " +
"for your nick " + from + ".");
}

if (message.search('[!:]optin') === 0) {
if (optOut.indexOf(from) >= 0) {
optOut.splice(optOut.indexOf(from), 1);
// on Test Days, add to metrics to avoid second(?) opt out notice
if (testDay) {
metrics.activeUsers[from] = 0;
}
}
client.say(from, "You’re opted in to Test Day data collection " +
"for your nick " + from + ".");
}

if (testDay) {
if (from === 'firebot') {
if (message.search(/https:\/\/bugzilla.mozilla.org\/show_bug.cgi\?id=(\d+)/i) >= 0) {
metrics.firebotBugs.push(/https:\/\/bugzilla.mozilla.org\/show_bug.cgi\?id=(\d+)/i.exec(message)[1]);
}
}
if (from in metrics.usersTalked) {
metrics.usersTalked[from] += 1;
} else {
metrics.usersTalked[from] = 1;

// if from is not on the opt out list
if (optOut.indexOf(from) === -1) {
if (from in metrics.activeUsers) {
metrics.activeUsers[from] += 1;
} else {
client.say(from, "Welcome to today’s Test Day, " + from + "!");
client.say(from, "To opt out of data collection, use the command :optout.");
metrics.activeUsers[from] = 1;
}
}

var nowHour = new Date().getUTCHours().toString();
if (nowHour in metrics.hourUTC) {
metrics.hourUTC[nowHour] += 1;
Expand Down Expand Up @@ -310,18 +329,6 @@ client.addListener('pm', function(from, message) { // private messages to bot
});
});

client.addListener('quit', function(who, reason, aChannel){
if (testDay){
lastQuit[who] = Date.now();
}
});

client.addListener('part', function(aChannel, who, reason){
if (testDay){
lastQuit[who] = Date.now();
}
});

client.addListener('error', function(message) {
console.error('ERROR: %s: %s', message.command, message.args.join(' '));
});
Expand All @@ -335,11 +342,12 @@ Stats.prototype.generateStats = function(metrcs, from) {
if (what.call(metrcs[keys[i]]).search('Array') > 0) {
client.say(from, keys[i] + ": " + metrcs[keys[i]].join(", "));
} else {
if (keys[i] == "usersTalked") {
client.say(from, "The following people were active in the channel: ");
var speakers = Object.keys(metrcs.usersTalked);
for (var t = 0; t < speakers.length; t++) {
client.say(from, speakers[t] + ": " + metrcs.usersTalked[speakers[t]]);
if (keys[i] == "activeUsers") {
var speakers = Object.keys(metrcs.activeUsers);
var speakersTotal = speakers.length;
client.say(from, "The following " + speakersTotal + " people were active in the channel: ");
for (var t = 0; t < speakersTotal; t++) {
client.say(from, speakers[t] + ": " + metrcs.activeUsers[speakers[t]]);
}
} else if (keys[i] == "hourUTC") {
client.say(from, "The following hours (UTC) were active in the channel: ");
Expand Down

0 comments on commit c94db45

Please sign in to comment.