Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Last active August 29, 2015 14:14
Show Gist options
  • Save jamtur01/f1e097ffca8c01196f52 to your computer and use it in GitHub Desktop.
Save jamtur01/f1e097ffca8c01196f52 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'chatterbot/dsl'
require "twitter"
require 'faraday'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
class FemalesBot
def start
blacklist "femalesbot"
puts "Starting FemalesBot."
begin
loop do
verbose
puts "Searching for Hew-mon females..."
search "females" do |tweet|
reply "#{tweet_user(tweet)} those hew-mon females! http://giphy.com/gifs/star-trek-ds9-ferengi-YimpOFRiw0y40", tweet
end
update_config
sleep 15
end
rescue Twitter::Error::TooManyRequests => error
puts "Rate limit exceeded: #{error}, sleeping for #{error.rate_limit.reset_in}"
sleep error.rate_limit.reset_in
retry
rescue
puts "Something went wrong. Retrying. #{$!}"
sleep 3
retry
end
end
def initialize
# Load config
@my_config = YAML.load_file('femalesbot.yml')
# I had to add this to resolve an "end of filei reached" problem
middleware = Proc.new do |builder|
builder.use Twitter::Request::MultipartWithFile
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Twitter::Response::RaiseError, Twitter::Error::ClientError
builder.use Twitter::Response::ParseJson
builder.use Twitter::Response::RaiseError, Twitter::Error::ServerError
builder.adapter :typhoeus
end
Twitter.middleware = Faraday::Builder.new(&middleware)
# Configure twitter gem
Twitter.configure do |config|
config.consumer_key = @my_config[:consumer_key]
config.consumer_secret = @my_config[:consumer_secret]
config.oauth_token = @my_config[:token]
config.oauth_token_secret = @my_config[:secret]
end
end
end
# Start main loop
bot = FemalesBot.new
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment