@@ -17,6 +17,7 @@ import emojiRegex from "emoji-regex";
1717import { funD , happyEE , sadEE , loveEE } from "../../data/reaction" ;
1818import { containsAny } from "../utils/string" ;
1919import { checkMessage } from "../utils/phishtank" ;
20+ import { getSetting } from "../services/settings" ;
2021
2122const regex = emojiRegex ( ) ;
2223const commandPrefix = process . env . COMMAND_PREFIX || "!" ;
@@ -101,49 +102,54 @@ export default async function (msg: Message, type: string) {
101102 * Override the default function
102103 * react(reaction: string) Promise<void>
103104 */
104- const originalReact = msg . react . bind ( msg ) ;
105- msg . react = async ( reaction : string ) : Promise < void > => {
106- // add delay for more
107- // humanly like interaction
108- const min = 2000 ;
109- const max = 6000 ;
110- const randomMs = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
111-
112- await sleep ( randomMs ) ;
113- const isEmoji = / .* [ A - Z a - z 0 - 9 ] .* / . test ( reaction ) ;
114- log . info ( "AutoReact" , lid , reaction ) ;
115-
116- if ( Math . random ( ) < 0.1 && ! isEmoji )
117- if ( Math . random ( ) < 0.2 )
118- await client . sendMessage ( msg . id . remote , reaction ) ;
119- else await msg . reply ( reaction ) ;
120- else await originalReact ( reaction ) ;
121- } ;
105+ const [ isMustautoReact ] = await Promise . all ( [ getSetting ( "auto_react" ) ] ) ;
106+ if ( isMustautoReact && isMustautoReact == "on" ) {
107+ const originalReact = msg . react . bind ( msg ) ;
108+ msg . react = async ( reaction : string ) : Promise < void > => {
109+ // add delay for more
110+ // humanly like interaction
111+ const min = 2000 ;
112+ const max = 6000 ;
113+ const randomMs = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
114+
115+ await sleep ( randomMs ) ;
116+ const isEmoji = / .* [ A - Z a - z 0 - 9 ] .* / . test ( reaction ) ;
117+ log . info ( "AutoReact" , lid , reaction ) ;
118+
119+ if ( Math . random ( ) < 0.1 && ! isEmoji )
120+ if ( Math . random ( ) < 0.2 )
121+ await client . sendMessage ( msg . id . remote , reaction ) ;
122+ else await msg . reply ( reaction ) ;
123+ else await originalReact ( reaction ) ;
124+ } ;
125+ }
122126
123127 /*
124128 *
125129 * Process msg reaction
126130 */
127- Promise . resolve ( ) . then ( async ( ) => {
128- if ( ! msg . fromMe ) {
129- const emojis = [
130- ...new Set ( [ ...msg . body . matchAll ( regex ) ] . map ( ( m ) => m [ 0 ] ) ) ,
131- ] ;
132- if ( emojis . length > 0 ) {
133- const react = emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ;
134-
135- await msg . react ( react ) ;
136- } else if ( containsAny ( msg . body , funD ) ) {
137- await msg . react ( "🤣" ) ;
138- } else if ( containsAny ( msg . body , happyEE ) ) {
139- await msg . reply ( funD [ Math . floor ( Math . random ( ) * funD . length ) ] ) ;
140- } else if ( containsAny ( msg . body , sadEE ) ) {
141- await msg . react ( "😭" ) ;
142- } else if ( containsAny ( msg . body , loveEE ) ) {
143- await msg . react ( "❤️" ) ;
131+ if ( isMustautoReact && isMustautoReact == "on" ) {
132+ Promise . resolve ( ) . then ( async ( ) => {
133+ if ( ! msg . fromMe ) {
134+ const emojis = [
135+ ...new Set ( [ ...msg . body . matchAll ( regex ) ] . map ( ( m ) => m [ 0 ] ) ) ,
136+ ] ;
137+ if ( emojis . length > 0 ) {
138+ const react = emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ;
139+
140+ await msg . react ( react ) ;
141+ } else if ( containsAny ( msg . body , funD ) ) {
142+ await msg . react ( "🤣" ) ;
143+ } else if ( containsAny ( msg . body , happyEE ) ) {
144+ await msg . reply ( funD [ Math . floor ( Math . random ( ) * funD . length ) ] ) ;
145+ } else if ( containsAny ( msg . body , sadEE ) ) {
146+ await msg . react ( "😭" ) ;
147+ } else if ( containsAny ( msg . body , loveEE ) ) {
148+ await msg . react ( "❤️" ) ;
149+ }
144150 }
145- }
146- } ) ;
151+ } ) ;
152+ }
147153
148154 /*
149155 * Check if the message starts with the command prefix.
0 commit comments