Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/discourse_chatbot/post/post_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def trigger_response(submission)
.order(created_at: :desc)
.limit(5)
.where.not(user_id: user.id)
.where("user_id > 0")
.where("user_id > 0 OR user_id = ?", bot_user.id)
.first
&.user_id
prior_user_was_bot = last_other_posting_user_id == bot_user.id
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-chatbot
# about: a plugin that allows you to have a conversation with a configurable chatbot in Chat, Topics and Private Messages
# version: 3.1.5
# version: 3.1.6
# authors: merefield
# url: https://github.com/merefield/discourse-chatbot

Expand Down
30 changes: 30 additions & 0 deletions spec/lib/post/topic_auto_reply_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,36 @@ def start_conversation
expect(evaluation.trigger_response(post)).to include(human_participants_count: 1)
end

it "recognizes a configured negative-ID bot while ignoring other system accounts" do
negative_bot = Fabricate(:user, id: -42, username: "negative_bot")
SiteSetting.chatbot_bot_user = negative_bot.username
create_post(negative_bot, raw: "Here is a summary of the keynote.")
create_post(Discourse.system_user)
post = create_post(user)

expect(evaluation.trigger_response(post)).to include(
bot_user_id: negative_bot.id,
reply_to_message_or_post_id: post.id,
human_participants_count: 1,
automatic_topic_reply: true,
)

SiteSetting.chatbot_unlimited_topic_auto_replies = false
SiteSetting.chatbot_auto_reply_up_to_post_count = 0
expect(evaluation.trigger_response(post)).to eq(false)

SiteSetting.chatbot_unlimited_topic_auto_replies = true
create_post(other_user)
create_post(negative_bot)
expect(evaluation.trigger_response(create_post(user))).to eq(false)
end

it "does not treat an unrelated negative-ID account as prior chatbot participation" do
create_post(Fabricate(:user, id: -42))

expect(evaluation.trigger_response(create_post(user))).to eq(false)
end

it "applies the limit to category auto-responses" do
SiteSetting.chatbot_auto_respond_categories = topic.category_id.to_s
SiteSetting.chatbot_unlimited_topic_auto_replies = false
Expand Down
Loading