You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

  1. package main
  2. import (
  3. "bufio"
  4. "fmt"
  5. "os"
  6. "strconv"
  7. "strings"
  8. "github.com/dghubble/go-twitter/twitter"
  9. )
  10. func postTweet(client *twitter.Client, text string) {
  11. tweet, httpResp, err := client.Statuses.Update(text, nil)
  12. if err != nil {
  13. fmt.Println(err)
  14. }
  15. if httpResp.Status != "200 OK" {
  16. c.Red("error: " + httpResp.Status)
  17. c.Purple("maybe twitter has blocked the account, CTRL+C, wait 15 minutes and try again")
  18. }
  19. fmt.Print("tweet posted: ")
  20. c.Green(tweet.Text)
  21. }
  22. func tweetFromFlock(flock Flock, text string) {
  23. fmt.Println("Starting to publish tweet: " + text)
  24. fmt.Println(strconv.Itoa(len(flock.Clients)))
  25. for i := 0; i < len(flock.Clients); i++ {
  26. fmt.Print("tweeting from: ")
  27. c.Cyan("@" + flock.ScreenNames[i])
  28. postTweet(flock.Clients[i], text)
  29. //waitTime(1)
  30. }
  31. }
  32. func optionTweetFromFlock(flock Flock) {
  33. fmt.Print("entry tweet content: ")
  34. newcommand := bufio.NewReader(os.Stdin)
  35. text, _ := newcommand.ReadString('\n')
  36. text = strings.TrimSpace(text)
  37. fmt.Print("tweet content: ")
  38. c.Purple(text)
  39. c.Red("Are you sure? [y/n]")
  40. newcommand = bufio.NewReader(os.Stdin)
  41. answer, _ := newcommand.ReadString('\n')
  42. answer = strings.TrimSpace(answer)
  43. switch answer {
  44. case "y":
  45. fmt.Println("ok, you are sure")
  46. tweetFromFlock(flock, text)
  47. break
  48. default:
  49. fmt.Println("Operation cancelled")
  50. break
  51. }
  52. }