From 69ffa049edeb7ed5b7d192ac6ea394945f80f9b9 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 29 Sep 2026 17:26:10 +0100 Subject: [PATCH] FIX: recognize negative-ID chatbot users in topic follow-ups --- lib/discourse_chatbot/post/post_evaluation.rb | 2 +- plugin.rb | 2 +- spec/lib/post/topic_auto_reply_spec.rb | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/discourse_chatbot/post/post_evaluation.rb b/lib/discourse_chatbot/post/post_evaluation.rb index 23db1d9..69458f6 100644 --- a/lib/discourse_chatbot/post/post_evaluation.rb +++ b/lib/discourse_chatbot/post/post_evaluation.rb @@ -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 diff --git a/plugin.rb b/plugin.rb index 482b78a..c4e61e3 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 diff --git a/spec/lib/post/topic_auto_reply_spec.rb b/spec/lib/post/topic_auto_reply_spec.rb index e648e1e..98f909f 100644 --- a/spec/lib/post/topic_auto_reply_spec.rb +++ b/spec/lib/post/topic_auto_reply_spec.rb @@ -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