77 Reaction ,
88} from "whatsapp-web.js" ;
99import qrcode from "qrcode-terminal" ;
10- import cliProgress from "cli-progress " ;
10+ import LoadingBar from "./utils/loadingBar " ;
1111import messageEvent from "./events/message" ;
1212import messageEdit from "./events/edit" ;
1313import groupLeave from "./events/groups/leave" ;
@@ -16,15 +16,7 @@ import reaction from "./events/reaction";
1616import ready from "./events/ready" ;
1717import revoke from "./events/revoke" ;
1818
19- const loadingBar = new cliProgress . SingleBar (
20- {
21- format : "Loading | {bar} | {value}%" ,
22- barCompleteChar : "█" ,
23- barIncompleteChar : "-" ,
24- hideCursor : true ,
25- } ,
26- cliProgress . Presets . shades_classic
27- ) ;
19+ const loadingBar = LoadingBar ( "Loading Client | {bar} | {value}%" ) ;
2820const client = new Client ( {
2921 puppeteer : {
3022 executablePath :
@@ -40,11 +32,13 @@ client.on("loading_screen", (percent: number, message: string) => {
4032 isLoadingBarStarted = true ;
4133 }
4234
35+ if ( percent >= 99 ) loadingBar . stop ( ) ;
36+
4337 loadingBar . update ( percent , { message } ) ;
4438} ) ;
4539
4640client . on ( "authenticated" , ( ) =>
47- log . info ( "Auth" , "Client authenticated successfully." )
41+ log . info ( "Auth" , "Client authenticated successfully." ) ,
4842) ;
4943
5044client . on ( "qr" , ( qr : string ) => {
@@ -53,34 +47,34 @@ client.on("qr", (qr: string) => {
5347 qrcode . generate ( qr , { small : true } ) ;
5448} ) ;
5549
56- client . on ( "ready" , async ( ) => {
57- loadingBar . stop ( ) ;
58- ready ( ) ;
59- } ) ;
50+ client . on ( "ready" , async ( ) => ready ( ) ) ;
6051
6152client . on ( "message_reaction" , async ( react : Reaction ) =>
62- reaction ( client , react )
53+ reaction ( client , react ) ,
6354) ;
6455
6556// client.on("message", (msg) => messageEvent(msg));
6657client . on ( "message_create" , async ( msg : Message ) => messageEvent ( msg ) ) ;
6758
6859client . on (
6960 "message_edit" ,
70- async ( msg : Message , newBody : string , prevBody : string ) =>
71- messageEdit ( msg , newBody , prevBody )
61+ async ( msg : Message , newBody : string , prevBody : string ) => {
62+ msg . body = newBody ;
63+ await Promise . all ( [ messageEdit ( msg , newBody , prevBody ) , messageEvent ( msg ) ] ) ;
64+ } ,
7265) ;
7366
7467client . on (
7568 "message_revoke_everyone" ,
76- async ( msg : Message , revoked_msg ?: Message ) => revoke ( msg , revoked_msg )
69+ async ( msg : Message , revoked_msg ?: Message ) => revoke ( msg , revoked_msg ) ,
7770) ;
7871
7972client . on ( "group_join" , async ( notif : GroupNotification ) => groupJoin ( notif ) ) ;
8073client . on ( "group_leave" , async ( notif : GroupNotification ) => groupLeave ( notif ) ) ;
81- client . on ( "auth_failure" , ( msg : string ) =>
82- log . error ( "Auth" , "Authentication failed. Please try again." )
83- ) ;
74+ client . on ( "auth_failure" , ( msg : string ) => {
75+ loadingBar . stop ( ) ;
76+ log . error ( "Auth" , "Authentication failed. Please try again." ) ;
77+ } ) ;
8478
8579client . initialize ( ) ;
8680
0 commit comments