a small collection of personal scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.8KB

  1. use strict;
  2. use warnings;
  3. use utf8;
  4. use String::Approx 'amatch';
  5. weechat::register ("wat", "shmibs", "0.3", "GPL", "untentionally obfscate speach ( usage: enable/disable with /wat <on|off> )", "", "");
  6. weechat::hook_command("wat", "", "", "", "", "toggle", "");
  7. weechat::hook_modifier("input_text_content", "catch_word", "");
  8. weechat::hook_modifier("input_text_for_buffer", "catch_send", "");
  9. my @replacements = ('pony', 'broken', 'portable', 'salivating', 'boring',
  10. 'garish', 'putrid', 'pustule', 'cardigan', 'foreign', 'dumpling',
  11. 'phalanges', 'goose', 'didactic', 'vroooOOOOM', 'zygote', 'tractor',
  12. 'blatant', 'authoritatively', 'feral', 'dung', 'scones', 'busted',
  13. 'tortoise', 'willingly', 'glorious', 'torpor', 'gracious', 'cretan',
  14. 'variantly', 'stammers', 'occupational', 'dissipated', 'Singapore',
  15. 'afterglow', 'toes', 'whorls', 'sneakiness', 'Johannesburg',
  16. 'inextricable', 'slaughterhouse', 'prophecy', 'zoo animal', 'beafy',
  17. 'telescoping', 'countess', 'marsupial', 'boots', 'guided', 'titillating',
  18. 'bequeath', 'delineation', 'ballpark', 'stultify', 'ionise', 'expand',
  19. 'cybernetics', 'alluring', 'medicinal', 'gross', 'fallopian', 'bituminous',
  20. 'soupy', 'whisper', 'blast', 'crunchy', 'categorical imperative', 'Arian',
  21. 'craving', 'triste', 'placenta', 'caramelised', 'plaster', 'God Fearing',
  22. 'hyperbole', 'tepid', 'gore', 'distance', 'Artistic Freedom', 'unix',
  23. 'drifting', 'bully');
  24. my @wrappers = ('%s.io', '%s.js', '%s.net', 'try %s or so', '%s-less',
  25. '%s-ish', 'and but so %s', 'GNU/%s', '/%s/', 'the %s debate', '%s, our
  26. benevolent dictator,');
  27. my $state = "off";
  28. my $length = 0;
  29. sub toggle {
  30. my $output = "";
  31. my $buffer = $_[1];
  32. if($_[2] eq "on") {
  33. $state = "on";
  34. }
  35. if($_[2] eq "off") {
  36. $state = "off";
  37. }
  38. return weechat::WEECHAT_RC_OK;
  39. }
  40. # catch words as they are typed
  41. sub catch_word {
  42. my ($data, $modifier_name, $buffer, $rval) = @_;
  43. if($rval) {
  44. if( $state eq "on" && substr($rval, 0, 1) ne "/" ) {
  45. if(length($rval) > $length) {
  46. $length = length($rval);
  47. if($length > 1) {
  48. if( substr($rval, $length-1, 1) eq " " && substr($rval, $length-2, 1) ne " " ) {
  49. $rval = mutate($rval);
  50. $rval .= " ";
  51. $length = length($rval);
  52. weechat::buffer_set($buffer, 'input', "$rval");
  53. weechat::buffer_set($buffer, 'input_pos', "$length");
  54. }
  55. }
  56. } else {
  57. $length = length($rval);
  58. }
  59. }
  60. }
  61. return $rval;
  62. }
  63. # check the last word before sending
  64. sub catch_send {
  65. my ($data, $modifier_name, $buffer, $rval) = @_;
  66. if( $state eq "on" && substr($rval, 0, 1) ne "/" ) {
  67. $rval = mutate($rval);
  68. }
  69. return $rval;
  70. }
  71. # apply modifications to the last word of the input string
  72. sub mutate {
  73. my @words = split(/ |\t|\n/, $_[0]);
  74. my $punctuation = 0;
  75. my $rnum = int(rand(100));
  76. if($words[$#words] && $rnum < 25) {
  77. # maintain the position of punctuation
  78. if( $words[$#words] =~ /[.,'"\?!:;\[\]\(\)]/ ) {
  79. $punctuation = substr($words[$#words], length($words[$#words])-1, 1);
  80. $words[$#words] = substr($words[$#words], 0, length($words[$#words])-1);
  81. }
  82. # grab a random wrapper from the list
  83. if($rnum < 4) {
  84. my $i = $wrappers[int(rand(@wrappers))];
  85. $words[$#words] = sprintf($i, $words[$#words]);
  86. }
  87. if($rnum >= 4 && $rnum < 11) {
  88. }
  89. # swap two words at random
  90. if($rnum >= 11 && $rnum < 15) {
  91. my $i = int(rand(@words));
  92. my $j = int(rand(@words));
  93. @words[$i,$j] = @words[$j,$i];
  94. }
  95. # swap chars
  96. if($rnum >= 15 && $rnum < 20) {
  97. my @chars = split(//, $words[$#words]);
  98. my $i = int(rand(@chars));
  99. my $j = int(rand(@chars));
  100. @chars[$i,$j] = @chars[$j,$i];
  101. $words[$#words] = join('', @chars);
  102. }
  103. # delete chars
  104. if($rnum >= 20) {
  105. }
  106. # maintain the position of punctuation, part
  107. # two
  108. if($punctuation) {
  109. $words[$#words] .= $punctuation;
  110. }
  111. }
  112. my $rval = join(' ', @words);
  113. return $rval;
  114. }