-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegram-sender.ahk
152 lines (129 loc) · 3.87 KB
/
telegram-sender.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
#Requires AutoHotkey v2.0
#SingleInstance Force
Persistent
SetWorkingDir(A_ScriptDir)
; Define messages and corresponding files
messages := Map(
"NewYear", "Happy New Year! 🎉",
"CNY", "Happy Lunar New Year! 🧧",
"Xmas", "Merry Christmas! 🎄",
"Morning", "Good Morning! ☀️",
"Test", "Test Message 🧪",
"Custom", "" ; Empty value for custom message
)
; Create instructions.txt
if !FileExist("instructions.txt") {
FileAppend("F7 key to force stop the script`nF8 key to force close the AHK", "instructions.txt")
}
; Check if people.txt exists
if !FileExist("people.txt") {
FileAppend("", "people.txt")
MsgBox("people.txt created. Please add contacts and rerun.", "Info", "Iconi")
ExitApp
}
; Create option-specific people files
for key in messages {
filename := key "-people.txt"
if !FileExist(filename) {
FileAppend("", filename)
}
}
; Create GUI with dynamic options
myGui := Gui()
myGui.Title := "Message Selector"
myGui.Add("Text",, "Select message to send:")
; Collect keys from the Map
keys := []
for key in messages
keys.Push(key)
ddl := myGui.Add("DropDownList", "vMsgChoice w150", keys)
myGui.Add("Button", "Default w80", "OK").OnEvent("Click", ProcessInput)
myGui.Show()
ProcessInput(*) {
global
myGui.Submit()
selectedMsg := ddl.Text
myGui.Destroy()
; Handle Custom Message input
if (selectedMsg = "Custom") {
customGui := Gui()
customGui.Title := "Custom Message"
customGui.Add("Text",, "Enter your custom message:")
customEdit := customGui.Add("Edit", "w300 r5")
customGui.Add("Button", "Default w80", "OK").OnEvent("Click", (*) => customGui.Submit())
customGui.Show()
WinWaitClose(customGui)
msgText := Trim(customEdit.Value)
if (msgText = "") {
MsgBox("Custom message cannot be empty!", "Error", "Iconx")
ExitApp
}
} else {
msgText := messages[selectedMsg]
}
; Use selected message file
selectedFile := selectedMsg "-people.txt"
; Read from selected file
content := FileRead(selectedFile)
lines := StrSplit(content, "`n", "`r")
toProcess := []
for line in lines {
line := Trim(line)
if (line != "" && !InStr(line, "?")) {
toProcess.Push(line)
}
}
if (toProcess.Length = 0) {
MsgBox("All contacts in " selectedFile " have been processed.", "Info", "Iconi")
ExitApp
}
; Check if Telegram program exists
if !ProcessExist("Telegram.exe") {
MsgBox("Telegram is not running.", "Error", "Iconx")
ExitApp
}
try {
WinActivate("ahk_exe Telegram.exe")
WinWaitActive("ahk_exe Telegram.exe",, 5)
} catch {
MsgBox("Could not activate Telegram window.", "Error", "Iconx")
ExitApp
}
global stopScriptFlag := false
Hotkey("F7", (*) => stopScriptFlag := true)
Hotkey("F8", (*) => ExitApp())
for contact in toProcess {
if stopScriptFlag {
MsgBox("Script stopped by user.", "Info", "Iconi")
ExitApp
}
; Search contact
Send("{Esc}")
Send("^f")
Sleep(250)
A_Clipboard := contact
Send("^v")
Sleep(750)
Send("{Enter}")
Sleep(500)
; Send message
A_Clipboard := msgText
Send("^v")
Sleep(250)
Send("{Enter}")
Sleep(500)
; Update selected message file
Loop lines.Length {
if (Trim(lines[A_Index]) = contact) {
lines[A_Index] := lines[A_Index] "?"
break
}
}
FileDelete(selectedFile)
for line in lines {
FileAppend(line "`n", selectedFile)
}
}
MsgBox("All messages sent successfully!", "Complete", "Iconi")
ExitApp
}