11import { MessageEmbed } from 'discord.js' ;
2- import { EmojiDoesNotExistException } from '../exceptions/runtime.exceptions.js' ;
2+ import {
3+ EmojiDoesNotExistException ,
4+ InvalidColorException ,
5+ } from '../exceptions/runtime.exceptions.js' ;
6+ import { isHexColor } from './tools.js' ;
37
48export class reactionTools {
59 static async configureReactions ( interaction , client ) {
@@ -23,10 +27,20 @@ export class reactionTools {
2327 static async addCategory ( interaction , client ) {
2428 const name = interaction . options . getString ( 'name' ) ;
2529 const description = interaction . options . getString ( 'description' ) ;
30+ const color = interaction . options . getString ( 'color' ) ;
2631
2732 const reactionService = client . database . ReactionService ;
2833
29- await reactionService . create ( interaction . guild . id , name , description ) ;
34+ let colorValidation = isHexColor ( color ) ;
35+
36+ //Validation
37+ if ( ! colorValidation ) {
38+ throw new InvalidColorException (
39+ 'Color verification failed. Make sure you use an Hexadecimal color. e.g. #aa22cc or #a2c'
40+ ) ;
41+ }
42+
43+ await reactionService . create ( interaction . guild . id , name , description , color ) ;
3044
3145 await this . updateRoleMessage ( client , interaction . guild , name ) ;
3246 }
@@ -35,6 +49,7 @@ export class reactionTools {
3549 const name = interaction . options . getString ( 'name' ) ;
3650 const description = interaction . options . getString ( 'description' ) ;
3751 const newName = interaction . options . getString ( 'new-name' ) ;
52+ const color = interaction . options . getString ( 'color' ) ;
3853
3954 const reactionService = client . database . ReactionService ;
4055
@@ -44,6 +59,18 @@ export class reactionTools {
4459 await reactionService . updateDescription ( interaction . guild . id , name , description ) ;
4560 }
4661
62+ if ( ! ! color ?. length ) {
63+ let colorValidation = isHexColor ( color ) ;
64+ console . log ( color ) ;
65+ //Validation
66+ if ( ! colorValidation ) {
67+ throw new InvalidColorException (
68+ 'Color verification failed. Make sure you use an Hexadecimal color. e.g. #aa22cc or #a2c'
69+ ) ;
70+ }
71+ await reactionService . updateColor ( interaction . guild . id , name , color ) ;
72+ }
73+
4774 if ( ! ! newName ?. length ) {
4875 await reactionService . updateName ( interaction . guild . id , name , newName ) ;
4976 updateName = newName ;
@@ -79,12 +106,9 @@ export class reactionTools {
79106
80107 //Validation
81108 if ( ! emojiValidation ) {
82- await interaction . reply ( {
83- content :
84- 'Emoji verification failed. Make sure you use an guild or unicode emoji. Emoji from other servers will not work.' ,
85- ephemeral : true ,
86- } ) ;
87- return ;
109+ throw new EmojiDoesNotExistException (
110+ 'Emoji verification failed. Make sure you use an guild or unicode emoji. Emoji from other servers will not work.'
111+ ) ;
88112 }
89113
90114 await reactionRoleService . create ( interaction . guild . id , category , role , description , emoji ) ;
@@ -155,6 +179,10 @@ export class reactionTools {
155179 body . push ( '' ) ;
156180 }
157181
182+ if ( category . color ) {
183+ message . setColor ( category . color ) ;
184+ }
185+
158186 category . roles . forEach ( ( role ) => {
159187 let roleText = role . description ? role . description : '<@&' + role . id + '>' ;
160188 body . push ( role . emoji + ' - ' + roleText ) ;
0 commit comments