From caee7157a27176082912a02b2851390727c6aac3 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 25 Mar 2020 11:27:47 -0400 Subject: Initial commit --- Gemfile | 2 ++ config.yml | 8 ++++++++ taucheck.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Gemfile create mode 100644 config.yml create mode 100644 taucheck.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7cdfb06 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +gem 'discordrb' +gem 'tumblr_client' \ No newline at end of file diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..880e703 --- /dev/null +++ b/config.yml @@ -0,0 +1,8 @@ +--- + tumblr_consumer_key: "" + tumblr_consumer_secret: "" + tumblr_access_token: "" + tumblr_access_secret: "" + tumblr_url: "" + discord_token: "" + discord_channel: 0 \ No newline at end of file diff --git a/taucheck.rb b/taucheck.rb new file mode 100644 index 0000000..6033f56 --- /dev/null +++ b/taucheck.rb @@ -0,0 +1,50 @@ +require 'tumblr_client' +require 'yaml' +require 'discordrb' + +class Checker + def initialize(config) + @blog_url = config["tumblr_url"] + @channel_id = config["discord_channel"] + @tumblr = Tumblr::Client.new({ + consumer_key: config["tumblr_consumer_key"], + consumer_secret: config["tumblr_consumer_secret"], + oauth_token: config["tumblr_access_token"], + oauth_token_secret: config["tumblr_access_secret"] + }) + @discord = Discordrb::Bot.new(token: config["discord_token"]) + end + + def run + puts "Here's the Discord invite url: " + @discord.invite_url + @discord.run(true) + + first_post = @tumblr.posts(@blog_url, limit: 1)["posts"].first + @last_post_id = first_post["id"] + handle_post(first_post) + + while true + sleep(300) + begin + posts = @tumblr.posts(@blog_url, limit: 10)["posts"] + posts.reverse_each do |post| + if post["id"] > @last_post_id + @last_post_id = post["id"] + handle_post(post) + end + end + rescue Exception => e + puts e + end + end + end + + def handle_post(post) + puts post["post_url"] + @discord.send_message(@channel_id, post["post_url"]) + end +end + +config = YAML.load_file("config.yml") +checker = Checker.new(config) +checker.run -- cgit 1.4.1