about summary refs log tree commit diff stats
path: root/taucheck.rb
diff options
context:
space:
mode:
Diffstat (limited to 'taucheck.rb')
-rw-r--r--taucheck.rb50
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 @@
1require 'tumblr_client'
2require 'yaml'
3require 'discordrb'
4
5class 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
46end
47
48config = YAML.load_file("config.yml")
49checker = Checker.new(config)
50checker.run