diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2020-03-25 11:27:47 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2020-03-25 11:27:47 -0400 |
| commit | caee7157a27176082912a02b2851390727c6aac3 (patch) | |
| tree | 2a4255f09f077bd52f23c257878b82de00ee58a4 /taucheck.rb | |
| download | taucheck-caee7157a27176082912a02b2851390727c6aac3.tar.gz taucheck-caee7157a27176082912a02b2851390727c6aac3.tar.bz2 taucheck-caee7157a27176082912a02b2851390727c6aac3.zip | |
Initial commit
Diffstat (limited to 'taucheck.rb')
| -rw-r--r-- | taucheck.rb | 50 |
1 files changed, 50 insertions, 0 deletions
| diff --git a/taucheck.rb b/taucheck.rb new file mode 100644 index 0000000..6033f56 --- /dev/null +++ b/taucheck.rb | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | require 'tumblr_client' | ||
| 2 | require 'yaml' | ||
| 3 | require 'discordrb' | ||
| 4 | |||
| 5 | class Checker | ||
| 6 | def initialize(config) | ||
| 7 | @blog_url = config["tumblr_url"] | ||
| 8 | @channel_id = config["discord_channel"] | ||
| 9 | @tumblr = Tumblr::Client.new({ | ||
| 10 | consumer_key: config["tumblr_consumer_key"], | ||
| 11 | consumer_secret: config["tumblr_consumer_secret"], | ||
| 12 | oauth_token: config["tumblr_access_token"], | ||
| 13 | oauth_token_secret: config["tumblr_access_secret"] | ||
| 14 | }) | ||
| 15 | @discord = Discordrb::Bot.new(token: config["discord_token"]) | ||
| 16 | end | ||
| 17 | |||
| 18 | def run | ||
| 19 | puts "Here's the Discord invite url: " + @discord.invite_url | ||
| 20 | @discord.run(true) | ||
| 21 | |||
| 22 | first_post = @tumblr.posts(@blog_url, limit: 1)["posts"].first | ||
| 23 | @last_post_id = first_post["id"] | ||
| 24 | handle_post(first_post) | ||
| 25 | |||
| 26 | while true | ||
| 27 | sleep(300) | ||
| 28 | begin | ||
| 29 | posts = @tumblr.posts(@blog_url, limit: 10)["posts"] | ||
| 30 | posts.reverse_each do |post| | ||
| 31 | if post["id"] > @last_post_id | ||
| 32 | @last_post_id = post["id"] | ||
| 33 | handle_post(post) | ||
| 34 | end | ||
| 35 | end | ||
| 36 | rescue Exception => e | ||
| 37 | puts e | ||
| 38 | end | ||
| 39 | end | ||
| 40 | end | ||
| 41 | |||
| 42 | def handle_post(post) | ||
| 43 | puts post["post_url"] | ||
| 44 | @discord.send_message(@channel_id, post["post_url"]) | ||
| 45 | end | ||
| 46 | end | ||
| 47 | |||
| 48 | config = YAML.load_file("config.yml") | ||
| 49 | checker = Checker.new(config) | ||
| 50 | checker.run | ||
