-
Notifications
You must be signed in to change notification settings - Fork 4
/
repeat.js
46 lines (43 loc) · 1.31 KB
/
repeat.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
let i = 0;
const messages = ["", "", ""];
const users = ["", "", ""];
const length = 3;
function prev(x) {
return (i - x + length) % length;
}
async function add(chatClient, channel, user, msg) {
if (msg.startsWith("!")) {
return;
}
if (msg.toLowerCase().includes("of all time") && !msg.includes("?")) {
await chatClient.say(channel, "so true");
return;
}
const message = msg.toLowerCase().replace(/[.,/?#!$%^&*;:{}=\-_`~()]/g, "")
messages[i] = message;
users[i] = user;
if (message === messages[prev(1)] && message === messages[prev(2)] &&
user !== users[prev(1)] && user !== users[prev(2)]) {
// One in 20 times, say Lea! instead.
if (Math.random() < 0.05) {
await chatClient.say(channel, "Lea!");
} else {
await chatClient.say(channel, message);
}
messages[i] = "";
users[i] = "";
}
if (message === messages[prev(1)] &&
user === users[prev(1)]) {
// One in 20 times, say Lea! instead.
if (Math.random() < 0.05) {
await chatClient.say(channel, "Lea!");
} else {
await chatClient.say(channel, `${message}?`);
}
messages[i] = "";
users[i] = "";
}
i = (i + 1) % length;
}
module.exports = { add };