-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ItsJordan/patch-1
Update RainbowRole.js
- Loading branch information
Showing
1 changed file
with
22 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |