-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathindex.js
74 lines (60 loc) · 2.07 KB
/
index.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
const keepAlive = require("./server")
const Discord = require('discord.js');
const dotenv = require('dotenv');
const TOKEN = (process.env.TOKEN);
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) {
let server = client.guilds.cache.get(servers[index]);
if (!server) {
if (config.logging) {
console.log(`[ColorChanger] Server ${servers[index]} was not found. Skipping.`);
}
continue;
}
let role = server.roles.cache.find(r => r.name === config.roleName);
if (!role) {
if (config.logging) {
console.log(`[ColorChanger] The role ${config.roleName} was not found on the server ${servers[index]}. Skipping.`);
}
continue;
}
role.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 < 1) {
console.log("The minimum speed is 60.000, if this gets abused your bot might get banned");
process.exit(1);
}
setInterval(changeColor, config.speed);
changeColor();
});
keepAlive()
client.login(TOKEN);