Skip to content

Commit

Permalink
Fix triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
dsh0416 committed Nov 23, 2020
1 parent 03c2fa6 commit be074b5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions relay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ def get_user(login)
nil
end

def get_excellent_time(topic)
resp = Faraday.get("https://ruby-china.org/api/v3/topics/#{topic['id']}/replies.json")
actions = JSON.parse(resp.body)["replies"].select do |reply|
reply["action"] == "excellent"
end
return nil if actions.empty?
DateTime.parse(actions.first["created_at"]).to_time
end

resp = Faraday.get(
"https://ruby-china.org/api/v3/topics.json",
{ type: "excellent" }
)

topics = JSON.parse(resp.body)["topics"]

filtered = topics.reject do |topic|
Time.now - DateTime.parse(topic["created_at"]).to_time > INTERVAL
filtered = topics.select do |topic|
Time.now - get_excellent_time(topic) < INTERVAL
end

formatted = filtered.map do |topic|
Expand Down

0 comments on commit be074b5

Please sign in to comment.