Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'twitter'
# Bot implementation
class Complimentator
# Module that holds all commands
module Command
def compliment(tweet)
update(tweet, @compliments.sample)
end
private
def update(tweet, msg)
status = "@#{tweet.user.screen_name} #{msg}"
@rest.update(status, in_reply_to_status_id: tweet.id).id
end
end
include Command
def initialize
keys = {
consumer_key: 'YOUR_KEY',
consumer_secret: 'YOUR_SECRET',
access_token: 'YOUR_TOKEN',
access_token_secret: 'YOUR_SECRET'
}
@rest = Twitter::REST::Client.new(keys)
@stream = Twitter::Streaming::Client.new(keys)
@compliments = [
'You have beautiful eyes!',
'You look nice today!',
'I love your smile',
'You are a smart cookie',
'I bet you sweat glitter'
]
end
def listen
@stream.user do |object|
next unless object.is_a?(Twitter::Tweet)
puts "#{object.text} - written by #{object.user.screen_name}"
text = object.text.downcase
Command.instance_methods.each do |command|
if text.include?('please') && text.include?(command.to_s)
puts "run: #{command}"
send(command, object)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.