-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
134 lines (118 loc) · 4.62 KB
/
handler.go
File metadata and controls
134 lines (118 loc) · 4.62 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
package webhook
import (
"encoding/json"
"fmt"
"github.com/aiteung/atapi"
"github.com/aiteung/atmessage"
"github.com/aiteung/module/model"
"github.com/whatsauth/wa"
"math/rand"
"net/http"
"os"
"strconv"
)
func PostBalasan(w http.ResponseWriter, r *http.Request) {
var msg model.IteungMessage
var resp atmessage.Response
json.NewDecoder(r.Body).Decode(&msg)
link := "https://medium.com/@sidiqfaisal30/cara-generate-code-qr-di-app-pakarbi-2d485478fe14"
if r.Header.Get("Secret") == os.Getenv("SECRET") {
if msg.Message == "loc" || msg.Message == "Loc" || msg.Message == "lokasi" || msg.LiveLoc {
location, err := ReverseGeocode(msg.Latitude, msg.Longitude)
if err != nil {
// Handle the error (e.g., log it) and set a default location name
location = "Unknown Location"
}
reply := fmt.Sprintf("heyyo, ni hao, kamu pasti lagi di %s \n Koordinatenya : %s - %s\n Cara Penggunaan WhatsAuth Ada di link dibawah ini"+
"yaa kak %s\n", location,
strconv.Itoa(int(msg.Longitude)), strconv.Itoa(int(msg.Latitude)), link)
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: reply,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
} else if msg.Message == "Allahuakbar" || msg.Message == "Innalillahi" || msg.Message == "Asstaghfirullah" {
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: fmt.Sprintf("Assyaghfirullah kang/eteh %s kasar bangett, aku jadi atut tauu", msg.Alias_name),
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
} else if msg.Message == "Cakep" || msg.Message == "Ganteng" || msg.Message == "Cantink" {
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: fmt.Sprintf("Arigatouu kang/eteh %s kamu jugaa cakep kouu", msg.Alias_name),
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
} else {
randm := []string{
"nihao, HI bro " + msg.Alias_name + "\n Faisal-Kun lagi sok sibuk \n I bot PakArbi nice to meet you, semoga kendaraan Anda tetap Aman. <3 \n Cara Generate code QR di app PakArbi ada di link berikut ini ya kak/teh...\n" + link,
"Asstghfirullah. Please Don't SPAM nanti Anda kena banned oleh pihak Whatsapp",
"hayyyaa ola ini lagi sibuk ",
"kak/teh cakep banget tau",
"Malam tak seindah ketika membayangimu ketika membuat website.",
}
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: GetRandomString(randm),
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://api.wa.my.id/api/send/message/text")
}
} else {
resp.Response = "Secret Salah"
}
fmt.Fprintf(w, resp.Response)
}
func ReverseGeocode(latitude, longitude float64) (string, error) {
// OSM Nominatim API endpoint
apiURL := fmt.Sprintf("https://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f", latitude, longitude)
// Make a GET request to the API
resp, err := http.Get(apiURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
// Decode the response
var result map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return "", err
}
// Extract the place name from the response
displayName, ok := result["display_name"].(string)
if !ok {
return "", fmt.Errorf("unable to extract display_name from the API response")
}
return displayName, nil
}
func Liveloc(w http.ResponseWriter, r *http.Request) {
var msg model.IteungMessage
var resp atmessage.Response
json.NewDecoder(r.Body).Decode(&msg)
// Reverse geocode to get the place name
location, err := ReverseGeocode(msg.Latitude, msg.Longitude)
if err != nil {
// Handle the error (e.g., log it) and set a default location name
location = "Unknown Location"
}
reply := fmt.Sprintf("heyyo, ni hao, kamu pasti lagi di %s \n Koordinatenya : %s - %s\n", location,
strconv.Itoa(int(msg.Longitude)), strconv.Itoa(int(msg.Latitude)))
if r.Header.Get("Secret") == os.Getenv("SECRET") {
dt := &wa.TextMessage{
To: msg.Phone_number,
IsGroup: false,
Messages: reply,
}
resp, _ = atapi.PostStructWithToken[atmessage.Response]("Token", os.Getenv("TOKEN"), dt, "https://cloud.wa.my.id/api/send/message/text")
} else {
resp.Response = "Secret Salah"
}
fmt.Fprintf(w, resp.Response)
}
func GetRandomString(strings []string) string {
randomIndex := rand.Intn(len(strings))
return strings[randomIndex]
}