Search Twitter for specific terms and automatically reply from your bot
account.
Please exercise reasonable benevolence with your new powers.
Installation
Add this line to your application's Gemfile:
gem 'twitter-bot'
And then execute:
$ bundle
Or install it yourself as:
$ gem install twitter-bot
Usage
Using your Twitter bot account:
-
Go to https://apps.twitter.com/app/new and create an app
-
Go to the Keys and Access Tokens tab and click "Create my access token"
at the bottom.
You will need to save the 2 keypairs on this page (consumer key/secret & token
key/secret) to configure your bot.
2. Create a bot
bot = Twitter::Bot.new(
consumer_key: 'value',
consumer_secret: 'value',
access_token_key: 'value',
access_token_secret: 'value')
bot.search('sneak peak') do |tweet|
'I think you mean "sneak peek"'
end
Advanced configuration
interval
: seconds to wait between polling requests (default: 5)user_agent
: custom user agent for Twitter API requests
More examples
bot.search('"how long is this tweet"') do |tweet|
"@#{tweet.user.screen_name} This is #{tweet.text.size} characters long"
end
bot.search('from:nihilist_arbys "horsey saurce"') { |tweet| 'Yum!' }
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request