annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
1 #Copyright © 2009 Jordi Gutiérrez Hermoso
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
2 #
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
3 #teh-lol.pl is free software: you can redistribute it and/or modify
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
4 #it under the terms of the GNU General Public License as published by
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
5 #the Free Software Foundation, either version 3 of the License, or
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
6 #(at your option) any later version.
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
7 #
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
8 #This program is distributed in the hope that it will be useful,
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
9 #but WITHOUT ANY WARRANTY; without even the implied warranty of
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
10 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
11 #GNU General Public License for more details.
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
12 #
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
13 #You should have received a copy of the GNU General Public License
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
14 #along with this program. If not, see <http://www.gnu.org/licenses/>.
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
15
6
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
16 use strict;
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
17
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
18 Xchat::register('teh lol', '0.1.3', 'lols back');
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
19
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
20 Xchat::hook_print('Channel Message', \&check_lol);
9
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
21 Xchat::hook_print('Your Message', \&update_tstamp);
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
22
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
23 my %timestamp;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
24
9
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
25 sub update_tstamp{
10
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
26 if( $_[0][1] eq "lol" ){
9
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
27 my $chan = Xchat::get_info("channel");
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
28 $timestamp{$chan} = time;
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
29 }
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
30 return Xchat::EAT_NONE;
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
31 }
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
32
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
33 sub check_lol {
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
34 my $chan = Xchat::get_info("channel");
6
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
35 my $timesince_lasttalk = time - Xchat::user_info -> {'lasttalk'};
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
36
9
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
37 #Two minutes of not saying anything in the channel counts as idling,
037012a17457 An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 8
diff changeset
38 #so don't pester when idling
6
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
39 if ($_[0][1] =~ /\b(lo+l)\b/i and $timesince_lasttalk < 120) {
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
40
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
41 my $lol = $1;
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
42
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
43 my $relol;
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
44
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
45 #Mimic long lols
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
46 if (length $lol > 3 ) {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
47 my $numos = int rand(3);
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
48 $numos += 3;
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
49 $relol = "l".("o" x $numos)."l";
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
50 }
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
51 else {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
52 $relol = "lol";
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
53 }
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
54
6
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
55
8
2b8b0412096a Never lol more than once every 30 minutes.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 7
diff changeset
56 #Don't lol more than once in 30 minutes.
2b8b0412096a Never lol more than once every 30 minutes.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 7
diff changeset
57 if ( time - $timestamp{$chan} > 1800 or
6
6999ba7bf22b Don't relol while idling (2 minutes of not participating in discussion)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 5
diff changeset
58 undef $timestamp{$chan}
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
59 ) {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
60
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
61 #Delay the response a little, for maximum annoyance.
5
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
62 #( theoros's algorithm from #not-math )
10
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
63 my $delay = 1.8;
5
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
64 if (length($relol) > 3){
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
65 $delay += ((length $relol) - 3 + rand(5)) * 0.069;
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
66 }
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
67
10
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
68 #Convert to milliseconds.
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
69 $delay *= 1e3;
7
65035a108782 Fix the call to usleep
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 6
diff changeset
70
10
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
71 Xchat::hook_timer($delay,
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
72 sub {
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
73 Xchat::command("say $relol");
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
74 return Xchat::REMOVE;
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
75 }
c1bbeff37875 Bugfixes to last commit
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 9
diff changeset
76 );
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
77 }
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
78 $timestamp{$chan} = time;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
79 }
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
80 return Xchat::EAT_NONE;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
81 }