about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-20 22:32:14 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-20 22:32:14 -0500
commitc4718cd2be0b1a9ecbfa3b4c4168dd4f6eade17e (patch)
tree5aa59424eaa4ae8deed962bac5b858fc5d9b780c /app
parent7a37731210a94de037882c734c8110fc899c2903 (diff)
add `tf:head` bangtag
Diffstat (limited to 'app')
-rw-r--r--app/lib/bangtags.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 0e8b7c532..f40ccede3 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -110,6 +110,7 @@ class Bangtags
             @tf_cmds = []
             @component_stack.reject! {|c| c == :tf}
           else
+            @vars['_tf:head:count'] = 0 if cmd[1].downcase.in?(%w(head take))
             @tf_cmds.push(cmd[1..-1])
             @component_stack.push(:tf)
           end
@@ -593,6 +594,14 @@ class Bangtags
             tf_cmd[1..-1].in_groups_of(2) do |args|
               chunk.gsub!(*args) if args.all?
             end
+          when 'head', 'take'
+            n = tf_cmd[1].to_i
+            n = 1 unless n > 0
+            next if @vars['_tf:head:count'] == n
+            c = @vars['_tf:head:count'] || 0
+            parts = chunk.split.take(n - c)
+            @vars['_tf:head:full'] = c + parts.count
+            chunk = parts.join(' ')
           when 'admin'
             next unless @account.user.admin?
             next if tf_cmd[1].nil? || chunk.start_with?('`admin:')
@@ -660,7 +669,7 @@ class Bangtags
       @chunks << chunk unless chunk.nil?
     end
 
-    @vars.transform_values! {|v| v.rstrip}
+    @vars.transform_values! {|v| v.rstrip if v.is_a?(String)}
 
     postprocess_before_save