-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
138 lines (119 loc) · 3.62 KB
/
main.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
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
package main
import (
"compress/gzip"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"time"
utils "github.com/batiscuff/tg_booster/boosterutils"
browser "github.com/EDDYCJY/fake-useragent"
"github.com/gammazero/workerpool"
. "github.com/logrusorgru/aurora"
)
var (
goodProxies []string
re *regexp.Regexp = regexp.MustCompile(`data-view="(\w+)"`)
)
func addView(proxy string, link string) {
// Creating User-Agent
randomUA := browser.NewBrowser(browser.Client{}, browser.Cache{}).Random()
// Creating a client and adding a timeout and proxy
proxyUrl, _ := url.Parse(proxy)
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)},
}
// Creating and configure 1 request
request, _ := http.NewRequest("GET", link+"?embed=1", nil)
request.Close = true
request.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jxl,image/webp,*/*;q=0.8")
request.Header.Add("Accept-Encoding", "gzip, deflate, br")
request.Header.Add("User-Agent", randomUA)
// Sending 1 request and response processing
response, err := client.Do(request)
if err != nil {
fmt.Println(Sprintf(Red(err)))
return
}
defer response.Body.Close()
// Check that the server actually sent compressed data
var reader io.ReadCloser
switch response.Header.Get("Content-Encoding") {
case "gzip":
reader, err = gzip.NewReader(response.Body)
defer reader.Close()
default:
reader = response.Body
}
// Read resp body
data, err := ioutil.ReadAll(reader)
if err != nil {
fmt.Println(Sprintf("Error reading HTTP body. %q", Red(err)))
return
}
// Finding data-view by regexp
var dataViewString string
if re.Match([]byte(data)) {
dataViewString = string(re.FindSubmatch(data)[1])
} else {
fmt.Println("Data-views not found.")
return
}
// Configure 2 request
request, _ = http.NewRequest("GET", "https://t.me/v/?views="+dataViewString, nil)
request.Close = true
if len(response.Cookies()) != 0 {
request.AddCookie(response.Cookies()[0])
}
request.Header.Add("Accept", "*/*")
request.Header.Add("Accept-Encoding", "gzip, deflate, br")
request.Header.Add("Referer", link)
request.Header.Add("User-Agent", randomUA)
request.Header.Add("X-Requested-With", "XMLHttpRequest")
// Sending 2 request
response, err = client.Do(request)
if err != nil {
fmt.Println(Red(err))
return
}
defer response.Body.Close()
if response.StatusCode >= 200 && response.StatusCode < 300 {
fmt.Println(Sprintf(Yellow("Views added! [%s]"), Green(proxy)))
goodProxies = append(goodProxies, proxy)
}
}
func main() {
fileName := flag.String("p", "", "Proxies file or link with http proxies ended .txt")
workers := flag.Int("w", 50, "Count of workers on pool")
postLink := flag.String("l", "", "Link on Telegram post for boost views. https://t.me/...")
flag.Parse()
// Check the proxies file/link
proxies, err := utils.LoadProxies(*fileName)
if err != nil {
fmt.Println(Bold(Red(err)))
os.Exit(1)
}
// Checking the link to the post from the telegram channel
if utils.CheckPostLink(*postLink) != true {
fmt.Println(Bold(Red("Invalid post link! Example link: https://t.me/channel_name/1")))
os.Exit(1)
}
start := time.Now()
// --- Workers Pool --
wp := workerpool.New(*workers)
for _, proxy := range proxies {
proxy := proxy
wp.Submit(func() {
addView(proxy, *postLink)
})
}
wp.StopWait()
elapsed := time.Since(start)
var lenProxies, lenGoodProxies = len(proxies), len(goodProxies)
fmt.Println(Sprintf(Bold(Magenta("Proxies count: %d\tViews count: %d")), Cyan(lenProxies), Cyan(lenGoodProxies)))
fmt.Println(Sprintf(Bold(Magenta("Run time: %s")), Cyan(elapsed)))
}