diff --git a/go/tg/l2.go b/go/tg/l2.go index 0a16e50..5ac4d0a 100644 --- a/go/tg/l2.go +++ b/go/tg/l2.go @@ -11,19 +11,19 @@ import ( "encoding/json" "crypto/tls" "time" + "strconv" ) -const ( - var Step string - var Proxy string -) +var userStates = make(map[int64]string) +var Proxy = make(map[int64]string) type DataIP struct { IP string `json:"query"` Country string `json:"country"` + ISP string `json:"isp"` } -func ProxyCheck(proxy) (bool, string, string) { +func ProxyCheck(proxy string) (bool, string, string, string) { proxyurl, err := url.Parse(proxy) if err != nil { fmt.Println(err) @@ -36,22 +36,22 @@ func ProxyCheck(proxy) (bool, string, string) { Transport: transport, Timeout: 20 * time.Second, } - req, err := http.NewRequest("GET", "http://ip-api.com", nil) + req, err := http.NewRequest("GET", "http://ip-api.com/json", nil) if err != nil { fmt.Println(err) } resp, err := client.Do(req) if err != nil { - return false, "", "" + return false, "Нет", "Нет", "Нет" fmt.Println(err) } - defer resp.Body.Close + defer resp.Body.Close() var data DataIP - err := json.NewDecoder(resp.Body).Decode(&data) + err = json.NewDecoder(resp.Body).Decode(&data) if err != nil { fmt.Println(err) } - return true, data.IP, data.Country + return true, data.IP, data.Country, data.ISP } func main() { @@ -68,5 +68,26 @@ func main() { u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates := bot.GetUpdatesChan(u) - for update := range updates {} - + for update := range updates { + if update.Message == nil { continue } + userID := update.Message.From.ID + if update.Message.IsCommand() { + if update.Message.Command() == "start" { + userStates[userID] = "wating" + bot.Send(tgbotapi.NewMessage(userID, "Введите прокси")) + } + continue + } + switch userStates[userID] { + case "wating": + prox := update.Message.Text + Proxy[userID] = prox + userStates[userID] = "" + status, ip, country, isp := ProxyCheck(Proxy[userID]) + stat := strconv.FormatBool(status) + msg := "Работа прокси: " + stat + "\nIP: " + ip + "\nСтрана: " + country + "\nПровайдер: " + isp + bot.Send(tgbotapi.NewMessage(userID, msg)) + } + } +} + diff --git a/go/tg/output/l2 b/go/tg/output/l2 new file mode 100755 index 0000000..eb81008 Binary files /dev/null and b/go/tg/output/l2 differ