annotate teh-lol.pl @ 9:037012a17457

An attempt to reset timestamps when manually lolling and change sleep with Xchat::hook_timer
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Mon, 24 May 2010 10:58:16 -0500
parents 2b8b0412096a
children c1bbeff37875
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
5
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
23 use Time::HiRes;
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
24
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
25 my %timestamp;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
26
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 sub update_tstamp{
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 if( $_[0][1] =~ /\b(lo+l)\b/i ){
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 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
30 $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
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 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
33 }
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
34
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
35 sub check_lol {
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
36 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
37 my $timesince_lasttalk = time - Xchat::user_info -> {'lasttalk'};
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
38
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
39 #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
40 #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
41 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
42
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
43 my $lol = $1;
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 my $relol;
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
46
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
47 #Mimic long lols
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
48 if (length $lol > 3 ) {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
49 my $numos = int rand(3);
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
50 $numos += 3;
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
51 $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
52 }
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
53 else {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
54 $relol = "lol";
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
55 }
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
56
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
57
8
2b8b0412096a Never lol more than once every 30 minutes.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 7
diff changeset
58 #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
59 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
60 undef $timestamp{$chan}
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
61 ) {
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
62
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
63 #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
64 #( theoros's algorithm from #not-math )
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
65 my $delay = 2.8;
5
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
66 if (length($relol) > 3){
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
67 $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
68 }
8f209cd0a7b6 Delay according to theoros's algorithm
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 4
diff changeset
69
7
65035a108782 Fix the call to usleep
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 6
diff changeset
70 #Convert to microseconds.
65035a108782 Fix the call to usleep
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 6
diff changeset
71 $delay *= 1e6;
65035a108782 Fix the call to usleep
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 6
diff changeset
72
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
73 Xchat::hook_timer($delay, sub { Xchat::command("say $relol"); });
3
6c34daa0afb0 Mimic lolling more subtly, delay lol reply
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 2
diff changeset
74 }
0
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
75 $timestamp{$chan} = time;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
76 }
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
77 return Xchat::EAT_NONE;
25377c6b6550 Per-channel timestamps
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
78 }