1- import { Events } from 'discord.js' ;
1+ import { Events , type Message , PermissionFlagsBits } from 'discord.js' ;
22import { MINUTE } from '../constants/time.js' ;
3+ import { config } from '../env.js' ;
34import { createEvent } from '../util/events.js' ;
45import { loadMarkdownOptions } from '../util/markdown.js' ;
56import { rateLimit } from '../util/rate-limit.js' ;
@@ -20,7 +21,7 @@ const reQuestion = `(?:experience|knowledge|info(?:rmation)?|ideas?|clues?|tips?
2021const reConnector = `(?:with|about|on|regarding|for|of)` ;
2122
2223const askToAskPattern = new RegExp (
23- String . raw `\b${ reSubject } \s+${ reVerb } \s+(?:${ reQuantifier } \s+)?(?:${ reQuestion } \s+)?(?:${ reConnector } \s+)?.+\?? ` ,
24+ String . raw `\b${ reSubject } \s+${ reVerb } \s+(?:${ reQuantifier } \s+)?(?:${ reQuestion } \s+)?(?:${ reConnector } \s+)?.+\?` ,
2425 'i'
2526) ;
2627
@@ -33,15 +34,34 @@ const [response] = await loadMarkdownOptions<{ name: string }>(
3334
3435const { canRun, reset } = rateLimit ( 10 * MINUTE ) ;
3536
37+ const shouldCheck = ( message : Message ) => {
38+ // check rate limit
39+ if ( ! canRun ( ) ) {
40+ return false ;
41+ }
42+ // check author
43+ if ( message . author . bot || message . author . system ) {
44+ return false ;
45+ }
46+ // check roles/permissions
47+ if (
48+ message . member !== null &&
49+ ( message . member . roles . highest . comparePositionTo ( config . roleIds . repel ) >= 0 ||
50+ message . member . permissions . has ( PermissionFlagsBits . ModerateMembers ) )
51+ ) {
52+ return false ;
53+ }
54+ return true ;
55+ } ;
56+
3657export const justAskEvent = createEvent (
3758 {
3859 name : Events . MessageCreate ,
3960 } ,
4061 async ( message ) => {
41- if ( ! canRun ( ) || message . author . bot ) {
62+ if ( ! shouldCheck ( message ) ) {
4263 return ;
4364 }
44-
4565 // Ignore long messages, likely user provided more context
4666 if ( message . content . split ( ' ' ) . length > 10 ) {
4767 return ;
0 commit comments