about summary refs log tree commit diff
path: root/app/lib/command_tag/processor.rb
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-21 02:48:51 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:44:01 -0500
commit627d9831cf64140f0092ff71b49b6e2f81e2b45b (patch)
treed4a205a23042efc1e3baeccc9123a3327292ed34 /app/lib/command_tag/processor.rb
parent227d8957f58307d667fe3a5a2e5330bce911babd (diff)
[Convenience] Parse command tags at the end of lines containing only mentions and/or hashtags
Diffstat (limited to 'app/lib/command_tag/processor.rb')
-rw-r--r--app/lib/command_tag/processor.rb9
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?