view teh-lol.pl @ 11:2f298f94a096

Improve long lols, now "lolol" is supported.
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Wed, 24 Nov 2010 13:56:46 -0600
parents c1bbeff37875
children 826e099b4b7b
line wrap: on
line source

#Copyright © 2009 Jordi Gutiérrez Hermoso
#
#teh-lol.pl is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict;

Xchat::register('teh lol', '0.1.3', 'lols back');

Xchat::hook_print('Channel Message', \&check_lol);
Xchat::hook_print('Your Message', \&update_tstamp);

my %timestamp;

sub update_tstamp{
  if( $_[0][1] eq "lol" ){
    my $chan = Xchat::get_info("channel");
    $timestamp{$chan} = time;
  }
  return Xchat::EAT_NONE;
}

sub check_lol {
  my $chan = Xchat::get_info("channel");
  my $timesince_lasttalk = time - Xchat::user_info -> {'lasttalk'};

  if ($_[0][1] =~ /\b(l((o|(?<!l)lo)+)l)\b/i #Match stuff like "lol",
                                             #"loool" and "lololol"
      and $timesince_lasttalk < 120) {  #Two minutes of not saying
                                        #anything in the channel
                                        #counts as idling, so don't
                                        #pester when idling.

    my $lol = $1;
    my $midlol = $2;
    my $relol;

    #Mimic long lols
    if (length $lol > 3 ) {
      my $repeat_mid = int rand(3)+1;
      $relol = "l".($midlol x $repeat_mid)."l";
    }
    else {
      $relol = "lol";
    }


    #Don't lol more than once in 30 minutes.
    if ( time - $timestamp{$chan} > 1800 or
         undef $timestamp{$chan}
        ) {

      #Delay the response a little, for maximum annoyance.
      #( theoros's algorithm from #not-math )
      my $delay = 1.8;
      if (length($relol) > 3){
        $delay += ((length $relol) - 3 + rand(5)) * 0.069;
      }

      #Convert to milliseconds.
      $delay *= 1e3;

      Xchat::hook_timer($delay,
                        sub {
                          Xchat::command("say $relol");
                          return Xchat::REMOVE;
                        }
                        );
    }
    $timestamp{$chan} = time;
  }
  return Xchat::EAT_NONE;
}