66 LocalAuth ,
77 Message ,
88 Reaction ,
9+ WAState ,
910} from "whatsapp-web.js" ;
1011import qrcode from "qrcode-terminal" ;
1112import LoadingBar from "./utils/loadingBar" ;
@@ -20,6 +21,7 @@ import callEvent from "./events/call";
2021import DownloadMedia from "./utils/message/download" ;
2122import CheckSpamLink from "./utils/phishtank/checkSpam" ;
2223import queue from "./queue" ;
24+ import groupAdminChanged from "./events/groups/groupAdminChanged" ;
2325
2426let instance : Client | null = null ;
2527let isLoadingBarStarted = false ;
@@ -50,6 +52,7 @@ async function client(): Promise<Client> {
5052 "--metrics-recording-only" ,
5153 "--disable-hang-monitor" ,
5254 ] ,
55+ defaultViewport : { width : 1366 , height : 768 } ,
5356 executablePath :
5457 process . env . PUPPETEER_EXEC_PATH || "/opt/google/chrome/google-chrome" ,
5558 } ,
@@ -86,22 +89,21 @@ function registerEvents(client: Client): void {
8689
8790 client . on ( "message_reaction" , ( react : Reaction ) => reaction ( client , react ) ) ;
8891
89- client . on ( "message_create" , async ( msg : Message ) => {
90- await Promise . allSettled ( [
91- CheckSpamLink ( msg ) ,
92- queue . add ( ( ) => DownloadMedia ( msg ) ) ,
93- messageEvent ( msg , "create" ) ,
94- ] ) ;
92+ client . on ( "message_create" , ( msg : Message ) => {
93+ CheckSpamLink ( msg ) ;
94+ queue . add ( ( ) => DownloadMedia ( msg ) ) ;
95+ messageEvent ( msg , "create" ) ;
9596 } ) ;
97+ client . on ( "media_uploaded" , ( msg : Message ) =>
98+ queue . add ( ( ) => DownloadMedia ( msg ) ) ,
99+ ) ;
96100
97101 client . on (
98102 "message_edit" ,
99- async ( msg : Message , newBody : string , prevBody : string ) => {
103+ ( msg : Message , newBody : string , prevBody : string ) => {
100104 msg . body = newBody ;
101- await Promise . allSettled ( [
102- messageEdit ( msg , newBody , prevBody ) ,
103- messageEvent ( msg , "edit" ) ,
104- ] ) ;
105+ messageEdit ( msg , newBody , prevBody ) ;
106+ messageEvent ( msg , "edit" ) ;
105107 } ,
106108 ) ;
107109
@@ -113,11 +115,18 @@ function registerEvents(client: Client): void {
113115
114116 client . on ( "group_join" , ( notif : GroupNotification ) => groupJoin ( notif ) ) ;
115117 client . on ( "group_leave" , ( notif : GroupNotification ) => groupLeave ( notif ) ) ;
118+ client . on ( "group_admin_changed" , ( notif : GroupNotification ) =>
119+ groupAdminChanged ( notif ) ,
120+ ) ;
116121
117122 client . on ( "auth_failure" , ( ) => {
118123 loadingBar . stop ( ) ;
119124 log . error ( "Auth" , "Authentication failed. Please try again." ) ;
120125 } ) ;
126+
127+ client . on ( "disconnected" , ( reason : WAState | "LOGOUT" ) => {
128+ throw Error ( `Client has been disconnected reason: ${ reason } ` ) ;
129+ } ) ;
121130}
122131
123132export { client } ;
0 commit comments