| 1 |
#!/usr/bin/perl -w |
|---|
| 2 |
|
|---|
| 3 |
# This bot should not be run by any sane person. Really. The original idea |
|---|
| 4 |
# was to join to a channel a bot for every module in CPAN, and have them |
|---|
| 5 |
# announce when new versions of themselves were released, etc, etc. I can't |
|---|
| 6 |
# remember who had this insane idea, probably sky. Anyway, this is proof of |
|---|
| 7 |
# concept code, and inspired the changes in the source that let you put >1 |
|---|
| 8 |
# BasicBot in a single POE session. |
|---|
| 9 |
|
|---|
| 10 |
# The problem is that with more than 30 or 40 running bots, even on the same |
|---|
| 11 |
# machine as the IRC server, the latencies get insane. You just can't keep |
|---|
| 12 |
# them all alive enough to stay connected and not time-out. So the idea was |
|---|
| 13 |
# a non-starter, because I'm not running a process on the server for every |
|---|
| 14 |
# module on CPAN. But I can think of some cases where you'd want to run 2 or |
|---|
| 15 |
# 3 bots in a single session, to bridge networks, say, that sort of thing, |
|---|
| 16 |
# and so heere's how I'd do it... |
|---|
| 17 |
|
|---|
| 18 |
# Probably, this does not work. |
|---|
| 19 |
|
|---|
| 20 |
# The bot moudle itself. |
|---|
| 21 |
|
|---|
| 22 |
package CPANBot; |
|---|
| 23 |
use Bot::BasicBot; |
|---|
| 24 |
use strict; |
|---|
| 25 |
use warnings::register; |
|---|
| 26 |
use base 'Bot::BasicBot'; |
|---|
| 27 |
|
|---|
| 28 |
sub create { |
|---|
| 29 |
my $class = shift; |
|---|
| 30 |
my $nick = shift; |
|---|
| 31 |
print STDERR "Creating $nick\n"; |
|---|
| 32 |
my $self = bless Bot::BasicBot->new( nick => $nick, |
|---|
| 33 |
server => 'london.irc.perl.org', |
|---|
| 34 |
no_run => 1, # don't run the bot automatically |
|---|
| 35 |
), $class; |
|---|
| 36 |
$self->{_delay} = shift || 1; |
|---|
| 37 |
return $self; |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
sub connected { |
|---|
| 41 |
my $self = shift; |
|---|
| 42 |
print STDERR $self->nick." connected\n"; |
|---|
| 43 |
$self->join('#jerakeen'); |
|---|
| 44 |
$self->say(channel => '#jerakeen', body => 'lo, I am '.$self->nick); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
sub said { |
|---|
| 48 |
my $self = shift; |
|---|
| 49 |
my $mess = shift; |
|---|
| 50 |
print STDERR $self->nick." : ".$mess->{body}."\n"; |
|---|
| 51 |
my $nick = $self->nick; |
|---|
| 52 |
if ($mess->{body} =~ /$nick/i) { |
|---|
| 53 |
$self->say(channel => $mess->{channel}, body => 'I 0wnz0r you'); |
|---|
| 54 |
} |
|---|
| 55 |
if ($nick =~ /$mess->{body}/i) { |
|---|
| 56 |
$self->say(channel => $mess->{channel}, body => 'you 0wnz0r me'); |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
package main; |
|---|
| 64 |
use POE; |
|---|
| 65 |
use CPANPLUS::Backend; |
|---|
| 66 |
use Data::Dumper; |
|---|
| 67 |
|
|---|
| 68 |
my $cp = new CPANPLUS::Backend; |
|---|
| 69 |
#$cp->reload_indices(update_source => 1); |
|---|
| 70 |
my $modules = $cp->module_tree; |
|---|
| 71 |
#print Dumper($modules); |
|---|
| 72 |
|
|---|
| 73 |
my @names = keys(%$modules); |
|---|
| 74 |
my @bots; |
|---|
| 75 |
|
|---|
| 76 |
for (@names) { |
|---|
| 77 |
s/:+/_/g; |
|---|
| 78 |
s/\W//g; |
|---|
| 79 |
# next unless length($_) < 19; |
|---|
| 80 |
next unless /^Bot/; |
|---|
| 81 |
push @bots, $_; |
|---|
| 82 |
print STDERR "$_!\n"; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
my $bot = {}; |
|---|
| 86 |
|
|---|
| 87 |
my $i = 0; |
|---|
| 88 |
|
|---|
| 89 |
for (@bots) { |
|---|
| 90 |
|
|---|
| 91 |
# this next line needs a code change to Bot::Basicbot - take the |
|---|
| 92 |
# $poe_kernel->run line out of the run method, we don't want the bots to |
|---|
| 93 |
# run themselves. |
|---|
| 94 |
|
|---|
| 95 |
$bot->{$_} = CPANBot->create($_, $i)->run; |
|---|
| 96 |
$i+= 11; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
$poe_kernel->run(); |
|---|