lib/cosgrove/comment_job.rb in cosgrove-0.0.2 vs lib/cosgrove/comment_job.rb in cosgrove-0.0.3rc1
- old
+ new
@@ -4,36 +4,33 @@
class CommentJob
include Utils
include Support
def perform(event, slug, template, message = nil)
+ chain = :steem
author_name, permlink = parse_slug slug
- muted = muted by: steem_account, chain: :steem
+ muted = muted by: steem_account, chain: chain
- posts = SteemData::Post.root_posts.where(author: author_name, permlink: permlink)
+ author = find_author(chain: chain, author_name: author_name)
- post = posts.first
- author = SteemData::Account.find_by(name: author_name)
+ return if author.nil?
- if post.nil?
- # Fall back to RPC
- response = api(:steem).get_content(author_name, permlink)
- unless response.result.author.empty?
- post = response.result
- created = Time.parse(post.created + 'Z')
- cashout_time = Time.parse(post.cashout_time + 'Z')
- end
- end
+ post = find_comment(chain: chain, author: author_name, permlink: permlink)
if post.nil?
cannot_find_input(event)
return
end
created ||= post.created
cashout_time ||= post.cashout_time
+ if created.class == String
+ created = Time.parse(created + 'Z')
+ cashout_time = Time.parse(cashout_time + 'Z')
+ end
+
nope = if post.nil?
"Sorry, couldn't find that."
elsif cashout_time < Time.now.utc
'Unable to comment on that. Too old.'
elsif post.parent_permlink == 'nsfw'
@@ -51,10 +48,10 @@
elsif muted.include? author_name
puts "Won't vote because author muted."
'Unable to vote.'
# elsif template == :welcome && author.post_count != 1
# 'Sorry, this function is intended to welcome new authors.'
- elsif SteemData::Post.where(author: steem_account, parent_permlink: post.permlink).any?
+ elsif find_comment(chain: :steem, author: steem_account, parent_permlink: post.permlink).any?
title = post.title
title = post.permlink if title.empty?
"I already commented on #{title} by #{post.author}."
end