@@ -28,53 +28,37 @@ export class ButtonHandler {
28
28
* This can happen if users swap types and leave old messages up.
29
29
*/
30
30
if ( config ?. reactType !== GuildReactType . button ) {
31
- return interaction . editReply (
32
- `Hey! The server doesn't use button roles! The button you clicked must be out of date.` ,
33
- ) ;
31
+ this . log . debug ( `User pressed button when guild config isn't button.` , guildId ) ;
32
+ return interaction . editReply ( `Hey! The server doesn't use button roles! The button you clicked must be out of date.` ) ;
34
33
}
35
34
36
35
const [ reactRoleId , categoryId ] = args ;
37
36
38
37
if ( isNaN ( Number ( reactRoleId ) ) || isNaN ( Number ( categoryId ) ) ) {
39
- return interaction . editReply (
40
- `Hey! Something went wrong with processing that button press! reactRoleId: ${ reactRoleId } | categoryId: ${ categoryId } ` ,
41
- ) ;
38
+ this . log . error ( `Invalid reactRoleId[${ reactRoleId } ] or categoryId[${ categoryId } ] for button press.` , guildId ) ;
39
+ return interaction . editReply ( `Hey! Something went wrong with processing that button press! reactRoleId: ${ reactRoleId } | categoryId: ${ categoryId } ` ) ;
42
40
}
43
41
44
42
const reactRole = await GET_REACT_ROLE_BY_ID ( Number ( reactRoleId ) ) ;
45
43
const category = await GET_CATEGORY_BY_ID ( Number ( categoryId ) ) ;
46
44
47
45
if ( ! reactRole || ! category ) {
48
- return interaction . editReply (
49
- `Hey! I failed to find the react role or category related to this button.` ,
50
- ) ;
46
+ this . log . debug ( `ReactRole[${ reactRole } ] of Category[${ categoryId } ] could not be found` , guildId ) ;
47
+ return interaction . editReply ( `Hey! I failed to find the react role or category related to this button.` ) ;
51
48
}
52
49
53
50
const member = await interaction . guild ?. members
54
51
. fetch ( interaction . user . id )
55
- . catch ( ( e ) =>
56
- this . log . error (
57
- `Fetching user[${ interaction . user . id } ] threw an error.\n${ e } ` ,
58
- ) ,
59
- ) ;
52
+ . catch ( e => this . log . error ( `Fetching user[${ interaction . user . id } ] threw an error.\n${ e } ` ) ) ;
60
53
61
54
if ( ! member ) {
62
- this . log . debug (
63
- `Failed to grab member object from interaction.` ,
64
- interaction . guildId ,
65
- ) ;
55
+ this . log . debug ( `Failed to grab member object from interaction.` , interaction . guildId ) ;
66
56
67
- return interaction . editReply (
68
- `Heyo! I had some issues finding _you_ here.` ,
69
- ) ;
57
+ return interaction . editReply ( `Heyo! I had some issues finding _you_ here.` ) ;
70
58
}
71
59
72
60
// If the category limits who can react and the user doesn't have said role ignore request.
73
- if (
74
- category . requiredRoleId &&
75
- ! member . roles . cache . has ( category . requiredRoleId )
76
- ) {
77
- // Remove reaction as to not confuse the user that they succeeded.
61
+ if ( category . requiredRoleId && ! member . roles . cache . has ( category . requiredRoleId ) ) {
78
62
return interaction . editReply (
79
63
`Hey! You lack the required role to get anything from this category. ${ RolePing (
80
64
category . requiredRoleId ,
@@ -83,10 +67,7 @@ export class ButtonHandler {
83
67
}
84
68
85
69
// If the category has an excluded role, and the user has said excluded role, ignore request.
86
- if (
87
- category . excludedRoleId &&
88
- member . roles . cache . has ( category . excludedRoleId )
89
- ) {
70
+ if ( category . excludedRoleId && member . roles . cache . has ( category . excludedRoleId ) ) {
90
71
return interaction . editReply (
91
72
`Heyo! You have a role that prevents you from obtaining anything from this category. ${ RolePing (
92
73
category . excludedRoleId ,
@@ -110,6 +91,8 @@ export class ButtonHandler {
110
91
) ;
111
92
} ;
112
93
94
+ this . log . debug ( `User[${ member . id } ] pressed button for ReactRole[${ reactRoleId } ] Category[${ categoryId } ]` , guildId ) ;
95
+
113
96
// Remove the role if the user has it. Should catch mutually exclusive removes too.
114
97
if ( member . roles . cache . has ( reactRole . roleId ) ) {
115
98
member . roles
@@ -158,33 +141,27 @@ export class ButtonHandler {
158
141
) ;
159
142
160
143
await member . roles . remove ( rolesToRemove ) . catch ( ( e ) => {
161
- this . log . error (
162
- `Failed to remove roles[${ rolesToRemove } ] from user[${ member . id } ]\n${ e } ` ,
163
- ) ;
144
+ this . log . error ( `Failed to remove roles[${ rolesToRemove } ] from user[${ member . id } ]\n${ e } ` ) ;
164
145
165
- return interaction . editReply (
166
- `Hey! I couldn't remove some mutually exclusive roles from you. Do I have the manage role permission?` ,
167
- ) ;
146
+ return interaction . editReply ( `Hey! I couldn't remove some mutually exclusive roles from you. Do I have the manage role permission?` ) ;
168
147
} ) ;
169
148
170
149
await member . roles . add ( role . roleId ) . catch ( ( e ) => {
171
- this . log . error (
172
- `Failed to add role[${ role . roleId } ] from user[${ member . id } ]\n${ e } ` ,
173
- ) ;
150
+ this . log . error ( `Failed to add role[${ role . roleId } ] from user[${ member . id } ]\n${ e } ` ) ;
174
151
175
152
return interaction . editReply (
176
153
`Hey! I couldn't add the role ${ RolePing (
177
154
role . roleId ,
178
155
) } . Do I the manage roles permission?`,
179
156
) ;
180
157
} ) ;
181
-
158
+
182
159
const removedRoles = ` and removed ${ rolesToRemove . map ( ( r ) => RolePing ( r . id ) ) . join ( ' ' ) } ` ;
183
160
184
161
return interaction . editReply (
185
162
`Hey! I gave you the ${ RolePing (
186
163
role . roleId ,
187
- ) } role${ rolesToRemove . size ? removedRoles : '.' } `,
164
+ ) } role${ rolesToRemove . size ? removedRoles : '.' } `,
188
165
) ;
189
166
} ;
190
167
}
0 commit comments