about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-09-22 16:00:46 -0500
committerFire Demon <firedemon@creature.cafe>2020-09-22 16:05:37 -0500
commitcbc28e1fee7b4bafbe59c68113c28506eeb4e999 (patch)
treed2ee70af74af39327f506ef8ec51f2e0caff8762
parent04e0a1fd3d43013d603092e09ac827b022cba3b9 (diff)
Add #!keysmash command tag and "keysmash" template variable
-rw-r--r--app/lib/command_tag/command/text_tools.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/lib/command_tag/command/text_tools.rb b/app/lib/command_tag/command/text_tools.rb
index 2c44167b4..b9c3f3ad7 100644
--- a/app/lib/command_tag/command/text_tools.rb
+++ b/app/lib/command_tag/command/text_tools.rb
@@ -1,6 +1,10 @@
 # frozen_string_literal: true
 
 module CommandTag::Command::TextTools
+  def handle_000_keysmash_startup(args = [100, 100])
+    @vars['keysmash'] = [handle_keysmash_with_return(args)]
+  end
+
   def handle_code_at_start(args)
     return if args.count < 2
 
@@ -55,4 +59,32 @@ module CommandTag::Command::TextTools
 
   alias handle_resub_before_save handle_replace_before_save
   alias handle_regex_sub_before_save handle_replace_before_save
+
+  def handle_keysmash_with_return(args)
+    keyboard = [
+      'asdf', 'jkl;',
+      'gh', "'",
+      'we', 'io',
+      'r', 'u',
+      'cv', 'nm',
+      't', 'x', ',',
+      'q', 'z',
+      'y', 'b',
+      'p', '[',
+      '.', '/',
+      ']', '\\'
+    ]
+
+    min_size = [[1, args[1].to_i].max, 100].min
+    max_size = [args[0].to_i, 100].min
+    max_size = 33 unless max_size.positive?
+
+    min_size, max_size = [max_size, min_size] if min_size > max_size
+
+    chunk = rand(min_size..max_size).times.map do
+      keyboard[(keyboard.size * (rand**3)).floor].split('').sample
+    end
+
+    chunk.join
+  end
 end