|
|
|
@ -139,6 +139,13 @@ func main() {
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get Bot information
|
|
|
|
|
botName, botUsername, err := getBotInfo(config.Token)
|
|
|
|
|
if err != nil {
|
|
|
|
|
printError(fmt.Sprintf("Failed to get bot information: %v", err))
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ensure message is provided
|
|
|
|
|
if message == "" {
|
|
|
|
|
printError("No message provided")
|
|
|
|
@ -195,6 +202,8 @@ func main() {
|
|
|
|
|
|
|
|
|
|
// Print the required information
|
|
|
|
|
fmt.Printf("\033[1mConfig Used:\033[0m %s\n", configUsed)
|
|
|
|
|
fmt.Printf("\033[1mBot Name:\033[0m %s\n", botName)
|
|
|
|
|
fmt.Printf("\033[1mBot Username:\033[0m @%s\n", botUsername)
|
|
|
|
|
fmt.Printf("\033[1mChat ID:\033[0m %s\n", config.ChatID)
|
|
|
|
|
fmt.Printf("\033[1mSilent:\033[0m %s\n", strconv.FormatBool(silent))
|
|
|
|
|
fmt.Printf("\033[1mMessage:\033[0m %s\n", message)
|
|
|
|
@ -221,3 +230,43 @@ func stripANSI(input string) string {
|
|
|
|
|
re := regexp.MustCompile(ansiPattern)
|
|
|
|
|
return re.ReplaceAllString(input, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getBotInfo(token string) (name string, username string, err error) {
|
|
|
|
|
urlStr := fmt.Sprintf("https://api.telegram.org/bot%s/getMe", token)
|
|
|
|
|
resp, err := http.Get(urlStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", "", err
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetMeResponse struct {
|
|
|
|
|
Ok bool `json:"ok"`
|
|
|
|
|
Result struct {
|
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
|
IsBot bool `json:"is_bot"`
|
|
|
|
|
FirstName string `json:"first_name"`
|
|
|
|
|
Username string `json:"username"`
|
|
|
|
|
} `json:"result"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var getMeResp GetMeResponse
|
|
|
|
|
err = json.Unmarshal(body, &getMeResp)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !getMeResp.Ok {
|
|
|
|
|
return "", "", fmt.Errorf("getMe failed: %s", getMeResp.Description)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name = getMeResp.Result.FirstName
|
|
|
|
|
username = getMeResp.Result.Username
|
|
|
|
|
|
|
|
|
|
return name, username, nil
|
|
|
|
|
}
|
|
|
|
|