1998-10-17 01:54:40 +00:00
|
|
|
#!/usr/bonsaitools/bin/perl5 -w
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-01 23:33:56 +00:00
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
1998-10-17 01:54:40 +00:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-01 23:33:56 +00:00
|
|
|
#
|
1998-10-17 01:54:40 +00:00
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-01 23:33:56 +00:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
1998-10-17 01:54:40 +00:00
|
|
|
# Contributor(s): Harrison Page <harrison@netscape.com>
|
|
|
|
# Terry Weissman <terry@mozilla.org>
|
2000-01-30 08:42:28 +00:00
|
|
|
# Risto Kotalampi <risto@kotalampi.com>
|
1998-10-17 01:54:40 +00:00
|
|
|
#
|
|
|
|
# mozbot.pl harrison@netscape.com 10/14/98
|
|
|
|
# "irc bot for the gang on #mozilla"
|
|
|
|
#
|
|
|
|
# features: reports tinderbox status upon request.
|
|
|
|
# remembers urls. tells you the phase of the moon.
|
1998-10-29 11:01:29 +00:00
|
|
|
# grabs mozillaZine headlines. fetches slashdot.org
|
|
|
|
# news. bot will auto-op based on nick and remote host.
|
1998-10-17 01:54:40 +00:00
|
|
|
#
|
|
|
|
# hack on me! required reading:
|
|
|
|
#
|
|
|
|
# Net::IRC web page:
|
|
|
|
# http://netirc.betterbox.net/
|
|
|
|
# (free software)
|
|
|
|
# or get it from CPAN @ http://www.perl.com/CPAN
|
|
|
|
#
|
|
|
|
# RFC 1459 (Internet Relay Chat Protocol):
|
|
|
|
# http://sunsite.cnlab-switch.ch/ftp/doc/standard/rfc/14xx/1459
|
|
|
|
|
|
|
|
|
|
|
|
$SIG{'INT'} = 'killed';
|
|
|
|
$SIG{'KILL'} = 'killed';
|
|
|
|
$SIG{'TERM'} = 'killed';
|
|
|
|
|
1998-10-22 22:01:42 +00:00
|
|
|
use strict;
|
|
|
|
use diagnostics;
|
1998-10-17 01:54:40 +00:00
|
|
|
use lib ".";
|
|
|
|
use Net::IRC;
|
1998-10-22 02:45:27 +00:00
|
|
|
use LWP::Simple;
|
1998-10-17 01:54:40 +00:00
|
|
|
use Tinderbox;
|
|
|
|
use Carp;
|
1998-11-06 20:53:22 +00:00
|
|
|
use Chatbot::Eliza;
|
1999-08-13 00:21:01 +00:00
|
|
|
use babel;
|
1999-10-12 22:34:49 +00:00
|
|
|
use IPC::Open2;
|
|
|
|
use FileHandle;
|
2000-04-18 17:59:50 +00:00
|
|
|
use Net::FTP;
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
$|++;
|
|
|
|
|
2000-04-21 23:47:20 +00:00
|
|
|
my $VERSION = "1.65"; # keep me in sync with the mozilla.org cvs repository
|
1998-10-22 02:45:27 +00:00
|
|
|
my $debug = 1; # debug output also includes warnings, errors
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
my %msgcmds = (
|
|
|
|
"url" => \&bot_urls,
|
1999-09-24 18:19:01 +00:00
|
|
|
"(stocks|stock)" => \&bot_stocks,
|
1998-10-29 18:59:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %pubcmds = (
|
|
|
|
"(help|about)" => \&bot_about,
|
|
|
|
"(hi|hello|lo|sup)" => \&bot_hi,
|
|
|
|
"moon" => \&bot_moon,
|
1999-08-25 16:39:01 +00:00
|
|
|
"uuid" => \&bot_uuid,
|
1998-10-29 18:59:22 +00:00
|
|
|
"up" => \&bot_up,
|
1999-05-21 00:42:55 +00:00
|
|
|
"(trees|tree)" => \&bot_tinderbox,
|
1998-12-31 18:38:54 +00:00
|
|
|
"debug" => \&bot_debug,
|
1999-09-24 18:19:01 +00:00
|
|
|
"(stocks|stock)" => \&bot_pub_stocks,
|
1999-08-13 00:21:01 +00:00
|
|
|
"(translate|xlate|x)" => \&bot_translate,
|
1999-10-26 15:48:25 +00:00
|
|
|
"review" => \&bot_review,
|
2000-04-18 17:59:50 +00:00
|
|
|
"ftp" => \&ftp_stamp
|
1998-10-29 18:59:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %admincmds = (
|
|
|
|
"bless" => \&bot_bless,
|
|
|
|
"unbless" => \&bot_unbless,
|
|
|
|
"shutdown" => \&bot_shutdown,
|
|
|
|
"say" => \&bot_say,
|
|
|
|
"list" => \&bot_list,
|
2000-04-18 17:59:50 +00:00
|
|
|
"ftpx" => \&ftp_check,
|
|
|
|
"ftpc" => \&ftp_clear
|
1998-10-29 18:59:22 +00:00
|
|
|
);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
my %rdfcmds = (
|
|
|
|
"(slashdot|sd|\/\.)" => "http://www.slashdot.org/slashdot.rdf",
|
|
|
|
"(mozillaorg|mozilla|mo)" => "http://www.mozilla.org/news.rdf",
|
|
|
|
"(newsbot|nb)" => "http://www.mozilla.org/newsbot/newsbot.rdf",
|
|
|
|
"(xptoolkit|xpfe)" => "http://www.mozilla.org/xpfe/toolkit.rdf",
|
1999-11-11 00:55:49 +00:00
|
|
|
"(freshmeat|fm)" => "http://freshmeat.net/backend/fm.rdf",
|
1999-03-30 01:55:38 +00:00
|
|
|
"(mozillazine|zine|mz)" => "http://www.mozillazine.org/contents.rdf",
|
1999-03-30 01:02:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my %rdf_title;
|
|
|
|
my %rdf_link;
|
|
|
|
my %rdf_last;
|
|
|
|
my %rdf_items;
|
2000-04-18 17:59:50 +00:00
|
|
|
my %latestbuilds;
|
|
|
|
my $ftpscanned = 0;
|
1999-03-30 01:02:30 +00:00
|
|
|
|
1998-10-17 02:50:48 +00:00
|
|
|
@::origargv = @ARGV;
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
my $server = shift;
|
|
|
|
my $port = shift;
|
|
|
|
my $nick = shift;
|
|
|
|
my $channel = shift;
|
|
|
|
|
1999-01-07 22:33:01 +00:00
|
|
|
my $stockf = "stocklist";
|
|
|
|
my %stocklist = ();
|
|
|
|
my %stockvals = ();
|
|
|
|
my %stockhist;
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
$server = $server || "irc.mozilla.org";
|
|
|
|
$port = $port || "6667";
|
|
|
|
$nick = $nick || "mozbot";
|
|
|
|
$channel = $channel || "#mozilla";
|
|
|
|
|
1999-03-05 06:28:58 +00:00
|
|
|
&debug ("mozbot $VERSION starting up");
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1999-01-07 22:42:42 +00:00
|
|
|
LoadStockList();
|
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
&create_pid_file;
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
# read admin list
|
2000-01-30 13:24:49 +00:00
|
|
|
my %admins = ( "rko" => "netscape.com", "cyeh" => "netscape.com", "terry" => "netscape.com" );
|
1999-09-15 16:24:37 +00:00
|
|
|
my $adminf = ".$nick-admins";
|
1998-10-22 02:45:27 +00:00
|
|
|
&fetch_admin_conf (\%admins);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
my $uptime = 0;
|
|
|
|
|
1998-10-22 22:01:42 +00:00
|
|
|
$::moon = "./moon";
|
|
|
|
$::moon = (-f $::moon) ? $::moon : "";
|
1998-10-29 18:59:22 +00:00
|
|
|
delete $pubcmds{'moon'} if (! $::moon);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1999-08-25 16:39:01 +00:00
|
|
|
$::uuid = "./uuidgen/uuidgen";
|
|
|
|
$::uuid = (-f $::uuid) ? $::uuid : "";
|
|
|
|
delete $pubcmds{'uuid'} if (! $::uuid);
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
my $phase;
|
1998-10-22 02:45:27 +00:00
|
|
|
my $last_moon = 0;
|
1999-08-25 16:39:01 +00:00
|
|
|
my $last_uuid = 0;
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
# leave @trees empty if you don't want tinderbox details
|
2000-04-21 23:47:20 +00:00
|
|
|
# @all_trees must be a superset of @trees
|
1998-10-17 01:54:40 +00:00
|
|
|
|
2000-04-21 23:47:20 +00:00
|
|
|
my @all_trees = qw (SeaMonkey SeaMonkey-Ports);
|
2000-04-21 01:07:38 +00:00
|
|
|
my @trees = qw (SeaMonkey);
|
1999-03-17 19:36:11 +00:00
|
|
|
if ($nick =~ /grend/) {
|
|
|
|
@trees = qw (Grendel);
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
my $trees;
|
1998-10-22 02:45:27 +00:00
|
|
|
my $status;
|
1998-10-17 01:54:40 +00:00
|
|
|
my $last_tree;
|
|
|
|
my %broken;
|
|
|
|
my @urls;
|
2000-04-18 17:59:50 +00:00
|
|
|
my $ftpsite="ftp.mozilla.org";
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
my $greet = 0;
|
|
|
|
my @greetings =
|
|
|
|
(
|
2000-01-03 19:38:08 +00:00
|
|
|
"g'day", "bonjour", "guten tag", "konnichiwa",
|
1998-12-31 23:29:48 +00:00
|
|
|
"hello", "hola", "hi", "buono giorno", "aloha",
|
1998-10-22 02:45:27 +00:00
|
|
|
"hey", "'sup", "lo", "howdy", "saluton", "hei",
|
1998-12-31 23:29:48 +00:00
|
|
|
"hallo", "word", "yo yo yo", "rheeet", "bom dia",
|
|
|
|
"ciao"
|
1998-10-22 02:45:27 +00:00
|
|
|
);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-12-31 18:38:54 +00:00
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
my $irc = new Net::IRC or confess "$0: duh?";
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
my $bot = $irc->newconn
|
|
|
|
(
|
|
|
|
Server => $server,
|
|
|
|
Port => $port,
|
|
|
|
Nick => $nick,
|
1998-10-22 02:45:27 +00:00
|
|
|
Ircname => "mozilla.org bot/thing $VERSION",
|
1998-10-17 01:54:40 +00:00
|
|
|
Username => $nick,
|
|
|
|
)
|
|
|
|
or die "$0: can't connect to $server, port $port";
|
|
|
|
|
|
|
|
&debug ("adding global handlers");
|
|
|
|
$bot->add_global_handler ([ 251,252,253,254,302,255 ], \&on_startup);
|
|
|
|
$bot->add_global_handler (376, \&on_connect);
|
|
|
|
$bot->add_global_handler (433, \&on_nick_taken);
|
|
|
|
$bot->add_global_handler ([ 'disconnect', 'kill', 474, 465 ], \&on_boot);
|
|
|
|
|
|
|
|
&debug ("adding more handlers");
|
|
|
|
$bot->add_handler ('msg', \&on_msg);
|
1998-10-22 02:45:27 +00:00
|
|
|
$bot->add_handler ('public', \&on_public);
|
|
|
|
$bot->add_handler ('join', \&on_join);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
&debug ("scheduling stuff");
|
1998-10-17 01:54:40 +00:00
|
|
|
$bot->schedule (0, \&tinderbox);
|
1998-10-17 02:50:48 +00:00
|
|
|
$bot->schedule (0, \&checksourcechange);
|
1999-01-07 22:33:01 +00:00
|
|
|
$bot->schedule (0, \&stocks);
|
2000-04-18 17:59:50 +00:00
|
|
|
$bot->schedule (0, \&ftp_scan);
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
foreach my $i (keys %rdfcmds) {
|
|
|
|
$bot->schedule(0, \&rdfchannel, $rdfcmds{$i});
|
|
|
|
$pubcmds{$i} = $rdfcmds{$i};
|
|
|
|
}
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
&debug ("connecting to $server $port as $nick on $channel");
|
|
|
|
|
1999-10-14 00:44:37 +00:00
|
|
|
$::megahal = "./megahal/megahal";
|
|
|
|
$::megahal = (-f $::megahal) ? $::megahal : "";
|
2000-04-18 17:59:50 +00:00
|
|
|
#david: why does the following line need to be commented out?
|
|
|
|
#$::megahal_pid;
|
1999-10-14 00:44:37 +00:00
|
|
|
|
|
|
|
if ($::megahal) {
|
|
|
|
$::WTR = FileHandle->new;
|
|
|
|
$::RDR = FileHandle->new;
|
|
|
|
$::megahal_pid = &init_megahal;
|
|
|
|
&debug ("Initializing MEGAHAL conversation AI\n");
|
|
|
|
}
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
# and done.
|
|
|
|
|
1999-03-30 04:50:31 +00:00
|
|
|
|
|
|
|
# Use this routine, always, instead of the standard "privmsg" routine. This
|
|
|
|
# one makes sure we don't send more than one message every two seconds or so,
|
|
|
|
# which will make servers not whine about us flooding the channel.
|
|
|
|
#
|
|
|
|
# Actually, it seems that we can send two in a row just fine, but at that
|
|
|
|
# point we should start throttling.
|
|
|
|
|
|
|
|
my $lastsenttime = 0;
|
|
|
|
my @msgqueue = ();
|
|
|
|
sub sendmsg {
|
|
|
|
my ($who, $msg) = (@_);
|
|
|
|
my $now = time();
|
|
|
|
if ($now > $lastsenttime && 0 == @msgqueue) {
|
|
|
|
$bot->privmsg($who, $msg);
|
|
|
|
$lastsenttime = $now;
|
|
|
|
} else {
|
|
|
|
push(@msgqueue, [$who, $msg]);
|
|
|
|
if (1 == @msgqueue) {
|
|
|
|
$bot->schedule(0, \&drainmsgqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub drainmsgqueue {
|
|
|
|
if (0 < @msgqueue) {
|
|
|
|
my ($who, $msg) = (@{shift(@msgqueue)});
|
|
|
|
$bot->privmsg($who, $msg);
|
|
|
|
$lastsenttime = time();
|
|
|
|
if (0 < @msgqueue) {
|
|
|
|
$bot->schedule(2, \&drainmsgqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
################################
|
|
|
|
# Net::IRC handler subroutines #
|
|
|
|
################################
|
|
|
|
|
|
|
|
sub on_startup
|
|
|
|
{
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
my (@args) = ($event->args);
|
|
|
|
shift (@args);
|
|
|
|
|
|
|
|
&debug ("@args\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_connect
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
&debug ("startup took " . (time - $^T) . " seconds");
|
|
|
|
|
|
|
|
$self->join ($channel);
|
|
|
|
|
|
|
|
$uptime = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
# on_nick_taken: or do something smarter
|
|
|
|
|
|
|
|
sub on_nick_taken
|
|
|
|
{
|
|
|
|
die "hey! somebody took my nick!";
|
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
sub do_command {
|
|
|
|
my ($hashref, $nick, $cmd, $rest) = (@_);
|
|
|
|
foreach my $m (keys %$hashref) {
|
|
|
|
if ($cmd =~ m/^$m$/) {
|
1999-03-30 01:02:30 +00:00
|
|
|
my $ref = $hashref->{$m};
|
|
|
|
if (ref($ref)) {
|
|
|
|
&{$ref} ($nick, $cmd, $rest);
|
|
|
|
} else {
|
|
|
|
bot_rdfchannel($nick, $cmd, $rest, $ref);
|
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
# on_msg: private message received via /msg
|
|
|
|
|
1998-11-06 20:53:22 +00:00
|
|
|
sub on_msg {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
my ($nick) = $event->nick;
|
|
|
|
my ($arg) = $event->args;
|
1998-10-29 18:59:22 +00:00
|
|
|
my @arglist = split(' ', $arg);
|
|
|
|
my $cmd = shift @arglist;
|
|
|
|
my $rest = join(' ', @arglist);
|
|
|
|
$::speaker = $nick; # Hack!!!
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-29 16:56:30 +00:00
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
if (exists $admins{$nick}) {
|
|
|
|
if (do_command(\%admincmds, $nick, $cmd, $rest)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-09-24 18:19:01 +00:00
|
|
|
if (do_command(\%msgcmds, $nick, $cmd, $rest)) {
|
1998-10-29 18:59:22 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-09-24 18:19:01 +00:00
|
|
|
if (do_command(\%pubcmds, $nick, $cmd, $rest)) {
|
1998-11-06 20:53:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
do_unknown($nick, $cmd, $rest);
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
1998-10-29 16:56:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_bless {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
my ($who, $where) = split(' ', $rest);
|
|
|
|
if (! $who or ! $where) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "usage: bless [ user ] [ host ] " .
|
|
|
|
"(example: bless marca netscape.com)");
|
1998-10-29 18:59:22 +00:00
|
|
|
return;
|
1998-10-29 16:56:30 +00:00
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
$admins{$who} = $where;
|
|
|
|
&debug ("$nick blessed $who ($where)");
|
|
|
|
&store_admin_conf (\%admins);
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "mozbot admins: " . join ' ', (sort keys %admins));
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
2000-04-18 17:59:50 +00:00
|
|
|
sub ftp_clear {
|
|
|
|
%latestbuilds=();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub ftp_stamp {
|
|
|
|
my $nick=$_[0];
|
|
|
|
my $msg = "Available from $ftpsite: " .
|
|
|
|
join(' ', sort(keys(%latestbuilds)));
|
|
|
|
saylongline($nick, $msg, " ... ");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub ftp_check {
|
|
|
|
my $nick=($_[0])?$_[0]:$channel;
|
|
|
|
my $buf="";
|
|
|
|
my $mdtms;
|
|
|
|
my $ftpserver=($_[2])?$_[2]:$ftpsite;
|
|
|
|
my $ftp = new Net::FTP($ftpserver, Debug => 0);
|
|
|
|
&debug ("fetching FTP $ftpserver nightly/latest");
|
|
|
|
if ($ftp->login("anonymous","mozbot\@localhost")){
|
|
|
|
$ftp->cwd("/pub/mozilla/nightly/latest");
|
|
|
|
for my $f ($ftp->ls){
|
|
|
|
$mdtms=$ftp->mdtm($f);
|
|
|
|
if (!$latestbuilds{$f} || $mdtms>$latestbuilds{$f}) {
|
|
|
|
$buf.=$f."; ";
|
|
|
|
$latestbuilds{$f}=$mdtms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ftp->quit;
|
|
|
|
};
|
|
|
|
$buf="New files @ ftp://$ftpserver/pub/mozilla/nightly/latest ".$buf if ($buf);
|
|
|
|
&debug("$nick $buf");
|
|
|
|
if ($ftpscanned) {
|
|
|
|
sendmsg($nick, $buf);
|
|
|
|
}
|
|
|
|
$ftpscanned = 1;
|
|
|
|
}
|
|
|
|
#DBM or DB_File %hash that's tied to a file
|
|
|
|
#DBM and DB_File are documented on the
|
|
|
|
# http://www.perl.com/CPAN-local/doc/manual/html/lib/ page.
|
|
|
|
# (note there are several DBM links there so be sure to check each
|
|
|
|
# (= exhaustive look not brief look))
|
|
|
|
# timeless believes ftp info doesn't need to persist across multiple sessions
|
|
|
|
# of mozbot
|
|
|
|
# Lots of help from
|
|
|
|
|
|
|
|
sub ftp_scan{
|
|
|
|
ftp_check(0);
|
|
|
|
$bot->schedule(300,\&ftp_scan);
|
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_unbless {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
my ($who) = ($rest);
|
|
|
|
if (exists ($admins{$who})) {
|
|
|
|
delete $admins{$who};
|
|
|
|
&debug ("$nick unblessed $who");
|
|
|
|
&store_admin_conf (\%admins);
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "mozbot admins: " . join ' ', (sort keys %admins));
|
1998-10-29 18:59:22 +00:00
|
|
|
return;
|
1998-10-29 16:56:30 +00:00
|
|
|
}
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "Can only unbless one of: " .
|
|
|
|
join(' ', (sort keys %admins)));
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub bot_shutdown {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
if ($rest ne "yes") {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "usage: shutdown yes");
|
1998-10-29 18:59:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
&debug ("forced shutdown from $nick");
|
|
|
|
$::dontQuitOnSignal++;
|
|
|
|
$bot->quit ("$nick told me to shutdown");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub bot_say {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
my $text = $rest;
|
|
|
|
if ($text =~ m@^/me (.*)@) {
|
|
|
|
$bot->me($channel, $1);
|
1998-10-29 16:56:30 +00:00
|
|
|
} else {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($channel, $text);
|
1998-10-29 16:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_list {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
1999-03-30 04:59:38 +00:00
|
|
|
my @list;
|
1998-10-29 18:59:22 +00:00
|
|
|
foreach (sort keys %admins) {
|
1999-03-30 04:59:38 +00:00
|
|
|
push(@list, "$_ $admins{$_}");
|
1998-10-29 16:56:30 +00:00
|
|
|
}
|
1999-03-30 04:59:38 +00:00
|
|
|
my $spacer = " ... ";
|
|
|
|
saylongline($nick, join($spacer, @list), $spacer);
|
1998-10-29 16:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub on_public {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
my ($to) = $event->to;
|
1998-10-17 01:54:40 +00:00
|
|
|
my ($arg) = $event->args;
|
|
|
|
my ($nick, $me) = ($event->nick, $self->nick);
|
1998-10-29 18:59:22 +00:00
|
|
|
$::speaker = $nick; # Hack!!!
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
# catch urls, stick them in a list for mozbot's url command
|
|
|
|
|
|
|
|
if ($arg =~ /(http|ftp|gopher):/i && $nick ne $me) {
|
|
|
|
push @urls, "$arg (" . &logdate() . ")";
|
|
|
|
while ($#urls > 10) {
|
|
|
|
shift @urls;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (my ($cmd, $rest) = $arg =~ /^$me[:,]?\s+(\S+)(?:\s+(.*))?$/i) {
|
|
|
|
if (do_command(\%pubcmds, $channel, $cmd, $rest)) {
|
|
|
|
return;
|
|
|
|
} else {
|
1998-11-06 20:53:22 +00:00
|
|
|
do_unknown($channel, $cmd, $rest);
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
|
1998-11-06 20:53:22 +00:00
|
|
|
sub do_unknown {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
1999-10-12 22:34:49 +00:00
|
|
|
if (defined $::megahal_pid) {
|
|
|
|
my $sentence = $cmd . " " . $rest . "\n";
|
|
|
|
&debug($sentence);
|
|
|
|
print $::WTR $sentence . "\n";
|
|
|
|
my $result = ($::RDR)->getline;
|
|
|
|
&debug($result . "\n");
|
|
|
|
sendmsg($nick, $result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!defined $::eliza) {
|
|
|
|
$::eliza = new Chatbot::Eliza;
|
|
|
|
}
|
|
|
|
my $result = $::eliza->transform("$cmd $rest");
|
|
|
|
sendmsg($nick, $result);
|
1998-11-06 20:53:22 +00:00
|
|
|
}
|
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub saylongline {
|
|
|
|
my ($nick, $str, $spacer) = (@_);
|
|
|
|
my $MAXPROTOCOLLENGTH = 255;
|
1998-12-31 18:38:54 +00:00
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
while (length ($str) > $MAXPROTOCOLLENGTH) {
|
|
|
|
my $pos;
|
|
|
|
$pos = rindex($str, $spacer, $MAXPROTOCOLLENGTH - length($spacer));
|
|
|
|
if ($pos < 0) {
|
|
|
|
$pos = rindex($str, " ", $MAXPROTOCOLLENGTH - 1);
|
|
|
|
if ($pos < 0) {
|
|
|
|
$pos = $MAXPROTOCOLLENGTH - 1;
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, substr($str, 0, $pos));
|
1998-10-29 18:59:22 +00:00
|
|
|
$str = substr($str, $pos);
|
|
|
|
if (index($str, $spacer) == 0) {
|
|
|
|
$str = substr($str, length($spacer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($str ne "") {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, $str);
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub do_headlines {
|
|
|
|
my ($nick, $header, $ref) = (@_);
|
|
|
|
my $spacer = " ... ";
|
|
|
|
my $str = $header . ": " . join($spacer, @$ref);
|
|
|
|
saylongline($nick, $str, $spacer);
|
|
|
|
}
|
1998-12-31 18:38:54 +00:00
|
|
|
|
|
|
|
sub reportDiffs {
|
|
|
|
my ($name, $url, $ref) = (@_);
|
|
|
|
|
|
|
|
my $firsttime = 0;
|
1999-03-30 01:02:30 +00:00
|
|
|
if (!exists $::headCache{$url}) {
|
1998-12-31 18:38:54 +00:00
|
|
|
$firsttime = 1;
|
1999-03-30 01:02:30 +00:00
|
|
|
$::headCache{$url} = {};
|
1998-12-31 18:38:54 +00:00
|
|
|
}
|
|
|
|
my $spacer = " ... ";
|
|
|
|
my $outstr = "";
|
|
|
|
foreach my $i (@$ref) {
|
|
|
|
if ($i =~ /^last update/) {
|
|
|
|
next;
|
|
|
|
}
|
1999-03-30 01:02:30 +00:00
|
|
|
if (!exists $::headCache{$url}->{$i}) {
|
|
|
|
$::headCache{$url}->{$i} = 1;
|
1998-12-31 18:38:54 +00:00
|
|
|
if ($outstr eq "") {
|
2000-04-18 17:59:50 +00:00
|
|
|
$outstr = "Just appeared in $name - $url : ";
|
1998-12-31 18:38:54 +00:00
|
|
|
} else {
|
|
|
|
$outstr .= $spacer;
|
|
|
|
}
|
|
|
|
$outstr .= $i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$firsttime) {
|
|
|
|
saylongline($channel, $outstr, $spacer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
1998-11-04 01:19:08 +00:00
|
|
|
sub bot_debug
|
|
|
|
{
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
|
|
|
|
my @list;
|
|
|
|
my %last =
|
|
|
|
(
|
|
|
|
"tinderbox" => $last_tree,
|
|
|
|
"moon" => $last_moon,
|
1999-08-25 16:39:01 +00:00
|
|
|
"uuid" => $last_uuid,
|
1998-11-04 01:19:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach (keys %last)
|
|
|
|
{
|
|
|
|
if ($last{$_} != 0)
|
|
|
|
{
|
|
|
|
push @list, "$_ updated: " . &logdate ($last{$_}) . ", " .
|
|
|
|
&days ($last{$_});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push @list, "$_ never updated!";
|
|
|
|
}
|
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
foreach (sort(keys %rdf_last)) {
|
|
|
|
push @list, "$_ updated: " . logdate($rdf_last{$_}) . ", " .
|
|
|
|
days($rdf_last{$_});
|
|
|
|
}
|
|
|
|
|
1998-11-04 01:19:08 +00:00
|
|
|
do_headlines ($nick, "Boring Debug Information", \@list);
|
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
|
2000-04-18 17:59:50 +00:00
|
|
|
#timeless didn't like http://server): it upset his irc client/browser link
|
1999-03-30 01:02:30 +00:00
|
|
|
sub bot_rdfchannel {
|
|
|
|
my ($nick, $cmd, $rest, $url) = (@_);
|
|
|
|
if (defined $rdf_title{$url}) {
|
2000-04-18 17:59:50 +00:00
|
|
|
do_headlines($nick, "Items in $rdf_title{$url} - $rdf_link{$url} ",
|
1999-03-30 01:02:30 +00:00
|
|
|
$rdf_items{$url});
|
|
|
|
} else {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "Nothing has been found yet at $url");
|
1999-03-30 01:02:30 +00:00
|
|
|
}
|
1999-01-07 23:21:44 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub bot_hi {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, $greetings[$greet++] . " $::speaker");
|
1998-10-29 18:59:22 +00:00
|
|
|
$greet = 0 if ($greet > $#greetings);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
sub on_join
|
|
|
|
{
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
my ($channel) = ($event->to)[0];
|
|
|
|
my $nick = $event->nick;
|
|
|
|
my $userhost = $event->userhost;
|
|
|
|
|
|
|
|
# auto-op if user is a mozbot admin and coming in from
|
|
|
|
# the right host
|
|
|
|
|
|
|
|
if (exists $admins{$nick} && $userhost =~ /$admins{$nick}$/i)
|
|
|
|
{
|
|
|
|
$self->mode ($channel, "+o", $nick);
|
|
|
|
&debug ("auto-op for $nick on $channel");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-17 02:50:48 +00:00
|
|
|
$::dontQuitOnSignal = 0;
|
1998-10-17 01:54:40 +00:00
|
|
|
sub on_boot
|
|
|
|
{
|
1998-10-17 03:06:52 +00:00
|
|
|
if (!$::dontQuitOnSignal) {
|
|
|
|
die "$0: disconnected from network";
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
sub listcmds {
|
|
|
|
my ($hashref) = (@_);
|
|
|
|
my @list;
|
|
|
|
foreach my $k (keys %$hashref) {
|
|
|
|
if ($k =~ m/^\(([a-z]+)\|/) {
|
|
|
|
push @list, $1;
|
|
|
|
} else {
|
|
|
|
push @list, $k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return join(' ', sort(@list));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
################
|
|
|
|
# bot commands #
|
|
|
|
################
|
|
|
|
|
|
|
|
# bot_about: it's either an about box or the
|
|
|
|
# address of the guy to blame when the bot
|
|
|
|
# breaks
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_about {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($::speaker, "i am mozbot version $VERSION. hack on me! " .
|
1998-10-22 02:45:27 +00:00
|
|
|
"harrison\@netscape.com 10/16/98. " .
|
1998-10-17 01:54:40 +00:00
|
|
|
"connected to $server since " .
|
1998-10-29 18:59:22 +00:00
|
|
|
&logdate ($uptime) . " (" . &days ($uptime) . "). " .
|
2000-01-30 08:42:28 +00:00
|
|
|
"see http://bonsai.mozilla.org/cvsquery.cgi?branch=HEAD&file=mozilla/webtools/mozbot/&date=week " .
|
1998-10-29 18:59:22 +00:00
|
|
|
"for a changelog.");
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($::speaker, "Known commands are: " .
|
|
|
|
listcmds(\%pubcmds));
|
|
|
|
sendmsg($::speaker, "If you /msg me, I'll also respond to: " .
|
|
|
|
listcmds(\%msgcmds));
|
1998-10-29 18:59:22 +00:00
|
|
|
if (exists $admins{$::speaker}) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($::speaker, "And you're an admin, so you can also do: " .
|
|
|
|
listcmds(\%admincmds));
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
if ($nick eq $channel) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick,
|
|
|
|
"[ Directions on talking to me have been sent to $::speaker ]");
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
# bot_moon: goodnight moon
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub get_moon_str
|
1998-10-17 01:54:40 +00:00
|
|
|
{
|
|
|
|
return "- no moon -" if (! defined $::moon);
|
|
|
|
return $phase if ($phase && (time - $last_moon > (60 * 60 * 24)));
|
|
|
|
|
|
|
|
# we only want to run this once/day
|
|
|
|
$phase = `$::moon`;
|
|
|
|
$last_moon = time;
|
|
|
|
return $phase;
|
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_moon {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, get_moon_str());
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
1999-08-25 16:39:01 +00:00
|
|
|
sub get_uuid_str {
|
|
|
|
my $this_uuid;
|
|
|
|
return "- no uuid -" if (! defined $::uuid);
|
|
|
|
$this_uuid = `$::uuid`;
|
|
|
|
return $this_uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bot_uuid {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
|
|
|
sendmsg($nick, get_uuid_str());
|
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
# bot_up: report uptime
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_up {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, &logdate ($uptime) . " (" . &days ($uptime) . ")");
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
# bot_urls: show last ten urls caught by mozbot
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_urls {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
|
|
|
if ($#urls == -1) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "- mozbot has seen no URLs yet -");
|
1998-10-29 18:59:22 +00:00
|
|
|
} else {
|
|
|
|
foreach my $m (@urls) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, $m);
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
# show tinderbox status
|
|
|
|
#
|
|
|
|
# this is a messy little function but it works.
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
sub bot_tinderbox {
|
|
|
|
my ($nick, $cmd, $rest) = @_;
|
1998-10-17 01:54:40 +00:00
|
|
|
my $bustage;
|
|
|
|
my $buf;
|
|
|
|
my @buf;
|
|
|
|
my @tree;
|
2000-04-18 17:59:50 +00:00
|
|
|
# my @rstats;
|
|
|
|
# my $ttree;
|
|
|
|
my $rg=0;
|
|
|
|
my $ry=0;
|
|
|
|
my $rr=0;
|
1998-10-29 18:59:22 +00:00
|
|
|
my $terse = (defined $rest && $rest eq "all");
|
|
|
|
if ($nick eq $channel) {
|
|
|
|
$terse = 1;
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
# user can supply a list of trees separated
|
|
|
|
# by whitespace, default is all trees
|
|
|
|
|
|
|
|
push @tree, $rest ? (split /\s+/, $rest) : @trees;
|
|
|
|
|
|
|
|
# loop through requested trees
|
|
|
|
|
2000-01-30 08:42:28 +00:00
|
|
|
push @buf, "Tinderbox status from http://tinderbox.mozilla.org/showbuilds.cgi";
|
1998-10-22 22:01:42 +00:00
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
foreach my $t (@tree)
|
|
|
|
{
|
|
|
|
$bustage = 0;
|
1998-10-22 02:45:27 +00:00
|
|
|
$buf = "$t " . ($$status{$t} ? "<$$status{$t}> " : "") . ": ";
|
1998-10-17 01:54:40 +00:00
|
|
|
# politely report failures
|
2000-04-21 18:59:16 +00:00
|
|
|
if (! exists $$trees{$t})
|
1998-10-17 01:54:40 +00:00
|
|
|
{
|
2000-04-21 23:47:20 +00:00
|
|
|
$buf .= "unknown tree \"$t\", trees include @all_trees. ";
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-18 17:59:50 +00:00
|
|
|
$rg=0;
|
|
|
|
$ry=0;
|
|
|
|
$rr=0;
|
1998-10-17 01:54:40 +00:00
|
|
|
foreach my $e (sort keys %{$$trees{$t}})
|
|
|
|
{
|
2000-04-18 17:59:50 +00:00
|
|
|
$rg++ if ($$trees{$t}{$e}=~/Success/);
|
|
|
|
$ry++ if ($$trees{$t}{$e}=~/Test Failed/);
|
|
|
|
$rr++ if ($$trees{$t}{$e}=~/Horked/);
|
|
|
|
&debug("$rg $ry $rr $e => $$trees{$t}{$e}");
|
1999-06-11 23:36:46 +00:00
|
|
|
next if ($terse && $$trees{$t}{$e} eq "Success");
|
1998-10-17 01:54:40 +00:00
|
|
|
$buf .= "[$e: $$trees{$t}{$e}] ";
|
|
|
|
$bustage++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-18 17:59:50 +00:00
|
|
|
# $buf .= "- no known bustage -" if (! $bustage);
|
|
|
|
if ( $bustage) {$buf .=
|
|
|
|
"$rg success, $ry test failures, and $rr horked.";}
|
|
|
|
else { $buf .= "- no known bustage -";};
|
1998-10-29 18:59:22 +00:00
|
|
|
push @buf, $buf;
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
$buf = $buf ||
|
|
|
|
"something broke. report a bug here: " .
|
1999-03-17 19:36:11 +00:00
|
|
|
"http://bugzilla.mozilla.org/enter_bug.cgi " .
|
1998-10-22 22:01:42 +00:00
|
|
|
"with product of Webtools and component set to Mozbot";
|
1998-10-22 02:45:27 +00:00
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
push @buf, "last update: " .
|
|
|
|
&logdate ($last_tree) . " (" . &days ($last_tree) . " ago)";
|
1998-10-29 18:59:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
foreach my $m (@buf) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, $m);
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 18:59:22 +00:00
|
|
|
}
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
#############
|
|
|
|
# utilities #
|
|
|
|
#############
|
|
|
|
|
|
|
|
sub debug
|
|
|
|
{
|
|
|
|
return if (! $debug);
|
|
|
|
|
|
|
|
foreach (@_)
|
|
|
|
{
|
2000-04-18 17:59:50 +00:00
|
|
|
#timeless: Broken
|
|
|
|
# chomp;
|
1998-10-17 01:54:40 +00:00
|
|
|
print &logdate() . " $_ [$$]\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# logdate: return nice looking date (10/16/98 18:29)
|
|
|
|
|
|
|
|
sub logdate
|
|
|
|
{
|
|
|
|
my $t = shift;
|
|
|
|
$t = time unless ($t);
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime ($t);
|
|
|
|
|
|
|
|
return sprintf ("%02d/%02d/%02d %02d:%02d",
|
2000-01-03 10:06:00 +00:00
|
|
|
$mon + 1, $mday, $year + 1900, $hour, $min);
|
1998-10-17 01:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# days: how long ago was that?
|
|
|
|
|
|
|
|
sub days
|
|
|
|
{
|
|
|
|
my ($then) = shift;
|
|
|
|
|
|
|
|
my $seconds = time - $then;
|
|
|
|
my $minutes = int ($seconds / 60);
|
|
|
|
my $hours = int ($minutes / 60);
|
|
|
|
my $days = int ($hours / 24);
|
|
|
|
|
|
|
|
if ($seconds < 60)
|
|
|
|
{ return (sprintf "%d second%s", $seconds, $seconds == 1 ? "" : "s"); }
|
|
|
|
elsif ($minutes < 60)
|
|
|
|
{ return (sprintf "%d minute%s", $minutes, $minutes == 1 ? "" : "s"); }
|
|
|
|
elsif ($hours < 24)
|
|
|
|
{ return (sprintf "%d hour%s", $hours, $hours == 1 ? "" : "s"); }
|
|
|
|
else
|
|
|
|
{ return (sprintf "%d day%s", $days, $days == 1 ? "" : "s"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
# signal handler
|
|
|
|
|
|
|
|
sub killed
|
|
|
|
{
|
1999-10-12 22:34:49 +00:00
|
|
|
if ($::megahal_pid) {
|
|
|
|
&debug("Killing megahal.\n");
|
|
|
|
kill (2, $::megahal_pid);
|
|
|
|
}
|
1998-10-17 01:54:40 +00:00
|
|
|
confess "i have received a signal of some manner. good night.\n\n";
|
|
|
|
}
|
|
|
|
|
1998-10-22 02:45:27 +00:00
|
|
|
# write admin list
|
|
|
|
|
|
|
|
sub store_admin_conf
|
|
|
|
{
|
|
|
|
my $admins = shift;
|
|
|
|
my $when = localtime (time) . " by $$";
|
|
|
|
|
|
|
|
if (open ADMINS, ">$adminf")
|
|
|
|
{
|
|
|
|
print ADMINS <<FIN;
|
|
|
|
# mozbot admin list file
|
|
|
|
#
|
|
|
|
# this file is generated. do not edit.
|
|
|
|
# generated $when
|
|
|
|
#
|
|
|
|
# version: 1.0
|
|
|
|
|
|
|
|
FIN
|
|
|
|
|
|
|
|
foreach (sort keys %admins)
|
|
|
|
{
|
|
|
|
print ADMINS "$_ $admins{$_}\n";
|
|
|
|
}
|
|
|
|
close ADMINS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&debug ("&store_admin_conf $adminf: $!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# fetch list of admins
|
|
|
|
|
|
|
|
sub fetch_admin_conf
|
|
|
|
{
|
|
|
|
my $admins = shift;
|
|
|
|
|
|
|
|
if (open ADMINS, $adminf)
|
|
|
|
{
|
|
|
|
while (<ADMINS>)
|
|
|
|
{
|
|
|
|
chomp;
|
|
|
|
next if ($_ =~ /^#/ or ! $_);
|
|
|
|
my ($user, $host) = split /\s+/, $_;
|
|
|
|
$$admins{$user} = $host;
|
|
|
|
}
|
|
|
|
&debug ("admins: " . keys %$admins);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&debug ("&fetch_admin_conf $adminf: $!");
|
|
|
|
}
|
|
|
|
|
|
|
|
close ADMINS;
|
|
|
|
}
|
|
|
|
|
|
|
|
# create a pid file if we can
|
|
|
|
|
|
|
|
sub create_pid_file
|
|
|
|
{
|
1999-09-15 16:24:37 +00:00
|
|
|
my $pid = ".$nick-pid";
|
1998-10-22 02:45:27 +00:00
|
|
|
|
|
|
|
if (open PID, ">$pid")
|
|
|
|
{
|
|
|
|
print PID "$$\n";
|
|
|
|
close PID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
&debug ("warning: problem creating pid file: $pid, $!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-12 22:34:49 +00:00
|
|
|
sub init_megahal {
|
|
|
|
my $pid;
|
|
|
|
chdir("./megahal");
|
|
|
|
$pid = open2($::RDR, $::WTR, "./megahal");
|
|
|
|
chdir("..");
|
|
|
|
return($pid);
|
|
|
|
|
|
|
|
}
|
1999-01-07 23:21:44 +00:00
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
sub rdfchannel {
|
|
|
|
my ($foo, $url) = (@_);
|
|
|
|
debug("fetching rdfchannel $url");
|
|
|
|
$bot->schedule(60*60, \&rdfchannel, $url);
|
1998-12-31 18:38:54 +00:00
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
my $output = get $url;
|
|
|
|
$rdf_last{$url} = time();
|
|
|
|
return if (!$output);
|
|
|
|
|
|
|
|
my $channelpart = "";
|
1999-07-30 16:53:50 +00:00
|
|
|
if ($output =~ m@<channel>(.*)</channel>@si) {
|
|
|
|
$channelpart = $1;
|
1999-03-30 01:02:30 +00:00
|
|
|
}
|
|
|
|
$output =~ s@<image>.*</image>@@si;
|
|
|
|
|
|
|
|
$rdf_title{$url} = $url;
|
|
|
|
if ($channelpart =~ m@<title>(.+?)</title>@si) {
|
|
|
|
$rdf_title{$url} = trim($1);
|
|
|
|
}
|
|
|
|
$rdf_link{$url} = $url;
|
|
|
|
if ($channelpart =~ m@<link>(.+?)</link>@si) {
|
|
|
|
$rdf_link{$url} = trim($1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my @list;
|
1999-07-30 16:53:50 +00:00
|
|
|
while ($output =~ m@<item>(.*?)<title>(.+?)</title>(.*?)</item>@sig) {
|
|
|
|
push(@list, $2);
|
1998-12-31 18:38:54 +00:00
|
|
|
}
|
1999-03-30 01:02:30 +00:00
|
|
|
$rdf_items{$url} = \@list;
|
1998-12-31 18:38:54 +00:00
|
|
|
|
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
reportDiffs($rdf_title{$url}, $rdf_link{$url}, \@list);
|
1998-12-31 18:38:54 +00:00
|
|
|
}
|
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
# fetch tinderbox details
|
|
|
|
|
|
|
|
sub tinderbox
|
|
|
|
{
|
|
|
|
&debug ("fetching tinderbox status");
|
2000-04-21 23:47:20 +00:00
|
|
|
my ($newtrees, $newstatus) = Tinderbox::status (\@all_trees);
|
1998-10-22 02:45:27 +00:00
|
|
|
|
|
|
|
if (! $newtrees)
|
|
|
|
{
|
|
|
|
$bot->schedule (90, \&tinderbox);
|
|
|
|
&debug ("hmm, couldn't get tinderbox status");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-10-17 01:54:40 +00:00
|
|
|
$last_tree = time;
|
1998-10-22 02:45:27 +00:00
|
|
|
|
|
|
|
if (defined $status)
|
|
|
|
{
|
|
|
|
foreach my $s (keys %$newstatus)
|
|
|
|
{
|
|
|
|
if (defined $$newstatus{$s} && $$status{$s} ne $$newstatus{$s})
|
|
|
|
{
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($channel,
|
|
|
|
"$s changed state from $$status{$s} to $$newstatus{$s}");
|
1998-10-22 02:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-17 03:39:20 +00:00
|
|
|
if (defined $trees) {
|
|
|
|
foreach my $t (@trees) {
|
|
|
|
foreach my $e (sort keys %{$$newtrees{$t}}) {
|
|
|
|
if (!defined $$trees{$t}{$e}) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($channel, "$t: A new column '$e' has appeared ($$newtrees{$t}{$e})");
|
1998-10-17 03:39:20 +00:00
|
|
|
} else {
|
|
|
|
if ($$trees{$t}{$e} ne $$newtrees{$t}{$e}) {
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($channel, "$t: '$e' has changed state from $$trees{$t}{$e} to $$newtrees{$t}{$e}");
|
1998-10-17 03:39:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$trees = $newtrees;
|
1998-10-22 02:45:27 +00:00
|
|
|
$status = $newstatus;
|
1998-10-17 01:54:40 +00:00
|
|
|
|
|
|
|
$bot->schedule (360, \&tinderbox);
|
|
|
|
}
|
|
|
|
|
1998-10-17 02:50:48 +00:00
|
|
|
|
|
|
|
# See if someone has changed our source.
|
|
|
|
|
|
|
|
sub checksourcechange {
|
1998-10-17 03:06:52 +00:00
|
|
|
my ($self) = @_;
|
|
|
|
my $lastourdate = $::ourdate;
|
|
|
|
my $lasttinderboxdate = $::tinderboxdate;
|
1998-10-17 02:50:48 +00:00
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks)
|
|
|
|
= stat("./mozbot.pl");
|
1998-10-17 03:06:52 +00:00
|
|
|
$::ourdate = $mtime;
|
1998-10-17 02:50:48 +00:00
|
|
|
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks)
|
|
|
|
= stat("./Tinderbox.pm");
|
1998-10-17 03:06:52 +00:00
|
|
|
$::tinderboxdate = $mtime;
|
1998-10-22 02:45:27 +00:00
|
|
|
|
|
|
|
if (defined $lastourdate &&
|
|
|
|
($::ourdate > $lastourdate ||
|
1998-10-17 03:06:52 +00:00
|
|
|
$::tinderboxdate > $lasttinderboxdate)) {
|
|
|
|
$::dontQuitOnSignal = 1;
|
|
|
|
$self->quit("someone seems to have changed my source code. Be right back");
|
|
|
|
&debug ("restarting self");
|
|
|
|
exec "$0 @::origargv";
|
|
|
|
}
|
1998-10-17 02:50:48 +00:00
|
|
|
$bot->schedule (60, \&checksourcechange);
|
|
|
|
}
|
1999-01-07 22:33:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub stocks {
|
|
|
|
$bot->schedule(15 * 60, \&stocks);
|
|
|
|
|
|
|
|
my $url = "http://quote.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=" .
|
|
|
|
join("+", sort(keys %stocklist));
|
1999-03-30 01:55:38 +00:00
|
|
|
&debug ("fetching stock quotes $url");
|
1999-01-07 22:33:01 +00:00
|
|
|
my $output = get $url;
|
|
|
|
return if (!$output);
|
|
|
|
%stockvals = ();
|
|
|
|
foreach my $line (split(/\n/, $output)) {
|
|
|
|
my @list = split(/,/, $line);
|
|
|
|
my $name = shift(@list);
|
|
|
|
$name =~ s/"(.*)"/$1/;
|
1999-03-30 01:55:38 +00:00
|
|
|
&debug ("parsing stock quote $name ($list[0]) $line");
|
1999-01-07 22:33:01 +00:00
|
|
|
$stockvals{$name} = \@list;
|
|
|
|
foreach my $ref (@{$stockhist{$name}}) {
|
|
|
|
my $oldval = $ref->[0];
|
|
|
|
my $newval = $list[0];
|
|
|
|
my $ratio = $newval / $oldval;
|
|
|
|
if ($ratio > 1.05 || $ratio < 0.95) {
|
|
|
|
foreach my $who ($stocklist{$name}) {
|
|
|
|
ReportStock($who, $name, "Large Stock Change");
|
|
|
|
}
|
|
|
|
$stockhist{$name} = [];
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!exists $stockhist{$name}) {
|
|
|
|
$stockhist{$name} = [];
|
|
|
|
}
|
|
|
|
push (@{$stockhist{$name}}, \@list);
|
|
|
|
while (30 < @{$stockhist{$name}}) {
|
|
|
|
shift @{$stockhist{$name}};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub LoadStockList {
|
1999-03-30 01:55:38 +00:00
|
|
|
%stocklist = ("AOL" => [$channel],
|
1999-08-11 17:10:00 +00:00
|
|
|
"RHAT" => [$channel],
|
1999-04-23 16:20:25 +00:00
|
|
|
"^DJI" => [$channel],
|
|
|
|
"^IXIC" => [$channel]);
|
1999-03-30 01:55:38 +00:00
|
|
|
|
|
|
|
if (open(LIST, $stockf)) {
|
|
|
|
%stocklist = ();
|
|
|
|
while (<LIST>) {
|
|
|
|
my @list = split(/\|/, $_);
|
|
|
|
my $name = shift(@list);
|
|
|
|
$stocklist{$name} = \@list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-07 22:33:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub FracStr {
|
|
|
|
my ($num, $needplus) = (@_);
|
|
|
|
my $sign;
|
|
|
|
if ($num < 0) {
|
|
|
|
$sign = "-";
|
|
|
|
$num = - $num;
|
|
|
|
} else {
|
1999-03-30 01:55:38 +00:00
|
|
|
$sign = $needplus ? "+" : "";
|
|
|
|
$num =~ s/^\+//;
|
|
|
|
}
|
|
|
|
my $orignum = $num;
|
1999-01-07 22:33:01 +00:00
|
|
|
|
|
|
|
my $bdot = int($num);
|
|
|
|
my $adot = $num - $bdot;
|
|
|
|
|
|
|
|
if ($adot == 0) {
|
|
|
|
return "$sign$bdot";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $base = 64;
|
|
|
|
$num = int($adot * $base);
|
|
|
|
|
|
|
|
while ($num % 2 == 0 && $base > 1) {
|
|
|
|
$base /= 2;
|
|
|
|
$num /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($adot == $num / $base) {
|
|
|
|
if ($bdot == 0) {
|
|
|
|
$bdot = "";
|
|
|
|
} else {
|
|
|
|
$bdot .= " ";
|
|
|
|
}
|
|
|
|
return "$sign$bdot$num/$base";
|
|
|
|
}
|
1999-03-30 01:55:38 +00:00
|
|
|
return "$sign$orignum";
|
1999-01-07 22:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub ReportStock {
|
|
|
|
my ($nick, $name, $title) = (@_);
|
|
|
|
if ($title ne "") {
|
|
|
|
$title .= ": ";
|
|
|
|
}
|
|
|
|
my $ref = $stockvals{$name};
|
|
|
|
my $a = FracStr($ref->[0], 0);
|
|
|
|
my $b = FracStr($ref->[3], 1);
|
1999-03-30 04:50:31 +00:00
|
|
|
sendmsg($nick, "$title$name at $a ($b)");
|
1999-01-07 22:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub bot_stocks {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
foreach my $name (sort(keys %stocklist)) {
|
|
|
|
foreach my $who (@{$stocklist{$name}}) {
|
|
|
|
if ($who eq $nick || $who eq $channel) {
|
|
|
|
ReportStock($nick, $name, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-30 01:02:30 +00:00
|
|
|
|
1999-09-24 18:19:01 +00:00
|
|
|
sub bot_pub_stocks {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
1999-10-12 22:34:49 +00:00
|
|
|
bot_stocks($::speaker, $cmd, $rest);
|
1999-09-24 18:19:01 +00:00
|
|
|
sendmsg($nick, "[ Stocks sent to $::speaker. In the future, use \"/msg mozbot stocks\" ]");
|
|
|
|
}
|
|
|
|
|
1999-08-13 00:21:01 +00:00
|
|
|
sub translate_usage {
|
|
|
|
my ($nick) = (@_);
|
|
|
|
sendmsg($nick, "Usage: translate (to|from) (en|fr|pt|it|de) sentence");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bot_translate {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
my ($dir, $lang, @words) = split(/ +/, $rest);
|
|
|
|
if ($dir ne "to" && $dir ne "from") {
|
|
|
|
return translate_usage($nick);
|
|
|
|
}
|
|
|
|
my $result = babel::babelfish($dir, $lang, join(' ', @words));
|
|
|
|
if ($result ne '') {
|
|
|
|
sendmsg($nick, $result);
|
|
|
|
} else {
|
|
|
|
translate_usage($nick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-26 01:22:00 +00:00
|
|
|
sub bot_review {
|
|
|
|
my ($nick, $cmd, $rest) = (@_);
|
|
|
|
sendmsg($nick, "$::speaker, I've reviewed your code, and it looks great. r=mozbot.");
|
|
|
|
}
|
|
|
|
|
1999-03-30 01:02:30 +00:00
|
|
|
sub trim {
|
|
|
|
($_) = (@_);
|
|
|
|
s/^\s+//g;
|
|
|
|
s/\s+$//g;
|
|
|
|
return $_;
|
|
|
|
}
|
1999-03-30 04:50:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do this at the very end, so we can intersperse "my" initializations outside
|
|
|
|
# of routines above and be assured that they will run.
|
|
|
|
|
|
|
|
$irc->start;
|