Rename plugin to discourse-chat-integration

This commit is contained in:
David Taylor 2017-07-03 11:08:14 +01:00
parent b824773a8a
commit 4643ad255c
8 changed files with 33 additions and 33 deletions

View File

@ -1,3 +1,3 @@
# discourse-chat
# discourse-chat-integration
This plugin is a work in progress, it is not yet ready for use

View File

@ -1,27 +1,27 @@
plugins:
chat_enabled:
chat_integration_enabled:
default: false
chat_discourse_username:
chat_integration_discourse_username:
default: system
chat_delay_seconds:
chat_integration_delay_seconds:
default: 20
#######################################
########## SLACK SETTINGS #############
#######################################
chat_slack_enabled:
chat_integration_slack_enabled:
default: false
chat_slack_outbound_webhook_url:
chat_integration_slack_outbound_webhook_url:
default: ''
chat_slack_discourse_excerpt_length:
chat_integration_slack_discourse_excerpt_length:
default: 400
chat_slack_icon_url:
chat_integration_slack_icon_url:
default: ''
chat_slack_access_token:
chat_integration_slack_access_token:
default: ''
#######################################
######### TELEGRAM SETTINGS ###########
#######################################
chat_telegram_enabled:
chat_integration_telegram_enabled:
default: false

View File

@ -2,7 +2,7 @@ module DiscourseChat
module Manager
def self.guardian
Guardian.new(User.find_by(username: SiteSetting.chat_discourse_username))
Guardian.new(User.find_by(username: SiteSetting.chat_integration_discourse_username))
end
def self.trigger_notifications(post_id)

View File

