@@ -3,32 +3,39 @@ const Utils = require('../utils/Utils.js');
33const { HELP , HELP_SHORT } = require ( '../assets/flags.json' ) ;
44
55const configuration = {
6- enabled : true ,
7- name : 'edit-color' ,
8- aliases : [ 'edit' ] ,
9- description : 'Edits a role color.' ,
10- usage : 'edit-role <ROLE> <HEX_COLOR>' ,
6+ enabled : true ,
7+ name : 'edit-color' ,
8+ aliases : [ 'edit' ] ,
9+ description : 'Edits a role color.' ,
10+ usage : 'edit-role <ROLE> <HEX_COLOR>' ,
1111} ;
1212
1313module . exports = {
14- conf : configuration ,
14+ conf : configuration ,
1515
16- run : async ( client , message , args ) => {
17- const guild = message . guild ;
16+ run : async ( client , message , args ) => {
17+ const guild = message . guild ;
1818
19- if ( args [ 0 ] === HELP || args [ 0 ] === HELP_SHORT || args . length < 2 || ! guild ) {
20- helpEmbed ( message , configuration ) ;
21- Utils . errAndMsg ( message . channel , 'Invalid arguments.' ) ;
22- } else {
23- try {
24- const role = guild . roles . find ( role => role . name === args [ 0 ] ) ;
25- await role . setColor ( args [ 1 ] ) ;
26- Utils . logAndMsg ( message . channel , `Updated role ${ args [ 0 ] } 's color to ${ role . color } ` ) ;
27- } catch ( err ) {
28- console . error ( err ) ;
29- message . channel . send ( `Couldn't update role ${ args [ 0 ] } 's color because: ${ err } ` ) ;
30- }
31- }
32- return ;
33- } ,
19+ if ( args [ 0 ] === HELP || args [ 0 ] === HELP_SHORT || args . length < 2 || ! guild ) {
20+ helpEmbed ( message , configuration ) ;
21+ Utils . errAndMsg ( message . channel , 'Invalid arguments.' ) ;
22+ } else {
23+ try {
24+ let name = args [ 0 ] ;
25+ let color = args [ 1 ]
26+ if ( args . length > 2 ) {
27+ name = args . slice ( 1 , - 1 ) . reduce ( ( str , val ) => str + ' ' + val , args [ 0 ] ) ;
28+ color = args [ args . length - 1 ]
29+ }
30+
31+ const role = guild . roles . find ( role => role . name === name ) ;
32+ await role . setColor ( color ) ;
33+ Utils . logAndMsg ( message . channel , `Updated role \`${ args [ 0 ] } \`'s color to \`${ role . color } \`` ) ;
34+ } catch ( err ) {
35+ console . error ( err ) ;
36+ message . channel . send ( `Couldn't update role \`${ args [ 0 ] } \`'s color because: ${ err } ` ) ;
37+ }
38+ }
39+ return ;
40+ } ,
3441} ;
0 commit comments