@@ -195,12 +195,13 @@ client.on("ready", () => {
195195 return respondToNonCommands ( message ) ;
196196 }
197197
198+ const canSendMessages = clientHasPermissionInChannel ( permissions . sendMessages , channel ) ;
198199 const shouldReject = developmentEnvironment && ! isSentInDevelopmentGuild ( message ) ;
199200 const args = substring . split ( / \s + / gi) ;
200201 switch ( args [ 0 ] . toLowerCase ( ) ) {
201202
202203 case "help" : {
203- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
204+ if ( ! canSendMessages || shouldReject ) {
204205 return ;
205206 }
206207 channel . send ( helpString )
@@ -218,7 +219,7 @@ client.on("ready", () => {
218219 }
219220
220221 case "ping" : {
221- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
222+ if ( ! canSendMessages || shouldReject ) {
222223 return ;
223224 }
224225 const ping = client . ping ;
@@ -239,7 +240,7 @@ client.on("ready", () => {
239240 }
240241
241242 case "ship" : {
242- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
243+ if ( ! canSendMessages || shouldReject ) {
243244 return ;
244245 }
245246 const firstUser = ( args . length >= 2 && args [ 1 ] . toLowerCase ( ) === "me" ) ? author : message . guild . members . random ( ) . user ;
@@ -282,7 +283,7 @@ client.on("ready", () => {
282283 messageToSend = `Please provide a value to remind you for. Example: ${ code ( "/remindme 3d Do homework" ) } ` ;
283284 }
284285 }
285- if ( messageToSend !== undefined && clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
286+ if ( messageToSend !== undefined && canSendMessages ) {
286287 return message . reply ( messageToSend )
287288 . catch ( error => console . error ( `An error occured while replying "${ messageToSend } " to message!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
288289 }
@@ -291,15 +292,15 @@ client.on("ready", () => {
291292 }
292293 const matched = getMatchedOriginalFromArgs ( message , args , 2 ) ;
293294 const reminder = matched === null ? args . slice ( 2 ) . join ( " " ) : message . content . substring ( matched . length ) ;
294- if ( clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
295+ if ( canSendMessages ) {
295296 messageToSend = "Timer set! \ud83d\udd5c" ;
296297 channel . send ( messageToSend )
297298 . catch ( error => console . error ( `An error occured while sending message "${ messageToSend } "!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
298299 }
299300 messageToSend = `\ud83d\udd5c ${ bold ( "DING!" ) } Reminder text: ${ bold ( reminder ) } . Reminder time set: ${ bold ( ms ( timeout , { long : true } ) ) } ` ;
300301 reminderTimerList . push ( setTimeout ( ( ) => author . send ( messageToSend , sendOptionsForLongMessage )
301302 . catch ( error => {
302- if ( clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
303+ if ( canSendMessages ) {
303304 message . reply ( dmUnavailableString )
304305 . catch ( error => console . error ( `An error occured while replying "${ dmUnavailableString } " to message!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
305306 }
@@ -309,7 +310,7 @@ client.on("ready", () => {
309310 }
310311
311312 case "give" : {
312- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
313+ if ( ! canSendMessages || shouldReject ) {
313314 return ;
314315 }
315316 let messageToSend ;
@@ -359,7 +360,7 @@ client.on("ready", () => {
359360
360361 case "eightball" :
361362 case "8ball" : {
362- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
363+ if ( ! canSendMessages || shouldReject ) {
363364 return ;
364365 }
365366 let messageToSend ;
@@ -378,7 +379,7 @@ client.on("ready", () => {
378379 case "github" :
379380 case "repo" :
380381 case "repository" : {
381- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
382+ if ( ! canSendMessages || shouldReject ) {
382383 return ;
383384 }
384385 channel . send ( repositoryString )
@@ -390,7 +391,7 @@ client.on("ready", () => {
390391 if ( shouldReject ) {
391392 return ;
392393 }
393- if ( ! isDeveloper ( author ) && clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
394+ if ( ! isDeveloper ( author ) && canSendMessages ) {
394395 const messageToSend = "You don't have permission to stop ChillBot!" ;
395396 return message . reply ( messageToSend )
396397 . catch ( error => console . error ( `An error occured while replying "${ messageToSend } " to message!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
@@ -403,7 +404,7 @@ client.on("ready", () => {
403404 if ( shouldReject ) {
404405 return ;
405406 }
406- if ( ! isDeveloper ( author ) && clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
407+ if ( ! isDeveloper ( author ) && canSendMessages ) {
407408 const messageToSend = "You don't have permission to restart ChillBot!" ;
408409 return message . reply ( messageToSend )
409410 . catch ( error => console . error ( `An error occured while replying "${ messageToSend } " to message!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
@@ -414,7 +415,7 @@ client.on("ready", () => {
414415
415416 case "osslicenses" :
416417 case "opensourcelicenses" : {
417- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
418+ if ( ! canSendMessages || shouldReject ) {
418419 return ;
419420 }
420421 const guildID = message . guild . id ;
@@ -458,7 +459,7 @@ client.on("ready", () => {
458459 case "changes" :
459460 case "changelog" :
460461 case "changelogs" : {
461- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
462+ if ( ! canSendMessages || shouldReject ) {
462463 return ;
463464 }
464465 let messageToSend ;
@@ -545,7 +546,7 @@ client.on("ready", () => {
545546 }
546547
547548 case "invite" : {
548- if ( ! clientHasPermissionInChannel ( permissions . sendMessages , channel ) || shouldReject ) {
549+ if ( ! canSendMessages || shouldReject ) {
549550 return ;
550551 }
551552 channel . send ( inviteString )
@@ -569,7 +570,7 @@ function handleGenerically(error, channel) {
569570 }
570571 console . error ( error . toString ( ) ) ;
571572 console . trace ( ) ;
572- if ( ! ( client === undefined || client === null || channel === undefined || channel === null ) && clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
573+ if ( ! ( client === undefined || client === null || channel === undefined || channel === null ) && canSendMessages ) {
573574 const messageToSend = "Sorry, an error occured."
574575 channel . send ( messageToSend )
575576 . catch ( error => console . error ( `An error occured while sending message "${ messageToSend } "!\n\nFull details:\n${ error . toString ( ) } ` ) ) ;
@@ -799,7 +800,7 @@ function respondToNonCommands(message) {
799800 throw new TypeError ( "Incorrect type for respondToNonCommands argument!" ) ;
800801 }
801802 const channel = message . channel ;
802- if ( hasMentionForUser ( message , client . user ) && clientHasPermissionInChannel ( permissions . sendMessages , channel ) ) {
803+ if ( hasMentionForUser ( message , client . user ) && canSendMessages ) {
803804 let messageToSend = getRandomFromArray ( response . mentioned ) ;
804805 if ( developmentEnvironment && ! isSentInDevelopmentGuild ( message ) ) {
805806 messageToSend = botUnavailableString ;
0 commit comments