changeset 28:fd62baedb568

Include punctuation in $relol; fix $midlol duplication
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 13 May 2013 12:29:44 -0400
parents 3f15551b3c69
children ed664d0da4ec
files teh-lol.pl
diffstat 1 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/teh-lol.pl
+++ b/teh-lol.pl
@@ -59,8 +59,20 @@
   ## Chatter name without possible colour codes
   $chatter = Xchat::strip_code($chatter);
 
-  #Match stuff like "lol", "loool" and "lololol"
-  if ($msg =~ /\b(l((o|(?<!l)lo)+)l)\b/i
+  ## Match stuff like "lol", "loool" and "lololol". Also mimic
+  ## punctuation.
+
+  if ($msg =~ /\b(l                ## Starting l, capture it in $1
+
+                 ((?:o|(?<!l)lo)+) ## either a single "o" or an "o"
+                                   ## followed by a bunch of "lolo",
+                                   ## capture it in $2
+
+                 l)                ## closing l
+
+                 ([\.!?]+|\b)      ## Final punctuation or word
+                                   ## boundary, capture it in $3
+               /ix
 
       #Two minutes of not saying anything in the channel counts as
       #idling, so don't pester when idling.
@@ -71,15 +83,28 @@
 
     my $lol = $1;
     my $midlol = $2;
+    my $endlol = $3;
     my $relol;
 
-    #Mimic long lols
-    if (length $lol > 3 ) {
+    #Mimic long lols, with same punctuation and capitalisation
+    if (length $lol > 3) {
+
+      ## Why can't I just plain index Perl strings like in Python?
+      ## Gotta turn them into arrays first. :-(
+      my @lol = split(//, $lol);
+      my @midlol = split(//, $midlol);
+
+      ## For maximum lolitude, randomly exaggerate long lols
       my $repeat_mid = int rand(3)+1;
-      $relol = "l".($midlol x $repeat_mid)."l";
+
+      $relol = $lol[0].$midlol[0];
+      for(my $i = 0; $i < $repeat_mid; $i++) {
+        $relol .= join("", @midlol[1..$#midlol]);
+      }
+      $relol .= $lol[$#lol].$endlol;
     }
     else {
-      $relol = $lol;
+      $relol = $lol.$endlol;
     }