-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsent.go
57 lines (44 loc) · 1000 Bytes
/
sent.go
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
package main
import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"regexp"
)
// TODO: get ig username.
func get_url(dst string) string {
return fmt.Sprintf("https://ngl.link/%s", dst)
}
func get_device_token(body *[]byte) *string {
tokens := regexp.MustCompile(`;token=([a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+-([a-zA-Z0-9]+)?)`).FindAllStringSubmatch(string(*body), -1)
if len(tokens) != 1 {
return nil
}
return &tokens[0][len(tokens[0])/2]
}
func Sent(dst *string, msg *string) (*string, error) {
res, err := http.Get(get_url(*dst))
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
token := get_device_token(&body)
if token == nil {
return nil, errors.New("user not found")
}
res, err = http.PostForm(get_url(*dst), url.Values{
"question": []string{*msg},
"deviceId": []string{*token},
})
if err != nil {
return nil, err
}
res.Body.Close()
return token, nil
}