Software Freedom Law Center

root/trunk/antimatter/tim/Bot-BasicBot/examples/countdownbot.pl

Revision 53, 1.4 kB (checked in by bkuhn, 10 months ago)
  • Added SFLC's internally developed tim bot released under AGPLv3
Line 
1 =head1 NAME
2
3 countdownbot - a bot that will announce the time till an event
4
5 =head1 DESCRIPTION
6
7 This bot is incredibly annoying. Give it a date, and it'll periodically
8 announce how long until that date. I wrote this to annoy Arthur.
9
10 =cut
11
12 #!/usr/bin/perl
13 use warnings;
14 use strict;
15
16 # Create and run the bot
17
18 Bot->new(
19   channels => [ '#2lmc' ],
20   nick => 'countdownbot',
21   server => 'irc.london.pm.org',
22   date => 'Tue Jan  6 17:00:00 2004', # apple keynote Jan 2004
23 )->run;
24
25
26
27 # Here's the definition of the bot
28 package Bot;
29 use base qw(Bot::BasicBot);
30
31 use Date::Parse qw(str2time);
32 use Time::Duration;
33
34 # Called 5 seconds after bot startup, and then called again 'x' seconds
35 # later, where 'x' is whatever the function returns.
36 sub tick {
37   my $self = shift;
38
39   # How long till the event?
40   my $secs = Date::Parse::str2time($self->{date}) - time;
41
42   # What will we say?
43   my $body = ($secs > 0) ? from_now($secs) : "Why are you still here?";
44
45   # Say this thing in all our channels.
46   $self->say( channel => $_, body => $body )
47     for (@{$self->{channels}});
48
49   # Now, depending on how long is left, wait a different amount of
50   # time.
51   if      ($secs > 60 * 30) {
52     return 60 * 10
53   } elsif ( $secs > 60 * 10 ) {
54     return 60 * 5
55   } elsif ( $secs > 60 ) {
56     return 60
57   } elsif ( $secs > 10 ) {
58     return 10
59   } elsif ( $secs > 0 ) {
60     return 1
61   } else {
62     exit; # done.
63   }
64 }
65
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC