1- import { GroupChat } from "whatsapp-web.js" ;
2- import { Message } from "../types/message"
1+ import { GroupChat , MessageMedia } from "whatsapp-web.js" ;
2+ import { Message } from "../types/message" ;
33import log from "../components/utils/log" ;
44import sleep from "../components/utils/sleep" ;
55import { helloMessage } from "../components/utils/data" ;
@@ -29,7 +29,7 @@ export default async function (msg: Message): Promise<void> {
2929 const groupChat = chat as GroupChat ;
3030 const participants = groupChat . participants ;
3131
32- const self = ( await client ( ) ) . info . wid . _serialized
32+ const self = ( await client ( ) ) . info . wid . _serialized ;
3333 const filteredParticipants = participants . filter ( ( p ) => {
3434 if ( p . id . _serialized === self ) return false ;
3535 if ( onlyAdmins && ! p . isAdmin && ! p . isSuperAdmin ) return false ;
@@ -47,8 +47,29 @@ export default async function (msg: Message): Promise<void> {
4747
4848 const mentions = filteredParticipants . map ( ( p ) => p . id . _serialized ) ;
4949 const total = mentions . length ;
50- const baseText =
51- helloMessage [ Math . floor ( Math . random ( ) * helloMessage . length ) ] ;
50+
51+ const [ baseText , media ] = await Promise . all ( [
52+ ( async ( ) => {
53+ const defaultMessage =
54+ helloMessage [ Math . floor ( Math . random ( ) * helloMessage . length ) ] ;
55+ if ( ! msg . hasQuotedMsg ) return defaultMessage ;
56+
57+ const qoutedMessage = await msg . getQuotedMessage ( ) ;
58+ return qoutedMessage . body ? qoutedMessage . body : defaultMessage ;
59+ } ) ( ) ,
60+ ( async ( ) => {
61+ if ( msg . hasMedia ) return await msg . downloadMedia ( ) ;
62+ } ) ( ) ,
63+ ] ) ;
64+
65+ if ( media && ( [ "sticker" , "ptt" ] . includes ( msg . type ) || msg . isGif ) ) {
66+ await msg . reply ( media ) ;
67+ }
68+
69+ const mediaShouldBeSend = ! (
70+ [ "sticker" , "ptt" ] . includes ( msg . type ) && msg . isGif
71+ ) ;
72+
5273 // i made it per batch to prevent rate limiting and possibly issues
5374 const batchSize = 30 ;
5475
@@ -60,7 +81,14 @@ export default async function (msg: Message): Promise<void> {
6081
6182 const messageText = i === 0 ? `${ baseText } \n\n${ mentionText } ` : mentionText ;
6283
63- await msg . reply ( messageText , undefined , { mentions : batchMentions } ) ;
84+ await msg . reply (
85+ mediaShouldBeSend ? ( media ? media : messageText ) : messageText ,
86+ undefined ,
87+ {
88+ caption : mediaShouldBeSend ? ( media ? messageText : "" ) : "" ,
89+ mentions : batchMentions ,
90+ } ,
91+ ) ;
6492
6593 const min = 2000 ;
6694 const max = 6000 ;
0 commit comments