Posted: Wed Jun 06, 2007 12:11 am Post subject: Multiple bots handled by one program
I'm making a bot-service which should be able to care for many users at once. As the limit of the MSN protocol seems to be 600, I had to divide the workload on several different bots. This now seems to work, however I have one problem.
When assigning handlers for the different events, eg. Message, the $self referred to in the sub's header is not the actual MSN object, but rather SwitchBoard, whatever that is. The problem is that when I can't access the MSN object who owns the SwitchBoard object, I cannot send any replies, or do anything else for that matter. The echobot.pl which I got with the MSN package, just accessed $msn directly, but I have many $msn's, and as of now can't know which ones to use
(Why) is there no way to retrieve the MSN object? Why is it SwitchBoard who calls the event-handler, and not the MSN object?
If anyone has any clever solutions to this, I'd be grateful.
$self->{Msn}->setDisplayName ("testing a \$msn object function");
A longer solution:
Don't use actual $msn type variables for your individual bots, put them inside of a hash, by name:
Code:
my $bot = {}; # this is an anonymous hash reference
my @bots = (
'mirror1@msn.com',
'mirror2@msn.com',
'mirror3@msn.com',
);
foreach my $handle (@bots) {
$bot->{$handle} = new MSN (
Handle => $handle,
Password => "you figure this part out on your own",
);
$bot->{$handle}->setHandler (Message => \&on_message);
$bot->{$handle}->signon();
}
# Treat $bot->{$handle} as you would a $msn object, e.g.
# $bot->{'mirror1@msn.com'}->setDisplayPicture, to command a
# specific mirror
sub on_message {
my ($self,@otherinfo) = @_;
# Get this bot's own handle.
my $handle = $self->{Msn}->{Handle};
# now we know this bot's handle, so we can command its
# MSN object directly.
$bot->{$handle}->sendMessage (To => 'master@msn.com', Message => 'hello world!');
}
Thank you so much for your reply. And now I feel stupid
The first solution will do just fine, I just didnt even consider that SwitchBoard had a pointer to the $msn object. Thanks to you, the problem is now trivial