about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2020-03-25 11:27:47 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2020-03-25 11:27:47 -0400
commitcaee7157a27176082912a02b2851390727c6aac3 (patch)
tree2a4255f09f077bd52f23c257878b82de00ee58a4
downloadtaucheck-caee7157a27176082912a02b2851390727c6aac3.tar.gz
taucheck-caee7157a27176082912a02b2851390727c6aac3.tar.bz2
taucheck-caee7157a27176082912a02b2851390727c6aac3.zip
Initial commit
-rw-r--r--Gemfile2
-rw-r--r--config.yml8
-rw-r--r--taucheck.rb50
3 files changed, 60 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7cdfb06 --- /dev/null +++ b/Gemfile
@@ -0,0 +1,2 @@
1gem 'discordrb'
2gem '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 @@
1---
2 tumblr_consumer_key: ""
3 tumblr_consumer_secret: ""
4 tumblr_access_token: ""
5 tumblr_access_secret: ""
6 tumblr_url: ""
7 discord_token: ""
8 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 @@
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