forked from enpitut2020/PocketMentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
43 lines (37 loc) · 1.33 KB
/
main.rb
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
require './twitter_client'
require './google_api'
require './firestore_client'
twitter_client = TwitterClient.new()
firestore_client = FirestoreClient.new()
SLEEP_TIME = 1 * 60 + 1
loop {
# # 暇ツイートパート
twitter_client.reloadRecentTweetId()
boredTweets = twitter_client.getBoredTweets()
if boredTweets.empty?
puts "暇ツイートはありません."
puts "みんな忙しそう"
else
twitter_client.setRecentTweet(boredTweets[0].id) unless boredTweets[0].nil?
boredTweets.reverse_each do |tweet|
recent_wish_doc = firestore_client.getUserRecentWishTweet(tweet.user.id)
message = twitter_client.createRecommendMessageFromText(recent_wish_doc[:tweet])
reply_message = twitter_client.addUserName(message, tweet.user.screen_name)
twitter_client.mention(reply_message, tweet.id)
end
end
# メンション処理パート
# リプライを取得
twitter_client.reloadRecentReplyId()
replies= twitter_client.getReplies()
twitter_client.setRecentReply(replies[0].id) unless replies[0].nil?
replies.each do |reply|
#リプライをfirestoreに保存
firestore_client.saveUser(reply)
firestore_client.saveTweet(reply)
#保存しましたみたいなことをリプする。
twitter_client.sendSavingMessage(reply)
end
# スリープ
sleep(SLEEP_TIME)
}