-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbot.js
50 lines (39 loc) · 1.38 KB
/
bot.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
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
const size = config.colors;
const rainbow = new Array(size);
for (var i=0; i<size; i++) {
var red = sin_to_hex(i, 0 * Math.PI * 2/3); // 0 deg
var blue = sin_to_hex(i, 1 * Math.PI * 2/3); // 120 deg
var green = sin_to_hex(i, 2 * Math.PI * 2/3); // 240 deg
rainbow[i] = '#'+ red + green + blue;
}
function sin_to_hex(i, phase) {
var sin = Math.sin(Math.PI / size * 2 * i + phase);
var int = Math.floor(sin * 127) + 128;
var hex = int.toString(16);
return hex.length === 1 ? '0'+hex : hex;
}
let place = 0;
const servers = config.servers;
function changeColor() {
for (let index = 0; index < servers.length; ++index) {
client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
.catch(console.error);
if(config.logging){
console.log(`[ColorChanger] Changed color to ${rainbow[place]} in server: ${servers[index]}`);
}
if(place == (size - 1)){
place = 0;
}else{
place++;
}
}
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.username}!`);
if(config.speed < 60000){console.log("The minimum speed is 60.000, if this gets abused your bot might get IP-banned"); process.exit(1);}
setInterval(changeColor, config.speed);
});
client.login(config.token);