Documentation
¶
Index ¶
- type SleepPolicy
- type TwitterBot
- func (t *TwitterBot) AutoFollowFollowers(query string, maxPage int, sleepPolicy SleepPolicy)
- func (t *TwitterBot) AutoFollowFollowersAsync(query string, maxPage int, sleepPolicy *SleepPolicy)
- func (t *TwitterBot) AutoUnfollowFriendsAsync(sleepPolicy *SleepPolicy)
- func (t *TwitterBot) Close()
- func (t *TwitterBot) RetweetOnce(queries, bannedQueries []string) error
- func (t *TwitterBot) RetweetOnceAsync(searchQueries, bannedQueries []string)
- func (t *TwitterBot) RetweetPeriodically(searchQueries, bannedQueries []string, freq time.Duration)
- func (t *TwitterBot) RetweetPeriodicallyAsync(searchQueries, bannedQueries []string, freq time.Duration)
- func (t *TwitterBot) SetLikePolicy(auto bool, threshold int)
- func (t *TwitterBot) SetRetweetPolicy(maxTry int, like bool)
- func (t *TwitterBot) TweetImageOnce(msg, archiveURL, img string) error
- func (t *TwitterBot) TweetImagePeriodically(fetch func() (string, string, string, error), freq time.Duration)
- func (t *TwitterBot) TweetImagePeriodicallyAsync(fetch func() (string, string, string, error), freq time.Duration)
- func (t *TwitterBot) TweetOnce(fetch func() (string, error)) error
- func (t *TwitterBot) TweetOnceAsync(fetch func() (string, error))
- func (t *TwitterBot) TweetPeriodically(fetch func() (string, error), freq time.Duration)
- func (t *TwitterBot) TweetPeriodicallyAsync(fetch func() (string, error), freq time.Duration)
- func (t *TwitterBot) TweetSliceOnce(fetch func() ([]string, error)) error
- func (t *TwitterBot) TweetSliceOnceAsync(fetch func() ([]string, error))
- func (t *TwitterBot) TweetSlicePeriodically(fetch func() ([]string, error), freq time.Duration)
- func (t *TwitterBot) TweetSlicePeriodicallyAsync(fetch func() ([]string, error), freq time.Duration)
- func (t *TwitterBot) UpdateProfileBanner(img string, width, height, offsetLeft, offsetTop int) error
- func (t *TwitterBot) Wait()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SleepPolicy ¶
type SleepPolicy struct {
// maxRand randomly sleeps after each request from '0' to 'maxRand' seconds
MaxRand int
// maybeSleep parameters enable the user to create a conditional sleep after each requests
// of 'maybeSleepChance' over 'maybeSleepTotalChance' chances. The sleep will last at least
// 'maybeSleepMin' seconds and a maximum of 'maybeSleepMax' seconds.
// For example, parameters 1, 10, 30, 60 design a random sleep between 30 to 60 seconds
// that will occur with a chance of 1 over 10 after each requests.
MaybeSleepChance int
MaybeSleepTotalChance int
MaybeSleepMin int
MaybeSleepMax int
}
SleepPolicy represents the sleeping behavior of the bot between requests to the twitter API. Their use is highly recommanded especially when you automatically follow and unfollow users. It will allow you to hide your bot face from twitter statistics analysis.
type TwitterBot ¶
type TwitterBot struct {
// contains filtered or unexported fields
}
TwitterBot represents the twitter bot.
func MakeTwitterBot ¶
func MakeTwitterBot(followersPath, friendsPath, tweetsPath string, debug bool) *TwitterBot
MakeTwitterBot creates a twitter bot. The database is made of 3 files: followers, friends and tweets. They are here to ensure to:
- not add a friend as friend
- not remove friendship from a non friend
- not retweet a tweet already retweeted
You have to set up 4 environment variables:
TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET.
They can be found here by creating a twitter app: https://apps.twitter.com/.
The 'debug' mode creates more logs and remove all sleeps between API twitter calls.
func MakeTwitterBotWithCredentials ¶
func MakeTwitterBotWithCredentials(followersPath, friendsPath, tweetsPath, consumerKey, consumerSecret, accessToken, accessSecret string, debug bool) *TwitterBot
MakeTwitterBotWithCredentials creates a twitter bot. Same as MakeTwitterBot but the twitter keys are given as input.
func (*TwitterBot) AutoFollowFollowers ¶
func (t *TwitterBot) AutoFollowFollowers(query string, maxPage int, sleepPolicy SleepPolicy)
AutoFollowFollowers automatically follows the followers of the first user fecthed using the given 'query'. The 'maxPage' parameter indicates the number of page of followers (5000 users max by page) we want to fetch. The sleep policy controls the type of sleep you want between requests.
func (*TwitterBot) AutoFollowFollowersAsync ¶
func (t *TwitterBot) AutoFollowFollowersAsync(query string, maxPage int, sleepPolicy *SleepPolicy)
AutoFollowFollowersAsync automatically asynchronously follows the followers of the first user fecthed using the given 'query'. The 'maxPage' parameter indicates the number of page of followers (5000 users max by page) we want to fetch. The sleep policy controls the type of sleep you want between requests.
func (*TwitterBot) AutoUnfollowFriendsAsync ¶
func (t *TwitterBot) AutoUnfollowFriendsAsync(sleepPolicy *SleepPolicy)
AutoUnfollowFriendsAsync automatically asynchronously unfollows friends from database that were added at least a day ago by default. The sleep policy controls the type of sleep you want between requests.
func (*TwitterBot) RetweetOnce ¶
func (t *TwitterBot) RetweetOnce(queries, bannedQueries []string) error
RetweetOnce retweets randomly, with a maximum of 'retweetPolicy.maxTry' tries, a tweet matching one element of the input queries slice. It returns an error if the loading of tweets in database failed or if the retweet itself failed.
func (*TwitterBot) RetweetOnceAsync ¶
func (t *TwitterBot) RetweetOnceAsync(searchQueries, bannedQueries []string)
RetweetOnceAsync retweets asynchronously and randomly, with a maximum of 'retweetPolicy.maxTry' tries, a tweet matching one element of the input queries slice. It logs errors if the loading of tweets in database failed or if the retweets itself failed.
func (*TwitterBot) RetweetPeriodically ¶
func (t *TwitterBot) RetweetPeriodically(searchQueries, bannedQueries []string, freq time.Duration)
RetweetPeriodically retweets periodically and randomly, with a maximum of 'retweetPolicy.maxTry' tries, a tweet matching one element of the input queries slice. The retweet frequencies is set up by the given 'freq' input parameter. It logs errors if the loading of tweets in database failed or if the retweets itself failed.
func (*TwitterBot) RetweetPeriodicallyAsync ¶
func (t *TwitterBot) RetweetPeriodicallyAsync(searchQueries, bannedQueries []string, freq time.Duration)
RetweetPeriodicallyAsync retweets asynchronously, periodically and randomly, with a maximum of 'retweetPolicy.maxTry' tries, a tweet matching one element of the input queries slice. The retweet frequencies is set up by the given 'freq' input parameter. It logs errors if the loading of tweets in database failed or if the retweets itself failed.
func (*TwitterBot) SetLikePolicy ¶
func (t *TwitterBot) SetLikePolicy(auto bool, threshold int)
SetLikePolicy sets the like policy that allows to automatically likes tweets that are already liked above a threshold.
func (*TwitterBot) SetRetweetPolicy ¶
func (t *TwitterBot) SetRetweetPolicy(maxTry int, like bool)
SetRetweetPolicy sets the retweet policy that allows to try to retweet 'maxTry' times when looping through a list of tweets to retweet. The 'like' parameter controls the ability to like the tweet or the retweet using the like policy.
func (*TwitterBot) TweetImageOnce ¶
func (t *TwitterBot) TweetImageOnce(msg, archiveURL, img string) error
TweetImageOnce tweets the given 'msg', 'archiveURL' and img' data provided as strings. Note: internally, the 'img' data will be encoded to base 64 in order to be properly tweeted via the twitter API.
func (*TwitterBot) TweetImagePeriodically ¶
func (t *TwitterBot) TweetImagePeriodically(fetch func() (string, string, string, error), freq time.Duration)
TweetImagePeriodically tweets periodically the message and image returned by the 'fetch' callback. The tweet frequencies is set up by the given 'freq' input parameter. It only logs the error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetImagePeriodicallyAsync ¶
func (t *TwitterBot) TweetImagePeriodicallyAsync(fetch func() (string, string, string, error), freq time.Duration)
TweetImagePeriodicallyAsync tweets asynchronously and periodically the message and image returned by the 'fetch' callback. The tweet frequencies is set up by the given 'freq' input parameter. It only logs the error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetOnce ¶
func (t *TwitterBot) TweetOnce(fetch func() (string, error)) error
TweetOnce tweets the message returned by the 'fetch' callback. It returns an error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetOnceAsync ¶
func (t *TwitterBot) TweetOnceAsync(fetch func() (string, error))
TweetOnceAsync tweets asynchronously the message returned by the 'fetch' callback. It only logs the error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetPeriodically ¶
func (t *TwitterBot) TweetPeriodically(fetch func() (string, error), freq time.Duration)
TweetPeriodically tweets periodically the message returned by the 'fetch' callback. The tweet frequencies is set up by the given 'freq' input parameter. It only logs the error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetPeriodicallyAsync ¶
func (t *TwitterBot) TweetPeriodicallyAsync(fetch func() (string, error), freq time.Duration)
TweetPeriodicallyAsync tweets asynchronously and periodically the message returned by the 'fetch' callback. The tweet frequencies is set up by the given 'freq' input parameter. It only logs the error if the 'fetch' call failed or if the tweet itself failed.
func (*TwitterBot) TweetSliceOnce ¶
func (t *TwitterBot) TweetSliceOnce(fetch func() ([]string, error)) error
TweetSliceOnce tweets the slice returned by the given 'fetch' callback. It returns an error is the 'fetch' calls fails and only logs errors for each failed tweet tentative.
func (*TwitterBot) TweetSliceOnceAsync ¶
func (t *TwitterBot) TweetSliceOnceAsync(fetch func() ([]string, error))
TweetSliceOnceAsync tweets asynchronously the slice returned by the given 'fetch' callback. It logs errors for each failed tweet tentative.
func (*TwitterBot) TweetSlicePeriodically ¶
func (t *TwitterBot) TweetSlicePeriodically(fetch func() ([]string, error), freq time.Duration)
TweetSlicePeriodically tweets periodically the slice returned by the given 'fetch' callback. The slice tweet frequencies is set up by the given 'freq' input parameter. It logs errors for each failed tweet tentative.
func (*TwitterBot) TweetSlicePeriodicallyAsync ¶
func (t *TwitterBot) TweetSlicePeriodicallyAsync(fetch func() ([]string, error), freq time.Duration)
TweetSlicePeriodicallyAsync tweets asynchronously and periodically the slice returned by the given 'fetch' callback. The slice tweet frequencies is set up by the given 'freq' input parameter. It logs errors for each failed tweet tentative.
func (*TwitterBot) UpdateProfileBanner ¶
func (t *TwitterBot) UpdateProfileBanner(img string, width, height, offsetLeft, offsetTop int) error
UpdateProfileBanner updates the profile banner of the authenticated user with the given encoded image data. Other parameters are optionals and usable coinjointly only if they all are strictly positive. For more details, see: https://dev.twitter.com/rest/reference/post/account/update_profile_banner
func (*TwitterBot) Wait ¶
func (t *TwitterBot) Wait()
Wait waits for all the asynchronous calls to return
]
(