forum: automatically post new forum posts to Discord.

This commit is contained in:
evazion
2021-02-18 07:08:45 -06:00
parent 93f6e935a8
commit b63d8207a9
6 changed files with 106 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ class ForumPost < ApplicationRecord
after_destroy(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
ModAction.log("#{CurrentUser.user.name} deleted forum ##{rec.id}", :forum_post_delete)
end
after_create_commit :async_send_discord_notification
deletable
mentionable(
@@ -153,6 +154,15 @@ class ForumPost < ApplicationRecord
end
end
def async_send_discord_notification
DiscordNotificationJob.perform_later(forum_post: self)
end
def send_discord_notification
return unless policy(User.anonymous).show?
DiscordApiClient.new.post_message(self)
end
def build_response
dup.tap do |x|
x.body = x.quoted_response