Skip to content

Commit

Permalink
Merge pull request #2 from ItsJordan/patch-1
Browse files Browse the repository at this point in the history
Update RainbowRole.js
  • Loading branch information
3ijtKwijt authored Jan 22, 2017
2 parents 9a01947 + 63f8aee commit c26d1e3
Showing 1 changed file with 22 additions and 39 deletions.
61 changes: 22 additions & 39 deletions RainbowRole.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
const Discord = require("discord.js");
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');

var size = config.colors;
var rainbow = new Array(size);
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;
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;
return hex.length === 1 ? '0'+hex : hex;
}

function getTime() {
let place = 0;
const servers = config.servers;

var date = new Date();

var hour = date.getHours();
hour = (hour < 10 ? "0" : "") + hour;

var min = date.getMinutes();
min = (min < 10 ? "0" : "") + min;

var sec = date.getSeconds();
sec = (sec < 10 ? "0" : "") + sec;

return hour + ":" + min + ":" + sec;
}

var place = 0;
var servers = config.servers;

var changeColor = function() {
for (let index = 0; index < servers.length; ++index) {
client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
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("[" + getTime() + " ][ColorChanger] Changed color to " + rainbow[place] + "in server: " + servers[index]);
}
if(place == (size - 1)){
place = 0;
}else{
place++;
}
}
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);
console.log(`Logged in as ${client.user.username}!`);
setInterval(changeColor, config.speed);
});


client.login(config.token);
client.login(config.token);

0 comments on commit c26d1e3

Please sign in to comment.