@ -3,7 +3,7 @@ require_relative "slack_message_formatter.rb"
module DiscourseChat::Provider::SlackProvider
PROVIDER_NAME = "slack".freeze
def self.excerpt(post, max_length = SiteSetting.chat_slack_discourse_excerpt_length)
def self.excerpt(post, max_length = SiteSetting.chat_integration_slack_discourse_excerpt_length)
doc = Nokogiri::HTML.fragment(post.excerpt(max_length,
remap_emoji: true,
keep_onebox_source: true
@ -25,8 +25,8 @@ module DiscourseChat::Provider::SlackProvider
category = (topic.category.parent_category) ? "[#{topic.category.parent_category.name}/#{topic.category.name}]": "[#{topic.category.name}]"
icon_url =
if !SiteSetting.chat_slack_icon_url.blank?
"#{Discourse.base_url}#{SiteSetting.chat_slack_icon_url}"
if !SiteSetting.chat_integration_slack_icon_url.blank?
"#{Discourse.base_url}#{SiteSetting.chat_integration_slack_icon_url}"
elsif !SiteSetting.logo_small_url.blank?
"#{Discourse.base_url}#{SiteSetting.logo_small_url}"
end
@ -72,7 +72,7 @@ module DiscourseChat::Provider::SlackProvider
attachments.concat message[:attachments]
uri = URI("https://slack.com/api/chat.update" +
"?token=#{SiteSetting.chat_slack_access_token}" +
"?token=#{SiteSetting.chat_integration_slack_access_token}" +
"&username=#{CGI::escape(record[:message][:username])}" +
"&text=#{CGI::escape(record[:message][:text])}" +
"&channel=#{record[:channel]}" +
@ -81,7 +81,7 @@ module DiscourseChat::Provider::SlackProvider
)
else
uri = URI("https://slack.com/api/chat.postMessage" +
"?token=#{SiteSetting.chat_slack_access_token}" +
"?token=#{SiteSetting.chat_integration_slack_access_token}" +
"&username=#{CGI::escape(message[:username])}" +
"&icon_url=#{CGI::escape(message[:icon_url])}" +
"&channel=#{ message[:channel].gsub('#', '') }" +
@ -98,7 +98,7 @@ module DiscourseChat::Provider::SlackProvider
def self.send_via_webhook(message)
http = Net::HTTP.new("hooks.slack.com", 443)
http.use_ssl = true
req = Net::HTTP::Post.new(URI(SiteSetting.chat_slack_outbound_webhook_url), 'Content-Type' =>'application/json')
req = Net::HTTP::Post.new(URI(SiteSetting.chat_integration_slack_outbound_webhook_url), 'Content-Type' =>'application/json')
req.body = message.to_json
response = http.request(req)
response
@ -107,7 +107,7 @@ module DiscourseChat::Provider::SlackProvider
def self.trigger_notification(post, channel)
message = slack_message(post, channel)
if SiteSetting.chat_slack_access_token.empty?
if SiteSetting.chat_integration_slack_access_token.empty?
self.send_via_webhook(message)
else
self.send_via_api(post, channel, message)

View File

@ -1,15 +1,15 @@
# name: discourse-chat
# name: discourse-chat-integration
# about: This plugin integrates discourse with a number of chat providers
# version: 0.1
# url: https://github.com/discourse/discourse-chat
# url: https://github.com/discourse/discourse-chat-integration
enabled_site_setting :chat_enabled
enabled_site_setting :chat_integration_enabled
after_initialize do
module ::DiscourseChat
PLUGIN_NAME = "discourse-chat".freeze
PLUGIN_NAME = "discourse-chat-integration".freeze
class Engine < ::Rails::Engine
engine_name DiscourseChat::PLUGIN_NAME
@ -40,7 +40,7 @@ after_initialize do
module ::Jobs
class NotifyChats < Jobs::Base
def execute(args)
return if not SiteSetting.chat_enabled? # Plugin may have been disabled since job triggered
return if not SiteSetting.chat_integration_enabled? # Plugin may have been disabled since job triggered
::DiscourseChat::Manager.trigger_notifications(args[:post_id])
end
@ -48,9 +48,9 @@ after_initialize do
end
DiscourseEvent.on(:post_created) do |post|
if SiteSetting.chat_enabled?
if SiteSetting.chat_integration_enabled?
# This will run for every post, even PMs. Don't worry, they're filtered out later.
Jobs.enqueue_in(SiteSetting.chat_delay_seconds.seconds,
Jobs.enqueue_in(SiteSetting.chat_integration_delay_seconds.seconds,
:notify_chats,
post_id: post.id
)

View File

@ -12,7 +12,7 @@ RSpec.describe PostCreator do
describe 'when a post is created' do
describe 'when plugin is enabled' do
before do
SiteSetting.chat_enabled = true
SiteSetting.chat_integration_enabled = true
end
it 'should schedule a chat notification job' do
@ -25,7 +25,7 @@ RSpec.describe PostCreator do
job = Jobs::NotifyChats.jobs.last
expect(job['at'])
.to eq((Time.zone.now + SiteSetting.chat_delay_seconds.seconds).to_f)
.to eq((Time.zone.now + SiteSetting.chat_integration_delay_seconds.seconds).to_f)
expect(job['args'].first['post_id']).to eq(post.id)
end
@ -34,7 +34,7 @@ RSpec.describe PostCreator do
describe 'when plugin is not enabled' do
before do
SiteSetting.chat_enabled = false
SiteSetting.chat_integration_enabled = false
end
it 'should not schedule a job for chat notifications' do

View File

@ -109,7 +109,7 @@ RSpec.describe DiscourseChat::Manager do
group.add(user)
# Set the chat_user to the newly created non-admin user
SiteSetting.chat_discourse_username = 'david'
SiteSetting.chat_integration_discourse_username = 'david'
# Create a category
category = Fabricate(:category, name: "Test category")

View File

@ -53,12 +53,12 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
describe '.trigger_notifications' do
before do
SiteSetting.chat_slack_outbound_webhook_url = "https://hooks.slack.com/services/abcde"
SiteSetting.chat_slack_enabled = true
SiteSetting.chat_integration_slack_outbound_webhook_url = "https://hooks.slack.com/services/abcde"
SiteSetting.chat_integration_slack_enabled = true
end
before do
@stub1 = stub_request(:post, SiteSetting.chat_slack_outbound_webhook_url).to_return(body: "success")
@stub1 = stub_request(:post, SiteSetting.chat_integration_slack_outbound_webhook_url).to_return(body: "success")
end
@ -71,7 +71,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
describe 'with api token' do
before do
SiteSetting.chat_slack_access_token = "magic"
SiteSetting.chat_integration_slack_access_token = "magic"
@stub2 = stub_request(:post, %r{https://slack.com/api/chat.postMessage}).to_return(body: "{\"success\":true, \"ts\": \"#{Time.now.to_i}.012345\", \"message\": {\"attachments\": [], \"username\":\"blah\", \"text\":\"blah2\"} }", headers: {'Content-Type' => 'application/json'})
@stub3 = stub_request(:post, %r{https://slack.com/api/chat.update}).to_return(body: '{"success":true, "ts": "some_message_id"}', headers: {'Content-Type' => 'application/json'})
end