From cbc28e1fee7b4bafbe59c68113c28506eeb4e999 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Tue, 22 Sep 2020 16:00:46 -0500 Subject: Add #!keysmash command tag and "keysmash" template variable --- app/lib/command_tag/command/text_tools.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'app/lib/command_tag') 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 -- cgit