Software Freedom Law Center

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

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

SFLC Main Page

[frdm] Support SFLC