lib/streambot.rb in streambot-0.2.2 vs lib/streambot.rb in streambot-0.2.3
- old
+ new
@@ -1,29 +1,35 @@
require 'rubygems'
require 'tweetstream'
require 'retweet'
+# The StreamBot class that provides a start and a stop method
class StreamBot
- # initialize method aka constructor
- def initialize(auth, blacklist=nil, *keywords)
+ # the initialization method aka the constructor
+ def initialize(auth, blacklist, *keywords)
@stream = TweetStream::Client.new(auth[:username],auth[:password])
- @retweet = Retweet.new(auth)
+ # initializing retweet
+ @retweet = Retweet.new(auth) #
+ # get string with keywords comma separated keywords
@keywords=keywords.join(',')
- @blacklist=blacklist if !blacklist.nil?
+ # set blacklist array if not nil
+ @blacklist=blacklist
end
- # starts the bot
+ # start the bot
def start
+ # starting to track the keywords via tweetstream
@stream.track(@keywords) do |status|
- if !@blacklist.include?(status.user)
- #puts "#{status.text} - #{status.id}"
+ # if status.user is NOT in blacklist then retweet it
+ if !@blacklist.include?(status.user)
+ #puts "#{status.text}"
@retweet.retweet(status.id)
end
end
end
- # stop bot
+ # stop the bot
def stop
@stream.stop
end
end