11import time
22import webbrowser as web
33from datetime import datetime
4+ from re import fullmatch
45from urllib .parse import quote
56
67import pyautogui as pg
@@ -24,6 +25,10 @@ def sendwhatmsg_instantly(
2425 if not core .check_number (number = phone_no ):
2526 raise exceptions .CountryCodeException ("Country Code Missing in Phone Number!" )
2627
28+ phone_no = phone_no .replace (" " , "" )
29+ if not fullmatch (r"^\+?[0-9]{2,4}\s?[0-9]{10}$" , phone_no ):
30+ raise exceptions .InvalidPhoneNumber ("Invalid Phone Number." )
31+
2732 web .open (f"https://web.whatsapp.com/send?phone={ phone_no } &text={ quote (message )} " )
2833 time .sleep (4 )
2934 pg .click (core .WIDTH / 2 , core .HEIGHT / 2 )
@@ -48,6 +53,10 @@ def sendwhatmsg(
4853 if not core .check_number (number = phone_no ):
4954 raise exceptions .CountryCodeException ("Country Code Missing in Phone Number!" )
5055
56+ phone_no = phone_no .replace (" " , "" )
57+ if not fullmatch (r"^\+?[0-9]{2,4}[0-9]{10}$" , phone_no ):
58+ raise exceptions .InvalidPhoneNumber ("Invalid Phone Number." )
59+
5160 if time_hour not in range (25 ) or time_min not in range (60 ):
5261 raise Warning ("Invalid Time Format!" )
5362
@@ -133,6 +142,8 @@ def sendwhatmsg_to_group_instantly(
133142def sendwhats_image (
134143 receiver : str ,
135144 img_path : str ,
145+ time_hour : int ,
146+ time_min : int ,
136147 caption : str = "" ,
137148 wait_time : int = 15 ,
138149 tab_close : bool = False ,
@@ -144,6 +155,23 @@ def sendwhats_image(
144155 raise exceptions .CountryCodeException ("Country Code Missing in Phone Number!" )
145156
146157 current_time = time .localtime ()
158+ left_time = datetime .strptime (
159+ f"{ time_hour } :{ time_min } :0" , "%H:%M:%S"
160+ ) - datetime .strptime (
161+ f"{ current_time .tm_hour } :{ current_time .tm_min } :{ current_time .tm_sec } " ,
162+ "%H:%M:%S" ,
163+ )
164+
165+ if left_time .seconds < wait_time :
166+ raise exceptions .CallTimeException (
167+ "Call Time must be Greater than Wait Time as WhatsApp Web takes some Time to Load!"
168+ )
169+
170+ sleep_time = left_time .seconds - wait_time
171+ print (
172+ f"In { sleep_time } Seconds WhatsApp will open and after { wait_time } Seconds Image will be Delivered!"
173+ )
174+ time .sleep (sleep_time )
147175 core .send_image (
148176 path = img_path , caption = caption , receiver = receiver , wait_time = wait_time
149177 )
0 commit comments