-
Notifications
You must be signed in to change notification settings - Fork 3
/
rijksbot
executable file
·39 lines (31 loc) · 1.09 KB
/
rijksbot
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
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path('lib'))
require 'dotenv'
require 'rijksbot'
Dotenv.load
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['RIJKSBOT_CONSUMER_KEY']
config.consumer_secret = ENV['RIJKSBOT_CONSUMER_SECRET']
config.access_token = ENV['RIJKSBOT_ACCESS_TOKEN']
config.access_token_secret = ENV['RIJKSBOT_ACCESS_SECRET']
end
# timeline = client.user_timeline(count: 800).map{|t| t.in_reply_to_status_id}
bot = Rijksbot.new(client)
last_checked = Time.now.utc - 86_400
loop do
mentions = client.mentions_timeline.select { |tweet| tweet.created_at > last_checked }
last_checked = Time.now.utc
mentions.each do |tweet|
puts "Recieved mention: #{tweet.text} from #{tweet.user.screen_name}"
if bot.already_replied?(tweet)
puts "already replied to #{tweet.text}"
else
puts "replying to #{tweet.user.screen_name}"
search_term = bot.extract_search(tweet)
image = bot.get_image(search_term) || bot.random_image
bot.reply_with_image(tweet, image)
end
end
sleep 30
end
puts 'finished'