forked from volas/ny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (49 loc) · 1.28 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
"use strict";
const Discord = require('discord.js');
const config = require('./config.json');
const client = new Discord.Client({
intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES]
});
const discordToken = process.env.DISCORD_TOKEN;
const triggerCooldown = 4000;
let angryCounter = 0;
let lastTrigger = 0;
for (let trigger of config.triggers){
trigger.regexp = new RegExp(trigger.regexp, "i");
}
client.login(discordToken);
client.on('messageCreate', async message => {
if (message.author.bot || message.channel.type === 'dm') {
return;
}
if(lastTrigger + triggerCooldown >= Date.now()) {
return;
}
for (let trigger of config.triggers){
if(trigger.regexp.test(message.content)) {
angryCounter++;
lastTrigger = Date.now();
let answer = trigger.answers[Math.floor(Math.random()*trigger.answers.length)];
if(angryCounter >= 3) {
let angryChance = angryCounter*0.1;
answer = answer.split("").map(
l => (Math.random() < angryChance) ? l.toUpperCase() : l
).join("");
}
return message.reply(answer);
}
}
});
client.on('ready', () => {
console.log(config);
console.log("Ready");
setInterval(function()
{
if(angryCounter > 0) {
angryCounter--;
}
if(angryCounter > 10) {
angryCounter = 0;
}
}, 60000);
});