-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdestiny-handler.js
139 lines (117 loc) · 5.36 KB
/
destiny-handler.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var DiceRoller = require('./diceRoller.js');
const DestinyPool = require('./destinyPool.js');
var destinyMatch = /^!Destiny Flip ((Dark)|(Light))/i;
var destinyAddMatch = /^!Destiny Add ((Dark)|(Light))/i;
var destinySetMatch = /^![Dd]estiny Set \[([DL]*)\]/i;
var poolMatch = /^!Destiny Roll/i;
var clearMatch = /^!Destiny Reset/i;
var showMatch = /^!Destiny Show/i;
var destinyHelpMatch = /^!Destiny Help/i;
exports.handleMessage = function(message, channelID, serverDice, serverSymbols, emojiServerID, sendMessages, printSymbols) {
if (message.match(poolMatch)) {
let destinyPool = new DestinyPool(channelID, []);
destinyPool.getPool().then(function(pool){
let roller = new DiceRoller(serverDice);
roller.roll('f');
pool = pool.concat(roller.symbolResults);
destinyPool.setPool(pool).then(function(result){
var returnMessage = "Adding " + printSymbols(roller.symbolResults, emojiServerID) + " to destiny pool";
var poolMessage = "Current destiny pool: " + printSymbols(pool, emojiServerID);
sendMessages(channelID, [roller.diceResults[0].code, returnMessage, poolMessage]);
});
});
}
if (message.match(clearMatch)) {
let destinyPool = new DestinyPool(channelID, []);
destinyPool.setPool([]).then(function(result){
sendMessages(channelID, ["Destiny Pool reset for this channel."]);
});
}
if (message.match(showMatch)) {
let destinyPool = new DestinyPool(channelID, []);
destinyPool.getPool().then(function(pool){
if (pool.length == 0){
sendMessages(channelID, ["No Destiny points have been rolled for this channel. Use `!Destiny Roll` to begin."]);
return;
} else {
var poolMessage = "Current destiny pool: " + printSymbols(pool, emojiServerID);
sendMessages(channelID, [poolMessage]);
}
});
}
if (message.match(destinyHelpMatch)){
var message = "```Available Commands:\n";
message += "!Destiny Roll\n";
message += "!Destiny Flip (Dark|Light)\n";
message += "!Destiny Add (Dark|Light)\n";
message += "!Destiny Show\n";
message += "!Destiny Reset\n";
message += "!Destiny Set [DL]\n";
message += " ^ This can be in any combination of (D)ark and (L)ight```";
sendMessages(channelID, [message]);
}
if (message.match(destinyMatch)) {
let destinyPool = new DestinyPool(channelID, []);
destinyPool.getPool().then(function(pool){
var returnMessage = "";
var match = destinyMatch.exec(message);
if (match[1].toLowerCase() === "dark") {
if (pool.indexOf(dark) !== -1) {
returnMessage += "Flipping a Dark Side point.";
pool[pool.indexOf(dark)] = light;
} else {
returnMessage += "No Dark Side points to flip.";
}
} else if (match[1].toLowerCase() === "light") {
if (pool.indexOf(light) !== -1) {
returnMessage += "Flipping a Light Side point.";
pool[pool.indexOf(light)] = dark;
} else {
returnMessage += "No Light Side points to flip.";
}
} else {
returnMessage += "The Force is confused.";
}
destinyPool.setPool(pool).then(function(result){
var poolMessage = "Current destiny pool: " + printSymbols(pool, emojiServerID);
sendMessages(channelID, [returnMessage + "\n" + poolMessage]);
});
});
}
if (message.match(destinyAddMatch)) {
let destinyPool = new DestinyPool(channelID, []);
destinyPool.getPool().then(function(pool){
var match = destinyAddMatch.exec(message);
var symbols = [];
symbols.push(match[1]);
returnMessage += "Adding " + printSymbols(symbols, emojiServerID) + " to the destiny pool.";
pool = pool.concat(symbols);
destinyPool.setPool(pool).then(function(result){
var returnMessage = "Adding " + printSymbols(symbols, emojiServerID) + " to destiny pool";
var poolMessage = "Current destiny pool: " + printSymbols(pool, emojiServerID);
sendMessages(channelID, [returnMessage, poolMessage]);
});
}).catch(function(err){
console.log(err);
});
}
if (message.match(destinySetMatch)) {
let destinyPool = new DestinyPool(channelID, []);
var returnMessage = "";
var pool = [];
var match = destinySetMatch.exec(message);
var destinyTokens = match[1].split('');
destinyTokens.forEach(function(token) {
token = token.toLocaleLowerCase();
if (token == 'd') {
pool.push('Dark');
} else if (token == 'l') {
pool.push('Light');
}
});
destinyPool.setPool(pool).then(function(result){
var poolMessage = "Destiny Pool set as specified: " + printSymbols(pool, emojiServerID);
sendMessages(channelID, [returnMessage + "\n" + poolMessage]);
});
}
}