about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-12-12 04:29:25 -0600
committermultiple creatures <dev@multiple-creature.party>2019-12-12 04:29:25 -0600
commit2be54072b1ce4b2390641cd45b568465b5dcb5fc (patch)
tree87d8cef5b8be4e64038779e7ea802d1828082020 /app/helpers
parenta8b4d5316c1c9f3804377a10583a0a4d50549e25 (diff)
add service account helper to make announcer & janitor posting easier
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/service_account_helper.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/helpers/service_account_helper.rb b/app/helpers/service_account_helper.rb
new file mode 100644
index 000000000..f66641734
--- /dev/null
+++ b/app/helpers/service_account_helper.rb
@@ -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