-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainScript0_96.ahk
506 lines (324 loc) · 12.7 KB
/
mainScript0_96.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
;**************************************************************************************************************************
;**************************************************************************************************************************
;**************************************************************************************************************************
; WhatsappBot
; Version 0.96 ---- 5.3.2018 - EDITING
; Programmer: Paulo B.
; Email: [email protected]
;
;
;
;**************************************************************************************************************************
;**************************************************************************************************************************
;**************************************************************************************************************************
;**************************************************************************************************************************
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
WinWaitActive, WhatsApp ahk_exe WhatsApp.exe
#Include Gdip.ahk ; a script to insert an image into the Clipboard to paste it later
EraseTries = 0
mailSent = 0
messageFileExists := FileExist(".\data\message.txt")
FindThreeDotsTries=0
Loop ;main program loop
{
Loop ;loop unti you find that there are three dots in the upper right corner
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1139, 8, 1373, 135, .\pictures\threeDots.png
CenterImgSrchCoords(".\pictures\threeDots.jpg", FoundX, FoundY)
FindThreeDotsTries++
} Until ErrorLevel = 0 or FindThreeDotsTries > 5 ;TODO: check this part of the code
FindThreeDotsTries=0
Loop ;Put the mouse over a tooltip and get the number from the (tooltip) contact name and do this until you get the number
{
WinWaitActive, WhatsApp ahk_exe WhatsApp.exe
Click, 495, 56, 0
Sleep, 1000
ControlGetText, currentTelNumber,,ahk_class tooltips_class32
Click, 563, -539, 0
} Until currentTelNumber!=""
if(previousTelNumber!=currentTelNumber) ;if the number has changed reset the erase tries
EraseTries=0
;**********************************************NUMBER IS ALREADY in CONTACTS = it doesnt have a + sign********************************************
if(InStr(currentTelNumber, "+")==0 and EraseTries==0) ;if there is no + or a new number then enter
{
if(messageFileExists != "")
{
;SendMessageFromFile(".\data\message.txt")
}
else if(messageFileExists =="")
{
; SendMessage()
}
SendImage()
DeleteContact()
previousTelNumber = currentTelNumber;
EraseTries++
}
;**********************************************NOVI BROJ********************************************
else if (previousTelNumber!=currentTelNumber and InStr(currentTelNumber, "+")!=0) ;here we have a new number and we want to save it to a file
{
previousTelNumber = %currentTelNumber% ;later for checking do we really have a new number
FileRead, newContactOrderNumber, .\data\newContactOrderNumber.txt ;take the number and use it as a new contacts name
StringReplace, currentTelNumber, currentTelNumber, %A_SPACE%, , All ;clean the number of all spaces
SaveContactInCSV(currentTelNumber,newContactOrderNumber) ;save the new contacts into google csv file
SaveContactInVCF(currentTelNumber,newContactOrderNumber) ;save the new contact number into a vcf file
;*********Save the new number*******************
newContactOrderNumber += 1
FileDelete, .\data\newContactOrderNumber.txt
FileAppend, %newContactOrderNumber%, .\data\newContactOrderNumber.txt
currentTelNumber:=0 ;erase the current number
;SendMessage() ; -- put this if you want to send a message
;SendMessageFromFile(".\data\message.txt")
SendImage()
DeleteContact()
EraseTries++
Sleep 1000
}
else if(EraseTries>10)
{
if(mailSent!=1) ; if the mail was sent wait before the script is reset before sending the mail another time
SendMailIfError()
mailSent = 1
}
else
{
if(EraseTries==0)
previousTelNumber = %currentTelNumber%
Sleep 3000
DeleteContact() ;try to deleate
Click, 791, 239 Left, 1 ;WARNING - what if a user sends a picture then clicking in the middle of the screen is a problem
Sleep, 400
EraseTries++
if(EraseTries >= 3) ; if the program tries to erase a kontakt message and it fails after 3 tries make sure we are not in a group
{
ExitFromWhatsappGroup()
}
}
;*********************************************************************************************************
} until mailSent==1
ChechStringForLetters(tekst)
{
if tekst contains Q,W,E,R,T,Z,U,I,O,P,Š,Đ,A,S,D,F,G,H,J,K,L,Č,Ć,Ž,Y,X,C,V,B,N,M,q,w,e,r,t,z,u,i,o,p,š,đ,a,s,d,f,g,h,j,k,l,č,ć,ž,y,x,c,v,b,n,m
return true
else
return false
}
;********************************************************************BRISANJE KONTAKTA**********************************************************************
DeleteContact()
{
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1139, 8, 1373, 135, .\pictures\threeDots.png
CenterImgSrchCoords(".\pictures\threeDots.png", FoundX, FoundY)
If ErrorLevel = 0
Click, %FoundX%, %FoundY% Left, 1
Sleep, 10
}
Until ErrorLevel = 0
tries = 0
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 988, 8, 1373, 374, .\pictures\deleteContactTest.png
CenterImgSrchCoords(".\pictures\deleteContactTest.png", FoundX, FoundY)
If ErrorLevel = 0
Click, %FoundX%, %FoundY%, 1
Sleep, 10
tries++
}
Until ErrorLevel = 0 or tries >= 20
if(tries<20) ;ako je nasao tipka
{
Sleep 3000
Click, 789, 419 Left, 1
}
}
ExitFromWhatsappGroup()
{
Click, 1226, 276 Left, 1
Sleep, 1000
Click, 794, 419 Left, 1
Sleep, 3000
Click, 1336, 65 Left, 1
Sleep, 3000
Click, 1225, 279 Left, 1
Sleep, 3000
Click, 792, 417 Left, 1
Sleep, 5000
}
;********************************************************************POŠALJI PORUKU********************************************************************
SendMessageFromFile(path)
{
FileRead, Clipboard, %path%
Click, 538, 702 Left, 1
Sleep, 10
Sleep, 300
Send, {Control Down}
Sleep, 10
Send, {v Down}
Sleep, 50
Send, {v Up}
Sleep, 50
Send, {Control Up}
Sleep, 50
Sleep, 400
Send, {Enter}
}
SendMessage(message)
{
Click, 538, 702 Left, 1
Sleep, 10
Clipboard = %message%
Sleep, 300
Send, {Control Down}
Sleep, 10
Send, {v Down}
Sleep, 50
Send, {v Up}
Sleep, 50
Send, {Control Up}
Sleep, 50
Sleep, 400
Send, {Enter}
}
SendImage()
{
pToken := Gdip_Startup() ;put the image into the Clipboard
Gdip_SetBitmapToClipboard(pBitmap := Gdip_CreateBitmapFromFile(".\pictures\welcome.png"))
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Click, 538, 702 Left, 1
Sleep, 300
Send, {Control Down}
Sleep, 10
Send, {v Down}
Sleep, 50
Send, {v Up}
Sleep, 50
Send, {Control Up}
Sleep, 50
Sleep, 3000
Send, {Enter}
}
CenterImgSrchCoords(imagePath,ByRef FoundX,ByRef FoundY)
{
FoundX += 20
FoundY += 20
}
;********************************************************************SAVE VCF********************************************************************
;BEGIN:VCARD
;VERSION:3.0
;FN:15123
;TEL;TYPE=VOICE,CELL;VALUE=text:+2313213131
;END:VCARD
SaveContactInVCF(ByRef currentTelNumber, newContactOrderNumber)
{
StringReplace, currentTelNumber, currentTelNumber, %A_SPACE%, , All
FormatTime, CurrentDateTime,, MM_d ;formate the date
saveLocation = .\data\%CurrentDateTime%.vcf ;where the file will be saved
buffer =
(
BEGIN:VCARD
VERSION:3.0
FN:%newContactOrderNumber%
TEL;TYPE=VOICE,CELL;VALUE=text:%currentTelNumber%
END:VCARD`n
)
FileAppend, %buffer%, %saveLocation%
}
;___________________________________________________________SAVE CSV__________________________________________________________________
SaveContactInCSV(ByRef currentTelNumber, newContactOrderNumber)
{
buffer := ",,,,,,,,,,,,,,,,,,,,,,,,,,* My Contacts,,,Mobile," currentTelNumber ",,`n"
FormatTime, CurrentDateTime,, MM_d ;format the date
saveLocation = .\data\%CurrentDateTime%.csv ;file save location
AttributeString := FileExist(saveLocation) ;TODO: check here for speed los
;If the file doesnt exist add a GOOGLE HEADER
if(AttributeString =="")
{
FileAppend,
(
Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value,E-mail 2 - Type,E-mail 2 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value,Phone 3 - Type,Phone 3 - Value,Phone 4 - Type,Phone 4 - Value,Phone 5 - Type,Phone 5 - Value,Address 1 - Type,Address 1 - Formatted,Address 1 - Street,Address 1 - City,Address 1 - PO Box,Address 1 - Region,Address 1 - Postal Code,Address 1 - Country,Address 1 - Extended Address,Organization 1 - Type,Organization 1 - Name,Organization 1 - Yomi Name,Organization 1 - Title,Organization 1 - Department,Organization 1 - Symbol,Organization 1 - Location,Organization 1 - Job Description,Website 1 - Type,Website 1 - Value `n
),%saveLocation%
}
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!FORMAT THE NUMBER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If newContactOrderNumber <= 9
{
FileAppend, 0000%newContactOrderNumber%0000%buffer%, %saveLocation%
Goto, escape
}
If newContactOrderNumber <= 99
{
FileAppend, 000%newContactOrderNumber%%buffer%, %saveLocation%
Goto, escape
}
If newContactOrderNumber <= 999
{
FileAppend, 00%newContactOrderNumber%%buffer%, %saveLocation%
Goto, escape
}
If newContactOrderNumber <= 9999
{
FileAppend, 0%newContactOrderNumber%%buffer%, %saveLocation%
Goto, escape
}
If newContactOrderNumber <= 99999
{
FileAppend, %newContactOrderNumber%%buffer%, %saveLocation%
Goto, escape
}
escape:
}
;***************************************************** WARNING: if using google you will need to TURN ON less secure aps ************************************
SendMailIfError()
{
AttributeString := FileExist(".\data\mailPassword.dat") ;does the file exist??
;if the file exists do the things down
if(AttributeString !="")
{
pmsg := ComObjCreate("CDO.Message")
pmsg.From := "[email protected]" ; """AHKUser"" <[email protected]>"
pmsg.To := "[email protected]"
pmsg.BCC := "" ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC := "" ;"[email protected], [email protected]"
pmsg.Subject := "Error in program!!!"
;You can use either Text or HTML body like
pmsg.TextBody := "Whatsapp Bot has encountred an error please check the script"
;OR
;pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><h2>Hello</h2><p>Testing!</p></body></html>"
;sAttach := "Path_Of_Attachment" ; can add multiple attachments, the delimiter is |
FileRead, mailPassword, .\data\mailPassword.dat ;take the password from the file
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "sample@[email protected]"
fields.sendpassword := mailPassword
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()
}
}
FindAStar()
{
Loop ;Check if a new message has a star in it
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 1139, 8, 1373, 135, .\pictures\star.png
CenterImgSrchCoords(".\pictures\star.jpg", FoundX, FoundY)
} Until ErrorLevel = 0
Click, FoundX, FoundY Left, 1
}