-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
82 lines (72 loc) · 2.55 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const ontime = require("ontime");
let getData = require("./spreadsheets/googleDataManage").getData;
let startSkypeBot = require("./skype/bot").startSkypeBot;
let updateSkypeBot = require("./skype/bot").updateSkypeBot;
let skipUsers = require("./skype/bot").skipUsers;
let userNames = [];
let botStarted = false;
let prevRows = [];
console.log("BOT STARTED");
function skipOneUser() {
let index;
let meetingsPassed = prevRows.map(function (row) {return +row[1];});
let updatedRows = prevRows.map( function (row, id) {
if (+row[1] === Math.min.apply(null, meetingsPassed) && index === undefined) {
row[1] = +row[1] + 1 + '';
index = id;
}
console.log(row);
return row;
});
getNextInQueue(updatedRows);
}
function getNextInQueue(rows) {
let filteredNames = [];
let newMessage = "";
if (typeof rows === "string") {
newMessage = "No data available";
} else {
prevRows = rows;
let meetingsPassed = rows.map(function (row) {return +row[1];});
let nextPeople = rows.filter(function (row) {return +row[1] === Math.min.apply(null, meetingsPassed);});
let peopleFromStart = rows.filter(
function (row) {return +row[1] === Math.min.apply(null, meetingsPassed) + 1;});
if (nextPeople.length >= 2) {
filteredNames = [nextPeople[0][0], nextPeople[1][0]];
} else if (nextPeople.length === 1) {
filteredNames = [nextPeople[0][0], peopleFromStart[0][0]];
} else {
filteredNames = [peopleFromStart[0][0], peopleFromStart[1][0]];
}
newMessage = `*${filteredNames[0]}* leads today's standup. *${filteredNames[1]}* next in the queue.`;
}
if (botStarted /*&& userNames[0] !== filteredNames[0] && userNames[1] !== filteredNames[1]*/) {
// updateSkypeBot(newMessage);
updateSkypeBot(newMessage, () => getData(getNextInQueue));
} else if (!botStarted /*&& userNames[0] !== filteredNames[0] && userNames[1] !== filteredNames[1]*/){
startSkypeBot(newMessage, () => getData(getNextInQueue));
botStarted = true;
}
userNames = filteredNames;
return filteredNames;
}
// trigger once to check how it works
getData(getNextInQueue);
skipUsers(skipOneUser);
// 8am hour server time is 10am in Ukraine
ontime({
cycle: [
"8:25:00"
],
utc: true,
single: true
}, (ot) => {
let day = new Date().getDay();
if (day === 0 || day === 6 ) {
ot.done();
return;
}
getData(getNextInQueue);
ot.done();
return;
});