Exemplo n.º 1
0
// Block a user, and tweet a notification of why they were blocked
func blockUser(tweet anaconda.Tweet, ruleName string, cfg *Config, api *anaconda.TwitterApi) {
	// Block the user from the main account
	user, err1 := api.BlockUserId(tweet.User.Id, nil)
	if err1 != nil {
		log.Fatalf("Failed to block user: %s", err1)
	}

	// Let them know via the notification account
	anaconda.SetConsumerKey(cfg.Auth2.ConsumerKey)
	anaconda.SetConsumerSecret(cfg.Auth2.ConsumerSecret)
	api2 := anaconda.NewTwitterApi(cfg.Auth2.AccessToken, cfg.Auth2.AccessTokenSecret)

	// TODO: Make this work...
	params := url.Values{}
	params.Set("InReplyToStatusID", tweet.IdStr)
	params.Set("InReplyToStatusIdStr", tweet.IdStr)

	tweet2, err2 := api2.PostTweet("@"+user.ScreenName+
		": Hi! You've been blocked by @"+cfg.Settings.MyScreenName+
		". Reason: "+cfg.Settings.ReasonsURL+"#"+ruleName, params)
	if err2 != nil {
		log.Fatalf("Failed to notify blocked user: %s", err2)
	}

	// Display tweet in terminal
	fmt.Println(">> " + tweet2.Text)

	// Restore API to main account auth settings
	anaconda.SetConsumerKey(cfg.Auth.ConsumerKey)
	anaconda.SetConsumerSecret(cfg.Auth.ConsumerSecret)
}
Exemplo n.º 2
0
func blockUser(user User, api *anaconda.TwitterApi) (twitterUser anaconda.User, err error) {

	// userIDが0かuserIDの長さが10でないと気はscreenNameでブロックする
	if user.id == 0 || len(user.screenName) != 10 {
		// screen_name の時
		if twitterUser, err = api.BlockUser(user.screenName, nil); err == nil {
			return twitterUser, nil
		}
	} else {

		// Id の時
		if _, err := api.BlockUserId(user.id, nil); err == nil {
			return twitterUser, nil
		}
	}

	return
}