-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram_val.ahk
More file actions
1206 lines (1120 loc) · 35.2 KB
/
telegram_val.ahk
File metadata and controls
1206 lines (1120 loc) · 35.2 KB
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ComObjError(0)
; #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.
TelegramBotToken =
TelegramBotChatID =
gudigudi:= ScanSubnet()
telev()
{
return 4
} ; version
Process, Priority, , L
RunAsAdmin()
MajorVersion := DllCall("GetVersion") & 0xFF ; 10
MinorVersion := DllCall("GetVersion") >> 8 & 0xFF ; 0
BuildNumber := DllCall("GetVersion") >> 16 & 0xFFFF ; 10532
Drive = G:\My Drive\file share
if !FileExist(Drive)
Drive = C:\Users\%A_Username%\Documents\share\file share
if !FileExist(Drive)
Drive = C:\Users\Administrator\Google Drive\file share
if !FileExist(Drive)
Drive = C:\Users\Admin\Google Drive\file share
OutputDebug %Drive%
global Users :=[] ,enter := "%0A", pc :=[] ,Drive,dailysummary,weeklysummary
logins :=[]
weeklysummary = 1
cmkey = cmdkey /add:%A_ComputerName% /user:%A_UserName% /pass:'
;IniWrite,%A_TickCount%,%Drive%/val/extra/progress.ini,last_active,%A_UserName%
/*
IfExist \\2700-pc\C\DLL\Users.ini
{
loop, Read,\\2700-pc\C\DLL\logins.ini
{
logins.push(A_LoopReadLine) ;
}
v := HasVal(logins,cmkey)
OutputDebug v=%v%
if (v = 0)
FileAppend,%cmkey%`n, \\2700-pc\C\DLL\logins.ini
loop % logins.Maxindex()
{
cmkey := login[A_Index]
RunWait,%cmkey% ,,hide
}
loop, Read,\\2700-pc\C\DLL\Users.ini
{
Users.push(A_LoopReadLine) ;
}
v := HasVal(Users,A_UserName)
OutputDebug v=%v%
if (v = 0)
FileAppend,%A_UserName%`n, \\2700-pc\C\DLL\Users.ini
loop, Read,\\2700-pc\C\DLL\pc.ini
{
pc.push(A_LoopReadLine) ;
}
v := HasVal(pc,A_ComputerName)
OutputDebug v=%v% ,
if (v = 0)
FileAppend,%A_ComputerName%`n, \\2700-pc\C\DLL\pc.ini
gudigudi:= ScanSubnet()
v := HasVal(gudigudi,A_ComputerName)
OutputDebug v=%v%
if (v = 3)
{
RunWait netsh winsock reset catalog,,hide
RunWait netsh int ip reset reset.log,,hide
RunWait ipconfig /flushdns,,hide
RunWait ipconfig /registerdns,,hide
RunWait route /f,,hide
;shutdown,6
}
}
else
sendmsg("remote pc not found")
*/
#include <json> ; Coco's JSON library, get it here: https://autohotkey.com/boards/viewtopic.php?t=627
global botToken,chatID
botToken := "" ; add your Telegram bot token
chatID := ; add your chat ID for testing porposes
oCustomers := {} ; Object of user ids of registered customers -> add your customers, you can send them a personal registration link
oCustomers[chatID] := "My Name" ; add your chat id (and name) to the customer object for testing purposes
offset := "" ; Telegram message offset
OutputDebug `n good to go `n
cmds := { "status" : "somefunction_status" ; bundle commands (case insensitive) and corresponding script functions to call ; ethe word te ode corespondece koi funtion name
, "Ping" : "somefunction_ping"
, "need_update" : "need_update"
, "Reboot" : "reboot"
, "force_update" : "force_update"
, "Show" : "inlinebuttons"
, "Find":"find"
,"Run":"execute"
, "ini":"Edit1"
, "Remove" : "RemoveKeyb" }
; add custom keyboard for testing
keyb= ; json formatted string
(
{"keyboard":[ ["status", "ping"],["need_update", "reboot"], ["Show inline buttons", "Remove Keyboard"] ], "resize_keyboard" : true }
)
;url := "https://api.telegram.org/bot" botToken "/sendMessage?chat_id=" chatID "&reply_markup=" keyb
url := "https://api.telegram.org/bot" botToken "/sendMessage?text="A_ComputerName " is up&chat_id=" chatID "&reply_markup=" keyb
;url := "https://api.telegram.org/bot" botToken "/sendMessage?text=Keyboard added&chat_id=" chatID "&reply_markup=" keyb
json_message := URLDownloadToVar(url)
; msgbox % json_message
; Check for new updates
SetTimer, UpdateTimer, 1000 ; every 1000 ms = 1 second
SetTimer, halfhourupdate, 1800000
;SetTimer, hourlyupdate, 7200000 ;3600000
;SetTimer, Shutdowntimer, 21600000 ;3600000
;SetTimer, hourlyupdate2, 7200000
;---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;Esc::ExitApp
; hit Escape to stop the script
!a::sendphoto()
return
!g::sendmsg("1")
return
::btw::
MsgBox, You typed btw.
return
!f::Pause
;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
halfhourupdate:
text = ""
IniRead, last_match, settings.ini,logs , last_match
if (last_match = last_match1)
{
Length := StrLen(A_UserName)
word = % SubStr(A_UserName, Length, 1)
text = %A_UserName% no match found in 30 mins
RunWait, %A_ScriptDir%\IrfanView\i_view64.exe /capture=1 /silent /convert= %A_ScriptDir%\save_me\2.png
location = %A_ScriptDir%\save_me\2.png
IniWrite,%location%,settings.ini,tele_notes,pic
Iniwrite,%text%,settings.ini,tele_notes,msg
sendphoto()
sleep 100
;Telegram_MsgBox(0,a,text)
;RunWait, Taskkill /FI USERNAME eq A_UserName /IM zack.exe /F /T ,,hide
;run c:\Users\%A_Username%\Documents\jatt\zack.ahk
kill_epic()
force_update()
ExitApp
}
last_match1 := last_match
text = ""
Return
/*
hourlyupdate:
text = ""
IniRead, last_match, settings.ini,SectionName , last_match
if (last_match = last_match1)
{
Length := StrLen(A_UserName)
word = % SubStr(A_UserName, Length, 1)
IniRead,shutdown,settings.ini,SectionName,shutdown
if(shutdown = 1)
{
if (word != 2 ) ; and A_ComputerName != 2700-pc)
{
text = %A_UserName% no match found in past hour shutdown
Telegram_MsgBox(0,a,text)
sleep 2000
Shutdown,6
}
else
{
text = %A_UserName% no match found in past hour logoff
Telegram_MsgBox(0,a,text)
sleep 2000
shutdown,0
}
}
;shutdown,0
}
last_match1 := last_match
;IfInString,A_UserName,2700_1_1
; {
; text := ping()
; Telegram_MsgBox(0,a,text)
; }
;
;IfInString,A_UserName,2700
; {
; Loop , % users.MaxIndex()
; {
; user := users[A_Index]
; IfInString,user,00
; {}
; else
; {
; ini = \\%user%-PC\Users\%user%\Documents\15-15\settings.ini
; IniRead, last_match, %ini%,SectionName , last_match
; if ( last_match == "ERROR")
; {}
; else{
; if (last_match = last_match_%User%)
; {
;
; text = %user% no match found in past hour
; Telegram_MsgBox(0,a,text)
; }
; last_match_%User% := last_match
; ggg = last_match_%User%
; zzz := last_match_%User%
; OutputDebug last_match %ggg% = %zzz% `n
; }
; }
; }
; }
text = ""
return
*/
UpdateTimer: ; checks constantly for user input in your bot
stack := {} ; message stack
updates := GetUpdates(botToken, (offset+1)) ; get (new) updates from your bot as JSON string; keep track of old messages
;msgbox % updates
oUpdates := JSON.Load(updates) ; create an AHK object from the JSON string
If oUpdates.ok ; check if json answer was "ok" : true
{
loop % oUpdates.result.MaxIndex() ; determine number of new messages (updates)
stack.Push(oUpdates.result[A_index]) ; add all updates (=messages) to stack
For key, msg in stack
{
from_id := first_name := mtext := last_name := username := ""
if (msg.callback_query.data!="") ; inline buttons have to be handled differently than normal messages and normal keyboards
{
from_id := msg.callback_query.from.id
mtext := msg.callback_query.data
}
else ; get message text or message from normal keyboard
{
from_id := msg.message.from.id ; which ID sent the message?
mtext := msg.message.text
;first_name := msg.message.from.first_name
;last_name := msg.message.from.last_name
;username ;= msg.message.from.username
}
offset := msg.update_id ; keep track of processed messages
if oCustomers.Haskey(from_id) ; check for known users... optional
{
word_array := StrSplit(mtext, A_Space, ".")
word := word_array[1]
OutputDebug mtext = %mtext% ,word = %word% `n
if cmds.Haskey(word) ; is message a known command?
{
fun := cmds[word] ;look up which function to call for a specific command
%fun%(botToken, msg, from_id, mtext) ; call function
}
else if (word == "version") or if (word == "Version")
{
tele := telev()
IniRead,version,settings.ini,config,version
Text = script=%version% tele=%telev% %A_UserName%
Telegram_MsgBox(0,a,Text)
;IfInString
;text := "Sorry... I don't know this command."
; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
;SendText(botToken, text, from_id)
}
}
else
Traytip, No, Unknown user, 3
} ; end 'for'
}
if a_hour = 00
{
if (dailysummary = 1)
{
pday := A_WDay - 1
if pday = 0
{
pday = 7
weeklysummary = 1
}
IniRead,matchesperday,settings.ini,week,%pday%
dailysummary = 0
text = %a_username%, %enter% match/day = %matchesperday%
OutputDebug %text%
Telegram_MsgBox(0,a,text)
if (A_WDay = 2 and weeklysummary = 1)
{
weeklysummary = 0
total = 0
loop,7
{
IniRead,matchesperday,settings.ini,week,%A_Index%
total := total + matchesperday
}
text = %a_username%, %enter% match/week = %total%
Telegram_MsgBox(0,a,text)
}
}
}
else if (dailysummary != 1)
dailysummary = 1
IfWinExist, Error
{
return ; function not usefull
RunWait, %A_ScriptDir%\IrfanView\i_view64.exe /capture=1 /silent /convert= %A_ScriptDir%\save_me\2.png
location = %A_ScriptDir%\save_me\2.png
IniWrite,%location%,settings.ini,tele_notes,pic
text = gc crash %A_UserName%
Iniwrite,%text%,settings.ini,tele_notes,msg
sendphoto()
run,G:\My Drive\file share\val\val_start.ahk
kill_epic()
ExitApp
}
return
/*
Shutdowntimer:
text = ""
IniRead, last_match, settings.ini,SectionName , last_match
if (last_match = last_match2)
{
text = %A_UserName% no match found in past hour
plz_sut = 1
Telegram_MsgBox(0,a,text)
;shutdown,0
}
else
plz_sut = 0
last_match2 := last_match
IfInString,A_UserName,2700_1_1
{
text := ping()
Telegram_MsgBox(0,a,text)
}
IfInString,A_UserName,2700
{
Loop , % users.MaxIndex()
{
user := users[A_Index]
IfInString,user,00
{}
else
{
ini = \\%user%-PC\Users\%user%\Documents\15-15\settings.ini
IniRead, last_match, %ini%,SectionName , last_match
if ( last_match == "ERROR")
{}
else{
if (last_match = last_match_%User%)
{
text = %user% no match found in 6 hour
Telegram_MsgBox(0,a,text)
}
last_match_%User% := last_match
ggg = last_match_%User%
zzz := last_match_%User%
OutputDebug last_match %ggg% = %zzz% `n
}
}
}
}
text = ""
if (plz_sut = 1)
{
sendmsg("no match found in 6 hrs")
Sleep 2500
Shutdown, 6
}
return
*/
;-------------------------------------------------------- functions for user commands ---------------------------------------------------------------------------------------------------------
somefunction_status(botToken, msg, from_id, mtext)
{
Random,rand,2000,3999
Sleep %rand%
if (msg.callback_query.id!="") ; After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery
{
cbQuery_id := msg.callback_query.id
; Notification and alert are optional
url := "https://api.telegram.org/bot" botToken "/answerCallbackQuery?text=Notification&callback_query_id=" cbQuery_id "&show_alert=true"
json_message := URLDownloadToVar(url)
;msgbox % json_message
}
text := status()
;SendText(botToken, text, from_id) ; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
return
}
somefunction_ping(botToken, msg, from_id, mtext)
{
Random,rand,2000,3999
Sleep %rand%
if (msg.callback_query.id!="") ; After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery
{
cbQuery_id := msg.callback_query.id
; Notification and alert are optional
url := "https://api.telegram.org/bot" botToken "/answerCallbackQuery?text=Notification&callback_query_id=" cbQuery_id "&show_alert=true"
json_message := URLDownloadToVar(url)
;msgbox % json_message
}
IfInString,A_UserName,2700_1_1
{
text := ping()
SendText(botToken, text, from_id) ; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
}
return
}
need_update(botToken, msg, from_id, mtext)
{
Random,rand,2000,3999
Sleep %rand%
if (msg.callback_query.id!="") ; After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery
{
cbQuery_id := msg.callback_query.id
; Notification and alert are optional
url := "https://api.telegram.org/bot" botToken "/answerCallbackQuery?text=Notification&callback_query_id=" cbQuery_id "&show_alert=true"
json_message := URLDownloadToVar(url)
;msgbox % json_message
}
IfInString,A_UserName,2700
{
Loop , % users.MaxIndex()
{
user := users[A_Index]
;odebug = %apid%
IfInString,user,00
{}
else
{
ini = \\%user%-PC\Users\%user%\Documents\15-15\settings.ini
Iniwrite, 1, %ini%,SectionName , restart
puser = %puser% updating %user% %enter%
}
}
}
Iniwrite, 1, settings.ini,config , restart
text = updating %A_UserName% %enter% %puser%
SendText(botToken, text, from_id) ; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
return
}
force_update(botToken = 0, msg = 0, from_id = 0, mtext = 0)
{
IniRead,force_updates,G:/My Drive/file share/val/extra/progress.ini,%A_UserName%,%A_NowUTC%
if (A_NowUTC - force_updates > 1500)
{
IniWrite,%A_NowUTC%,G:/My Drive/file share/val/extra/progress.ini,force_updates,%A_UserName%
run,G:\My Drive\file share\val\val_start.ahk
kill_epic()
ExitApp
}
}
find(botToken, msg, from_id, mtext)
{
Random,rand,2000,3999
text := A_UserName
Sleep %rand%
word_array := StrSplit(mtext, A_Space, ".")
word := word_array[2]
IfInString,word,pr1
{
loop, Read,Username.txt
{
currentUser := StrSplit(A_LoopReadLine, ",")
,currentpr := currentUser[3]
,currentrank := currentUser[2]
OutputDebug %A_LoopReadLine% `n
OutputDebug currentpr %currentpr% & currentrank %currentrank% `n
If (currentpr=="1" and currentrank=="Unranked")
{
text .= "%0A"A_LoopReadLine
}
}
}
else
{
;Usernames:=[]
loop, Read,Username.txt
{
currentUser := StrSplit(A_LoopReadLine, ",")
,currentUser := currentUser[1]
IfInString,currentUser,%word%
{
text = %A_LoopReadLine% found in
break
}
}
} ; else
text = %text% %A_UserName% %A_ComputerName%
SendText(botToken, text, from_id) ; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
}
sendphoto()
{
IniRead,strings,settings.ini,tele_notes,msg
IniRead,SelectedFile,settings.ini,tele_notes,pic
text = %A_UserName% = %strings%
SendPhoto2(botToken, chatID, Selectedfile,text) ; send the image; use msgbox for checking the json response
}
Edit1(botToken, msg, from_id, mtext)
{
mtext := StrReplace(mtext, "`r`n")
output:= StrSplit(mtext,",")
OutputDebug % output.MaxIndex()
If InStr(mtext,A_UserName) or output.MaxIndex() = 5
{
output:= StrSplit(mtext,",")
readwrite := output[1]
outputv := output[2]
file := output[3]
scename := output[4]
readvariable := output[5]
If InStr(readwrite,"read")
{
iniread,outputv,%file%,%scename%,%readvariable%
Value := outputv
}
else
{
Iniwrite,%outputv%,%file%,%scename%,%readvariable%
Value = written
}
text = %Value% %A_UserName%
SendText(botToken, text, from_id)
}
}
execute(botToken, msg, from_id, mtext)
{
output:= StrSplit(mtext,"Run")
function:= output[2]
function1 := output[1]
OutputDebug `n %function1% `n %function%
FileDelete,temp.ahk
this = strings = string Value empty
FileAppend,%this% `n , temp.ahk
FileAppend, %function% `n , temp.ahk
;................................send_telegram().............................
this = send_telegram(strings,pic := "0")
;~ FileAppend,`n %this% `n { `n , temp.ahk
this := "IniWrite,%strings%,settings.ini,tele_notes,msg"
FileAppend,%this% `n , temp.ahk
this = if pic = 0
FileAppend,%this% `n , temp.ahk
this = {
FileAppend,%this% `n , temp.ahk
this = send {alt down}
FileAppend,%this% `n , temp.ahk
this = Sleep 50
FileAppend,%this% `n , temp.ahk
this = send {g}
FileAppend,%this% `n , temp.ahk
this = Sleep 50
FileAppend,%this% `n , temp.ahk
this = send {alt up}
FileAppend,%this% `n , temp.ahk
this = }
FileAppend,%this% `n , temp.ahk
this = else
FileAppend,%this% `n , temp.ahk
this = {
FileAppend,%this% `n , temp.ahk
this = RunWait, %A_ScriptDir%\IrfanView\i_view64.exe /capture=1 /silent /convert= %A_ScriptDir%\telegram\1.png
FileAppend,%this% `n , temp.ahk
location = %A_ScriptDir%\telegram\1.png
;~ IniWrite,%location%,settings.ini,tele_notes,pic
this = send {alt down}
FileAppend,%this% `n , temp.ahk
this = Sleep 50
FileAppend,%this% `n , temp.ahk
this = send {a}
FileAppend,%this% `n , temp.ahk
this =Sleep 50
FileAppend,%this% `n , temp.ahk
this =send {alt up}
FileAppend,%this% `n , temp.ahk
this = }
FileAppend,%this% `n , temp.ahk
;................................send_telegram().............................
Run,temp.ahk
}
kill_epic()
{
RunWait Taskkill /IM VALORANT-Win64-Shipping.exe /F
RunWait Taskkill /IM VALORANT.exe /F
RunWait Taskkill /IM UnrealCEFSubProcess.exe /F
RunWait Taskkill /IM RiotClientUx.exe /F
RunWait Taskkill /IM RiotClientServices /F
}
;--------------------------------------------------------------------
; add inline buttons
inlinebuttons(botToken, msg, from_id, mtext="")
{
keyb= ; json string:
(
{"inline_keyboard":[ [{"text": "Command One" , "callback_data" : "status"}, {"text" : "Some button (Cmd3)", "callback_data" : "Command3"} ] ], "resize_keyboard" : true }
)
url := "https://api.telegram.org/bot" botToken "/sendMessage?text=Keyboard added&chat_id=" from_id "&reply_markup=" keyb
json_message := URLDownloadToVar(url) ; find this function at the next code box below
return json_message
}
;---------------------------------------------------------------------
; Remove custom keyboard
RemoveKeyb(botToken, msg, from_id, mtext="")
{
keyb=
(
{"remove_keyboard" : true }
)
url := "https://api.telegram.org/bot" botToken "/sendMessage?text=Keyboard removed&chat_id=" from_id "&reply_markup=" keyb
json_message := URLDownloadToVar(url)
;msgbox % json_message
return
}
;------------------------------------------ Telegram functions --------------------------------------------------------------------------------------------------------
GetUpdates(token, offset="", updlimit=100, timeout=0)
{
If (updlimit>100)
updlimit := 100
; Offset = Identifier of the first update to be returned.
url := "https://api.telegram.org/bot" token "/getupdates?offset=" offset "&limit=" updlimit "&timeout=" timeout
updjson := URLDownloadToVar(url)
return updjson
}
;------------------------------------------------
SendText(token, text, from_id, replyMarkup="", parseMode="" )
{
OutputDebug `n %text%
url := "https://api.telegram.org/bot" token "/sendmessage?chat_id=" from_ID "&text=" text "&reply_markup=" replyMarkup "&parse_mode=" parseMode
json_message := URLDownloadToVar(url)
return json_message
}
;----------------------------------- additional functions ------------------------------------------------------------------------------------------------------------------
URLDownloadToVar(url,ByRef variable=""){ ; function originally by Maestrith, I think
try ; keep script from breaking if API is down or not reacting
{
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
;hObject:=ComObjCreate("MSXML2.XMLHTTP.6.0")
hObject.Open("GET",url)
hObject.Send()
variable:=hObject.ResponseText
;variable= {"ok":true,"result":{"message_id":62,"from":{"id":1331062094,"is_bot":true,"first_name":"Fearbot","username":"Rastinderbot"},"chat":{"id":706316494,"first_name":"American","last_name":"Sniper","type":"private"},"date":1597871292,"text":"Keyboard added"}}
;OutputDebug %variable%
return variable
}
}
status()
{
IfInString,A_UserName,2700_1_1
{
;loop, Read,\\2700-pc\C\DLL\Users.ini
; {
; Users.push(A_LoopReadLine) ;
; }
Loop , % users.MaxIndex()
{
user := users[A_Index]
;odebug = %apid%
IfInString,user,00
{}
else
{
RunWait cmdkey /add:%user%-pc /user:%user% /pass:' ,,hide
ini = \\%user%-PC\Users\%user%\Documents\15-15\settings.ini
IniRead, set, %ini%,SectionName , set
IniRead, last_match, %ini%,SectionName , last_match
IniRead, matchcount, %ini%,SectionName , matchcount
if ( last_match == "ERROR")
continue
else
this = %this% %user%>set=%set%,matches=%matchcount%,lastest=%last_match% %enter%
}
}
}
IniRead, user, settings.ini,user , user
IniRead, lvl, settings.ini,user , lvl
IniRead, last_match, settings.ini,logs , last_match
;IniRead, count, settings.ini,logs , count
RunWait, %A_ScriptDir%\IrfanView\i_view64.exe /capture=1 /silent /convert= %A_ScriptDir%\save_me\2.png
location = %A_ScriptDir%\save_me\2.png
IniWrite,%location%,settings.ini,tele_notes,pic
text = lvl-%lvl% count-%count% , last_match-%last_match%, user-%user%
Iniwrite,%text%,settings.ini,tele_notes,msg
sendphoto()
return this
}
sendmsg(m)
{
Telegram_MsgBox(0,a,text)
if m = 1
{
;IniRead,strings,settings.ini,tele_notes,msg
IniRead,strings,C:\Users\%A_UserName%\Documents\jatt\settings.ini,tele_notes,msg
text = %A_UserName% = %strings%
Telegram_MsgBox(0,a,text)
}
else
{
send {NumpadSub down}
Sleep 50
send {NumpadSub up}
text = %A_UserName% = %m%
Telegram_MsgBox(0,a,text)
}
}
sendmsg_val()
{
text = height %A_ScreenHeight%,
}
ping()
{
bcarray :=[]
IfInString,A_UserName,2700_1_1
{
gudigudi:= ScanSubnet()
Loop % gudigudi.MaxIndex()
bcarray.Push(gudigudi[A_Index])
}
;scan all active network adapters for active IP's... if no ip's were specified...
;Msgbox % ScanSubnet("192.168.2.1 192.168.43.1 192.168.56.1") ;find all ip's in the specified address subnets...ex. 192.168.2.(1-255)
IfInString,A_UserName,2700_1_1
{
;loop, Read,\\2700-pc\C\DLL\Users.ini
; {
; Users.push(A_LoopReadLine) ;
; }
loop , % pc.MaxIndex()
{
pc_name := pc[a_Index]
pc_add = \\%pc_name%\Users
;RunWait cmdkey /add:%pc_name% /user:%user% /pass:' ,,hide
if (FileExist(pc_add))
bcarray.Push(pc_name[A_Index])
;else
;this = %this% %pc_name% is dowm %enter%
}
}
;****************** discarded ***********************************************
IfInString,A_UserName,2700_1_1
{
;loop, Read,\\2700-pc\C\DLL\Users.ini
; {
; Users.push(A_LoopReadLine) ;
; }
loop , % pc.MaxIndex()
{
Value := pc[a_Index]
;IfInString,Value,1
;{}
; else{
; Value = %Value%-PC
OutputDebug %Value% `n
html := ping_check(Value)
If html
bcarray.Push(Value)
;puser = %puser% %Value% is down %enter%
;}
}
;puser = %puser% %A_UserName% hi ras
;return puser
loop % pc.MaxIndex()
{
rr := pc[a_index]
OutputDebug %rr%
v := HasVal(bcarray,rr)
OutputDebug v=%v%
if (v = 0)
this = %this% %rr% is dowm %enter%
}
return this
}
}
reboot(botToken, msg, from_id, mtext)
{
Random,rand,2000,3999
Sleep %rand%
if (msg.callback_query.id!="") ; After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery
{
cbQuery_id := msg.callback_query.id
; Notification and alert are optional
url := "https://api.telegram.org/bot" botToken "/answerCallbackQuery?text=Notification&callback_query_id=" cbQuery_id "&show_alert=true"
json_message := URLDownloadToVar(url)
;msgbox % json_message
}
text := reboot1(mtext)
if text
SendText(botToken, text, from_id) ; url encoding for messages : %0A = newline (\n) %2b = plus sign (+) %0D for carriage return \r single Quote ' : %27 %20 = space
}
reboot1(mtext)
{
IniRead,force_updates,G:/My Drive/file share/val/extra/progress.ini,%A_UserName%,%A_NowUTC%
if (A_NowUTC - force_updates > 1500)
{
IfInString,mtext,all or IfInString,mtext,A_UserName
{
IniWrite,%A_NowUTC%,G:/My Drive/file share/val/extra/progress.ini,force_reboot,%A_UserName%
shutdown,6
text = %A_UserName% is going down
}}
return text
IfInString,mtext,all
{
IfInString,A_UserName,00
{
IfInString,mtext,all
;shutdown,0
text = %A_UserName% is going down
}
else
{
;shutdown,6
text = %A_UserName% is going down
}
}
IfInString,mtext,%A_ComputerName%
{
;shutdown,6
text = %A_UserName% is going down
}
IfInString,mtext,%A_UserName%
{
;shutdown,0
text = %A_UserName% is going down
}
return text
}
ping_check(Server)
{
FileDelete, Ping.log
k =
ServerDown = ; clearing out variable
;Settimer, ServerCheck, 5000 ; currently set to 5 secs for testing
;ServerCheck:
Target = %Server% -n 1 -w 250
Run, %comspec% /c ping %Target% > Ping.log, , Hide
Sleep, 350
FileRead, FileContent, Ping.log
If FileContent not contains Reply from ; or another error
{
;MsgBox, %Server% not responding ; for testing
;ServerDown++ ; increments up the timeout count
}
Else
{
k = 1
;MsgBox, %Server% is up ; for testing
;ServerDown = ; clears the timeout count in case there was any on it
}
FileDelete, Ping.log
Return k
}
RunAsAdmin() {
Global 0
IfEqual, A_IsAdmin, 1, Return 0
Loop, %0%
params .= A_Space . %A_Index%
DllCall("shell32\ShellExecute" (A_IsUnicode ? "":"A"),uint,0,str,"RunAs",str,(A_IsCompiled ? A_ScriptFullPath
: A_AhkPath),str,(A_IsCompiled ? "": """" . A_ScriptFullPath . """" . A_Space) params,str,A_WorkingDir,int,1)
ExitApp
}
hasVal(haystack, needle) {
if(!isObject(haystack))
return false
if(haystack.Length()==0)
return false
for k,v in haystack
if(v==needle)
return true
return false
}
hasstringVal(haystack, needle) {
if(!isObject(haystack))
return false
if(haystack.Length()==0)
return false
for k,v in haystack
If InStr(v,needle)
return true
return false
}
ScanSubnet(addresses:="") { ;pings IP ranges & returns active IP's
BL := A_BatchLines
SetBatchLines, -1
If !addresses{ ;scan all active network adapters/connections for active IP's... if no ip's were specified...
colItems := ComObjGet( "winmgmts:" ).ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
while colItems[objItem]
addresses .= addresses ? " " objItem.IPAddress[0] : objItem.IPAddress[0]
}
return addresses ; since 2700x is no loger admin we put return
rVa :=[]
pcnames :=[]
Loop, Parse, addresses, % A_Space
{
OutputDebug %addresses% `n
If ( A_LoopField && addrArr := StrSplit(A_LoopField,".") )
Loop 256
addr .= addr ? A_Space "or Address = '" addrArr.1 "." addrArr.2 "." addrArr.3 "." A_Index-1 "'" : "Address = '" addrArr.1 "." addrArr.2 "." addrArr.3 "." A_Index-1 "'"
colPings := ComObjGet( "winmgmts:" ).ExecQuery("Select * From Win32_PingStatus where " addr "")._NewEnum
While colPings[objStatus]
{
rVal:=(oS:=(objStatus.StatusCode="" or objStatus.StatusCode<>0)) ? "" : (rVal ? objStatus.Address : objStatus.Address)
if rVal
rVa.Push(rVal)
else
break
}
addr := "" ;the quota on Win32_PingStatus prevents more than roughtly two ip ranges being scanned simultaneously...so each range is scanned individually.
}
SetBatchLines, % BL
OutputDebug `n
Loop , % rVa.MaxIndex()
{
aa := rVa[A_Index]
;OutputDebug %aa% `n
pcnames.push(ReverseLookup(aa))
}
Return pcnames
}
ReverseLookup(ipaddr)
{
;OutputDebug %ipaddr% `n
VarSetCapacity(WSADATA, 394 + (A_PtrSize - 2) + A_PtrSize, 0)
if (DllCall("ws2_32\WSAStartup", "ushort", 0x0202, "ptr", &WSADATA) != 0)
return "WSAStartup failed", DllCall("ws2_32\WSACleanup")
inaddr := DllCall("ws2_32\inet_addr", "astr", ipaddr, "uint")
if !(inaddr) || (inaddr = 0xFFFFFFFF)
return "inet_addr failed", DllCall("ws2_32\WSACleanup")
size := VarSetCapacity(sockaddr, 16, 0), NumPut(2, sockaddr, 0, "short") && NumPut(inaddr, sockaddr, 4, "uint")
VarSetCapacity(hostname, 1025 * (A_IsUnicode ? 2 : 1))
if (DllCall("ws2_32\getnameinfo", "ptr", &sockaddr, "int", size, "ptr", &hostname, "uint", 1025, "ptr", 0, "uint", 32, "int", 0))
return "getnameinfo failed with error: " DllCall("ws2_32\WSAGetLastError"), DllCall("ws2_32\WSACleanup")
return StrGet(&hostname+0, 1025, "cp0"), DllCall("ws2_32\WSACleanup")
}
; end of auto-execute section; the rest of the script are re-usable library functions
;----------------------------------------------------------------------------------------------------------------------------------
SendPhoto2(token, chatID, file, caption := "" ) ; you could add more options; compare the Telegram API docs
{
url_str := "https://api.telegram.org/bot" token "/sendPhoto?caption=" caption
objParam := { "chat_id" : chatID
, "photo" : [file] }
return UploadFormData(url_str, objParam)
}
;---------------------------------------------
UploadFormData(url_str, objParam) ; Upload multipart/form-data
{
CreateFormData(postData, hdr_ContentType, objParam)
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("POST", url_str, true)
whr.SetRequestHeader("Content-Type", hdr_ContentType)
; whr.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko") ; ???????
whr.Option(6) := False ; No auto redirect
whr.Send(postData)
try
whr.WaitForResponse()
json_resp := whr.ResponseText
whr := ; free COM object
return json_resp ; will return a JSON string that contains, among many other things, the file_id of the uploaded file
}
;###################################################################################################################