1- import {
2- Client ,
3- Message ,
4- MessageContent ,
5- MessageSendOptions ,
6- } from "whatsapp-web.js" ;
1+ import { Message , MessageContent , MessageSendOptions } from "whatsapp-web.js" ;
72import log from "../utils/log" ;
83import { commands } from "../utils/cmd/loader" ;
94import { penalizeUser , rateLimiter } from "../utils/rateLimiter" ;
10- import sleep from "../utils/sleep" ;
115import {
126 addBlockUser ,
137 deductUserPoints ,
@@ -21,14 +15,12 @@ import quiz from "../utils/quiz";
2115import riddle from "../utils/riddle" ;
2216import { getSetting } from "../services/settings" ;
2317import { errors , mentionResponses } from "../utils/data" ;
24- import { funD , happyEE , sadEE , loveEE } from "../../data/reaction" ;
25- import { containsAny } from "../utils/string" ;
18+ import autoReaction from "../utils/message/react" ;
2619import { InstantDownloader } from "../utils/instantdl/downloader" ;
2720import { checkInappropriate } from "../utils/contentChecker" ;
28- import prisma from "../prisma" ;
2921import redis from "../redis" ;
30- import queue from "../queue" ;
31- import regex from "../emoji " ;
22+ import downloadQueue from "../queue/download " ;
23+ import reactQueue from "../queue/react " ;
3224import ai from "../../commands/ai" ;
3325import * as Sentry from "@sentry/node" ;
3426
@@ -127,7 +119,7 @@ export default async function (msg: Message, type: string): Promise<void> {
127119 await Promise . allSettled ( [
128120 quiz ( msg ) ,
129121 riddle ( msg ) ,
130- queue . add ( ( ) => InstantDownloader ( msg ) ) ,
122+ downloadQueue . add ( ( ) => InstantDownloader ( msg ) ) ,
131123 ( async ( ) => {
132124 // override the msg!
133125 const react = { ...msg } ;
@@ -142,40 +134,7 @@ export default async function (msg: Message, type: string): Promise<void> {
142134 )
143135 return ;
144136
145- react . react = async ( reaction : string ) : Promise < void > => {
146- // add delay for more
147- // humanly like interaction
148- const min = 2000 ;
149- const max = 6000 ;
150- const randomMs = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
151-
152- await sleep ( randomMs ) ;
153- const isEmoji = / .* [ A - Z a - z 0 - 9 ] .* / . test ( reaction ) ;
154- log . info ( "AutoReact" , lid , reaction ) ;
155-
156- if ( Math . random ( ) < 0.1 && ! isEmoji )
157- if ( Math . random ( ) < 0.2 )
158- ( await client ( ) ) . sendMessage ( react . id . remote , reaction ) ;
159- else await msg . reply ( reaction ) ;
160- else await msg . react ( reaction ) ;
161- } ;
162-
163- const emojis = [
164- ...new Set ( [ ...react . body . matchAll ( regex ) ] . map ( ( m ) => m [ 0 ] ) ) ,
165- ] ;
166- if ( emojis . length > 0 ) {
167- await react . react (
168- emojis [ Math . floor ( Math . random ( ) * emojis . length ) ] ,
169- ) ;
170- } else if ( containsAny ( react . body , funD ) ) {
171- await react . react ( "🤣" ) ;
172- } else if ( containsAny ( react . body , happyEE ) ) {
173- await msg . reply ( funD [ Math . floor ( Math . random ( ) * funD . length ) ] ) ;
174- } else if ( containsAny ( react . body , sadEE ) ) {
175- await react . react ( "😭" ) ;
176- } else if ( containsAny ( react . body , loveEE ) ) {
177- await react . react ( "❤️" ) ;
178- }
137+ reactQueue . add ( ( ) => autoReaction ( msg ) ) ;
179138 } ) ( ) ,
180139 ( async ( ) => {
181140 const botId = ( await client ( ) ) . info . wid . _serialized ;
0 commit comments