blob: 0fcd74eb8bf76fc75c6dd5ab22cb507756e5e35e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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)
body = post["summary"] + "\n" + post["post_url"]
puts body
@discord.send_message(@channel_id, body)
end
end
config = YAML.load_file(ARGV[0] || "config.yml")
checker = Checker.new(config)
checker.run
|