Software Freedom Law Center

root/trunk/antimatter/tim/Scripts/time-bot.plx

Revision 120, 4.1 kB (checked in by bkuhn, 6 months ago)

r161@hughes: bkuhn | 2008-06-02 13:30:50 -0400

  • Various minor changes to make bot work correctly on freenode
  • Property svn:executable set to
Line 
1 #!/usr/bin/perl -I ./Modules
2 # Copyright (C) 2005, 2006, 2007   Software Freedom Law Center, Inc.
3 #  Author: Bradley M. Kuhn <bkuhn@softwarefreedom.org>
4 #
5 #  This software gives you freedom; it is licensed to you under version
6 #  3 of the GNU Affero General Public License.
7 #
8 #  This software is distributed WITHOUT ANY WARRANTY, without even the
9 #  implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR
10 #  PURPOSE.  See the GNU Affero General Public License for further
11 #  details.
12 #
13 # You should have received a copy of the GNU Affero General Public
14 # License, version 3 along with this software.  If not, see
15 # <http://www.gnu.org/licenses/>.
16
17 # I hard coded this script to run out of the cwd.  This is for testing
18 # purposes and since Landon is replacing this, no worries.
19
20 unshift(@INC, "./Modules");
21
22 use strict;
23 use warnings;
24
25 use Bot::BasicBot::Time;
26
27 use Unix::Syslog qw(:subs);
28 use Unix::Syslog qw(:macros);
29 use Date::Manip;
30
31 my $PID_FILE = "time-bot.pid";
32
33 my $PAGE_EMAIL = 'page@example.org';
34
35 my @CHANNELS = ( { channel => "#antimatter"
36                    });
37 #                   password => 'PASS' });
38 ###############################################################################
39 {
40   my %messageHistory;
41
42   sub WarnLog ($$) {
43     my($now, $message) = @_;
44
45     syslog LOG_INFO, $message;
46
47     my $lastTime = $messageHistory{$message};
48
49     my $sendIt = 0;
50     if (not defined $lastTime) {
51       $sendIt = 1;
52     } else {
53       my $err;
54       my $sinceLast = DateCalc($lastTime,"+ 10 minutes",\$err);
55       $sendIt = 1 if ($now gt $sinceLast);
56     }
57     if ($sendIt) {
58       open(SENDMAIL, "|/usr/sbin/sendmail -f root\@example.org -t");
59       print SENDMAIL "To: $PAGE_EMAIL\nFrom: root\@example.org\n",
60       "Subject: IRC, TIME\n\n$message\n.\n";
61       close(SENDMAIL);
62       if ($? != 0) {
63         syslog LOG_INFO, "Unable to perform sendmail: $!";
64       } else {
65         $messageHistory{$message} = $now;
66       }
67     }
68   }
69 }
70 my($server, $channel, $nick) = ($ARGV[0], $ARGV[1], $ARGV[2]);
71
72 unless (defined $server and defined $channel) {
73   $server = "irc.freenode.net";
74   $channel = "#antimatter";
75 }
76 if ($channel ne "#antimatter") {
77   $channel = [ { channel => "#mainchannel" }];
78 #                                                password => 'PASS'
79 #                                                invite_nick => 'ChanServ'}];
80 } else {
81   $channel = [ { channel => "$channel" } ];
82 }
83 open(PASSWORD, "<./oldtimbot")
84   or die "unable to open password file: $!";
85 my(%passwords);
86 foreach my $line (<PASSWORD>) {
87   chomp $line;
88   next unless $line =~/^\s*(\S+)\s*:\s*(\S+)\s*$/;
89   $passwords{$1} = $2;
90 }
91 close PASSWORD;
92
93 die "Unable to find password in password file"
94   unless defined $passwords{nick_password};
95 #  and defined $passwords{server_password};
96
97 ###############################################################################
98
99 open(PID, ">$PID_FILE") or WarnLog(ParseDate("today"),
100                                    "unable to write to $PID_FILE: $!");
101 print PID "$$\n";
102 close PID;
103
104 my $dmv = DateManipVersion;
105 die "Bad DateManip Version is $dmv" unless $dmv =~ /^bkuhn/;
106
107 $nick = 'oldtimbot' if not defined $nick;
108          my $bot = Bot::BasicBot::Time->new(channels => $channel,
109                                    nick_password => $passwords{nick_password},
110                                            server => $server,
111                                            port   => "6667",
112                                            nick     => $nick,
113 #                                      password => $passwords{server_password},
114                                             ignore_list => [qw/LazyLuke/],
115                                            ssl   => 1,
116                                            username => "TimeTrack",
117                                            name     => "SFLC Time Tracking Bot",
118                                             dbPath => '.'
119                        );
120
121 $bot->run() or WarnLog(ParseDate("today"), "Bot POE died.");
122
123 ###############################################################################
124 #
125 # Local variables:
126 # compile-command: "perl -I../Modules -I ../Bot-BasicBot/lib -c time-bot.plx"
127 # End:
128
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC