Sha256: 7fc78e6fbd9152c82cc5fa0667a82ab10e38fdeb59527f1341fcddeef724b374

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require_relative 'src/<%= bot_name %>.rb'
require "twitter"
require "tweetstream"

Twitter.configure do |config|
  config.consumer_key       = ENV['TWITTER_CONSUMER_KEY']
  config.consumer_secret    = ENV['TWITTER_CONSUMER_SECRET']
  config.oauth_token        = ENV['TWITTER_OAUTH_TOKEN']
  config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
end

TweetStream.configure do |config|
  config.consumer_key       = ENV['TWITTER_CONSUMER_KEY']
  config.consumer_secret    = ENV['TWITTER_CONSUMER_SECRET']
  config.oauth_token        = ENV['TWITTER_OAUTH_TOKEN']
  config.oauth_token_secret = ENV['TWITTER_OAUTH_SECRET']
  config.auth_method        = :oauth
end

loop do
  begin
    puts "starting search"
    TweetStream::Client.new.sample(language: 'en') do |tweet|

      # your bot should have a method called matches?(text)
      # if a tweet passes your matcher, the bot retweets it!

      if <%= class_name %>.matches? tweet.text
        puts "got one!"
        Twitter.retweet tweet.id
      end
    end
  rescue
    puts 'FAILURE'
  ensure
    sleep 300
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twitter_bot_generator-0.2.3 lib/twitter_bot_generator/templates/streaming-bot.rb.erb
twitter_bot_generator-0.2.2 lib/twitter_bot_generator/templates/streaming-bot.rb.erb