-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspongecase.js
48 lines (40 loc) · 1.35 KB
/
spongecase.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
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
module.exports = function(controller) {
const spongeCase = (text) => {
// here's the dang algorithm
let counter = 0;
let spongeArray = [];
text.split('').forEach((chr) => {
if (/[A-Za-z]/.test(chr)) {
if (counter % 2 == 0) {
spongeArray.push(chr.toUpperCase());
} else {
spongeArray.push(chr.toLowerCase());
}
counter = counter + 1;
} else {
spongeArray.push(chr);
}
});
spongeString = spongeArray.join('');
return spongeString;
}
// !spongecase
controller.hears(/^!spongecase/i, ['message','direct_message'], async function(bot, message) {
// removes command
let tokens = message.text.split(' ')
tokens.shift();
let str = tokens.join(' ');
await bot.reply(message,{ text: spongeCase(str) });
});
// randomly spongecase things sometimes because CHAOS ENERGY
controller.on('message', async function(bot, message) {
let chance = Math.floor(Math.random() * 1000);
if (chance > 980) {
await bot.reply(message,{ text: spongeCase(message.text) });
}
});
}