comparison teh-lol.pl @ 10:c1bbeff37875

Bugfixes to last commit
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Mon, 24 May 2010 11:27:19 -0500
parents 037012a17457
children 2f298f94a096
comparison
equal deleted inserted replaced
9:037012a17457 10:c1bbeff37875
18 Xchat::register('teh lol', '0.1.3', 'lols back'); 18 Xchat::register('teh lol', '0.1.3', 'lols back');
19 19
20 Xchat::hook_print('Channel Message', \&check_lol); 20 Xchat::hook_print('Channel Message', \&check_lol);
21 Xchat::hook_print('Your Message', \&update_tstamp); 21 Xchat::hook_print('Your Message', \&update_tstamp);
22 22
23 use Time::HiRes;
24
25 my %timestamp; 23 my %timestamp;
26 24
27 sub update_tstamp{ 25 sub update_tstamp{
28 if( $_[0][1] =~ /\b(lo+l)\b/i ){ 26 if( $_[0][1] eq "lol" ){
29 my $chan = Xchat::get_info("channel"); 27 my $chan = Xchat::get_info("channel");
30 $timestamp{$chan} = time; 28 $timestamp{$chan} = time;
31 } 29 }
32 return Xchat::EAT_NONE; 30 return Xchat::EAT_NONE;
33 } 31 }
60 undef $timestamp{$chan} 58 undef $timestamp{$chan}
61 ) { 59 ) {
62 60
63 #Delay the response a little, for maximum annoyance. 61 #Delay the response a little, for maximum annoyance.
64 #( theoros's algorithm from #not-math ) 62 #( theoros's algorithm from #not-math )
65 my $delay = 2.8; 63 my $delay = 1.8;
66 if (length($relol) > 3){ 64 if (length($relol) > 3){
67 $delay += ((length $relol) - 3 + rand(5)) * 0.069; 65 $delay += ((length $relol) - 3 + rand(5)) * 0.069;
68 } 66 }
69 67
70 #Convert to microseconds. 68 #Convert to milliseconds.
71 $delay *= 1e6; 69 $delay *= 1e3;
72 70
73 Xchat::hook_timer($delay, sub { Xchat::command("say $relol"); }); 71 Xchat::hook_timer($delay,
72 sub {
73 Xchat::command("say $relol");
74 return Xchat::REMOVE;
75 }
76 );
74 } 77 }
75 $timestamp{$chan} = time; 78 $timestamp{$chan} = time;
76 } 79 }
77 return Xchat::EAT_NONE; 80 return Xchat::EAT_NONE;
78 } 81 }