| ... | ... | @@ -3,8 +3,13 @@ const fs = require('fs'); |
| 3 | 3 | const client = new Discord.Client(); |
| 4 | 4 | const Color = require('color'); |
| 5 | 5 | |
| 6 | function updateClientStatus() { |
| 7 | client.user.setActivity(`!paint -ing ${client.guilds.size} servers.`) |
| 8 | } |
| 9 | |
| 6 | 10 | client.on('ready', () => { |
| 7 | 11 | console.log(`Logged in as ${client.user.tag}!`); |
| 12 | updateClientStatus(); |
| 8 | 13 | }); |
| 9 | 14 | |
| 10 | 15 | client.on('message', async (msg) => { |
| ... | ... | @@ -27,7 +32,7 @@ client.on('message', async (msg) => { |
| 27 | 32 | try { |
| 28 | 33 | color = Color('#' + input); |
| 29 | 34 | } catch (error) { |
| 30 | | msg.channel.send(`> Could not get a color from ${input.replace(/\n/g, '').replace(/`/g, '\\\\`')}`) |
| 35 | msg.channel.send(`> Could not get a color from \`\`${input.substring(0, 500).replace(/\n/g, ' ').replace(/`/g, '\u2063`\u2063')}\`\``) |
| 31 | 36 | return; |
| 32 | 37 | } |
| 33 | 38 | } |
| ... | ... | @@ -58,20 +63,33 @@ client.on('message', async (msg) => { |
| 58 | 63 | const rolesToRemove = msg.member.roles.filter(role => role.name.startsWith('#') && role.name !== hex); |
| 59 | 64 | rolesToRemove.map(async (role) => { |
| 60 | 65 | msg.member.removeRole(role); |
| 61 | | if (role.members.size === 0) { |
| 62 | | console.log('Deleting ' + role.name) |
| 66 | if (role.members.size === 1) { |
| 63 | 67 | role.delete(); |
| 64 | 68 | } |
| 65 | 69 | }); |
| 66 | 70 | await msg.member.addRole(role); |
| 67 | 71 | msg.channel.send(`> You\'ve been painted to **${hex}**`); |
| 68 | 72 | } catch (error) { |
| 69 | | console.log(error); |
| 70 | | msg.channel.send(`> **Error**: Could not assign your role, ask the server admin to check my permissions.`); |
| 73 | msg.channel.send(`> **Error**: Could not assign your role, ask the server admin to check my permissions (Requires 'Manage Roles').`); |
| 71 | 74 | } |
| 72 | 75 | } |
| 73 | 76 | }); |
| 74 | 77 | |
| 78 | client.on('guildMemberRemove', (member) => { |
| 79 | const rolesToRemove = member.roles.filter(role => role.name.startsWith('#')); |
| 80 | setTimeout(() => { |
| 81 | rolesToRemove.map(async (role) => { |
| 82 | if (role.members.size === 0) { |
| 83 | role.delete(); |
| 84 | } |
| 85 | }); |
| 86 | }, 1000); |
| 87 | }); |
| 88 | |
| 89 | client.on('guildDelete', guild => { |
| 90 | 	updateClientStatus(); |
| 91 | }); |
| 92 | |
| 75 | 93 | client.on('guildCreate', guild => { |
| 76 | 94 | let defaultChannel = ""; |
| 77 | 95 | guild.channels.forEach((channel) => { |
| ... | ... | @@ -91,7 +109,11 @@ Some things to note |
| 91 | 109 | |
| 92 | 110 | To use me, simply run |
| 93 | 111 | > !paint <color> |
| 94 | | > Where <color> is any valid HEX or CSS color value.`); |
| 112 | > Where <color> is any valid HEX or CSS color value. |
| 113 | |
| 114 | Created by dave caruso, https://davecode.me, support \`dave@davecode.me\``); |
| 115 | |
| 116 | updateClientStatus(); |
| 95 | 117 | }); |
| 96 | 118 | |
| 97 | | client.login(fs.readFileSync('token').toString().replace(/ |\n/g,'')); |
| 119 | client.login(fs.readFileSync(__dirname + '/token').toString().replace(/ |\n/g,'')); |