Created
July 2, 2014 21:00
-
-
Save flotwig/a4156023948864b75272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'snoo' | |
reddit = Snoo::Client.new :useragent => '/u/flotwig - Responds to "It is known." with "It is known." http://l.t.tl/1q' | |
reddit.log_in 'KhaleesiServantGirl', '' | |
debug = false | |
latest_id = 0 | |
def base10_reddit_id(base36_id) | |
return base36_id.split('_',2).last.to_i(36) | |
end | |
while comments = reddit.get_comments(:subreddit => 'KhSeGl+asoiaf+gameofthrones', | |
:sort => 'new') | |
puts 'Got new list of comments.' if debug | |
comments['data']['children'].each { |comment| | |
next unless base10_reddit_id(comment['data']['name']) > latest_id | |
latest_id = base10_reddit_id(comment['data']['name']) | |
next if comment['data']['author'] === 'KhaleesiServantGirl' | |
next if (comment['data']['body'] =~ /It\ is\ known[\.\!]/i).nil? | |
puts 'Match found, responding.' if debug | |
reddit.comment('It is known.',comment['data']['name']) | |
sleep 2 | |
} | |
sleep 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment