Advertisement
2wild4u

rainbow.js

Jun 8th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const client = new Discord.Client();
  3. const config = require('./config.json');
  4.  
  5. const size = config.colors;
  6. const rainbow = new Array(size);
  7.  
  8. for (var i=0; i<size; i++) {
  9. var red = sin_to_hex(i, 0 * Math.PI * 2/3); // 0 deg
  10. var blue = sin_to_hex(i, 1 * Math.PI * 2/3); // 120 deg
  11. var green = sin_to_hex(i, 2 * Math.PI * 2/3); // 240 deg
  12.  
  13. rainbow[i] = '#'+ red + green + blue;
  14. }
  15.  
  16. function sin_to_hex(i, phase) {
  17. var sin = Math.sin(Math.PI / size * 2 * i + phase);
  18. var int = Math.floor(sin * 127) + 128;
  19. var hex = int.toString(16);
  20.  
  21. return hex.length === 1 ? '0'+hex : hex;
  22. }
  23.  
  24. let place = 0;
  25. const servers = config.servers;
  26.  
  27. function changeColor() {
  28. for (let index = 0; index < servers.length; ++index) {
  29. client.guilds.get(servers[index]).roles.find('name', config.roleName).setColor(rainbow[place])
  30. .catch(console.error);
  31.  
  32. if(config.logging){
  33. console.log(`[ColorChanger] Changed color to ${rainbow[place]} in server: ${servers[index]}`);
  34. }
  35. if(place == (size - 1)){
  36. place = 0;
  37. }else{
  38. place++;
  39. }
  40. }
  41. }
  42.  
  43. client.on('ready', () => {
  44. console.log(`Logged in as ${client.user.username}!`);
  45. 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);}
  46. setInterval(changeColor, config.speed);
  47. });
  48.  
  49.  
  50. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement