diff options
-rw-r--r-- | app/lib/command_tag/processor.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index 4823c0af9..d9e49c84a 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -14,7 +14,7 @@ class CommandTag::Processor @conversation = status.conversation @run_once = Set[] @vars = {} - @text = status.text.gsub("\r\n", "\n").gsub("\n\r", "\n").gsub("\r", "\n") + @text = prepare_input(status.text) return unless @account.present? && @account.local? && @status.present? end @@ -29,7 +29,7 @@ class CommandTag::Processor @text = @text.join("\n").rstrip %w(before_save once_before_save).each { |suffix| execute_statements(suffix) } - if @text.blank? + if @text.blank? || @text.gsub(Account::MENTION_RE, '').strip.blank? %w(when_blank once_when_blank).each { |suffix| execute_statements(suffix) } unless (@status.published? && !@status.edited.zero?) || @text.present? @@ -51,6 +51,11 @@ class CommandTag::Processor private + def prepare_input(text) + text.gsub(/\r\n|\n\r|\r/, "\n") + .gsub(/^\s*((?:(?:#{Account::MENTION_RE}|#{Tag::HASHTAG_RE})\s*)+)#!/, "\\1\n#!") + end + def parse_statements @text.scan(STATEMENT_RE).flatten.map do |statement| next if statement.blank? || statement[0]&.strip.blank? |