add service account helper to make announcer & janitor posting easier

master
multiple creatures 2019-12-12 04:29:25 -06:00
parent a8b4d5316c
commit 2be54072b1
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
module ServiceAccountHelper
def service_post(service, text, options = {})
acct = find_service_account(service)
return if acct.nil?
options[:text] = text
options[:local_only] ||= true
options[:nomentions] ||= true
options[:content_type] ||= 'text/markdown'
PostStatusService.new.call(acct, options.compact)
end
def service_dm(service, to, text, options = {})
options[:mentions] = [to]
options[:visibility] ||= :direct
service_post(service, text, options)
end
def find_service_account(service)
account_id = ENV["#{service.upcase}_USER"].to_i
return if account_id == 0
Account.find_by(id: account_id)
end
end