From 627d9831cf64140f0092ff71b49b6e2f81e2b45b Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Tue, 21 Jul 2020 02:48:51 -0500 Subject: [Convenience] Parse command tags at the end of lines containing only mentions and/or hashtags --- app/lib/command_tag/processor.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app') 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? -- cgit