using Bot::BasicBot with private channels


O

Olinga

[This message was posted to comp.lang.perl.modules yesterday but I've
received no responses so I'm posting here]

The attached Bot::BasicBot script, modified to protect some string
literals, works fine when connecting to servers using public channels,
including logging the first call to "say" sent to itself. Private
channels require an invitation request sent to an invite bot. In a
normal irc client I would type this to get the invitation:

/msg <botname> invite <username> <password>

To do this with BasicBot I called the "say" function on lines 30-34,
which are commented out in the attached script:

$self->say(
channel=>"msg",
who=>"welcomebot",
body=>"invite username password"
);

The script appears to hang (I don't know for sure because I don't see
a way to report errors) with those lines un-commented and never logs
any messages as it does when connected to public channels and lines
30-34 commented out.

Does anyone have suggestions on how to obtain the invite properly?
Perhaps this functionality is not supported.
=================================================================
#!/usr/bin/perl
use warnings;
use strict;

package MyBot;
use base qw( Bot::BasicBot );

open FILE,">/path/to/log";

MyBot->new(
server => 'uri',
channels => [ '#channel'],
port => '6667',
nick => 'username'
)->run();

sub connected {
my $self = shift;
#just to make sure this function was entered
$self->forkit({
run => [print FILE "connecting\n"]
});
#test by sending message to myself: works
$self->say(
channel=>"msg",
who=>"username",
body=>"invite username password"
);
#invite required prior to connecting to #tv channel: does not work
# $self->say(
# channel=>"msg",
# who=>"welcomebot",
# body=>"invite username password"
# );

}

sub said {
my ($self,$message) = @_;
my $who = $message->{who};
my $raw_nick = $message->{raw_nick};
my $channel = $message->{channel};
my $body = $message->{body};
my $address = $message->{address};
#for now just record a transcript of messages
my $str = "who: $who nick: $raw_nick channel: $channel body: $body
address: $address\n";
$self->forkit({
run => [print FILE $str]
});
return;
 
Ad

Advertisements

O

Olinga

You should always, yes always, check the return value from open.

Nowadays, you should also use the 3-arg form of open() along
with a lexical filehandle:

Tad - No disagreement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top