My bot lives on the same box as a web server hosting forums, and I would like for the bot to post a message to the irc channel when ever a new post is made.
I figured I could have the webserver write a file when a post is made, then have the bot check for the file every 5 mins or so. if the file exsist, read the info from the file concering the post, and echo it in the irc channel.
Can any one offer any insite as to how this might be done, as far as the plugin part is concerned?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Perlbot::schedule doesn't do anything except to call Net::IRC::Connection::schedule and takes only two parameters. Due to this, the scheduled function gets no parameters. No $user, no $text and no $event.
After all, when the sub is called it was triggered due to a timeout on the local machine, not due to a server event. There's no IRC-relevant data available, so you don't get any.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
My bot lives on the same box as a web server hosting forums, and I would like for the bot to post a message to the irc channel when ever a new post is made.
I figured I could have the webserver write a file when a post is made, then have the bot check for the file every 5 mins or so. if the file exsist, read the info from the file concering the post, and echo it in the irc channel.
Can any one offer any insite as to how this might be done, as far as the plugin part is concerned?
this
sub init {
$self->perlbot->schedule(300, sub { $self->checkfile() });
}
sub checkfile {
my $self = shift;
my $user = shift;
my $text = shift;
my $event = shift;
open (FILEXTR, "myfile.txt");
chomp(@linez = <FILEXTR>);
close (FILEXTR);
}
evr as u wish
There's sort of a mistake there...
Perlbot::schedule doesn't do anything except to call Net::IRC::Connection::schedule and takes only two parameters. Due to this, the scheduled function gets no parameters. No $user, no $text and no $event.
After all, when the sub is called it was triggered due to a timeout on the local machine, not due to a server event. There's no IRC-relevant data available, so you don't get any.
You can pass some params in the closure:
$self->perlbot->schedule(300, sub { $self->checkfile($self->config('channel_to_notify')) });
(assuming you have a channel_to_notify setting in your plugin's config)
This is how Net::IRC's schedule works, we just wrap it in the perlbot object.
Er, hell, you can just call $self->config... from checkfile(), no need to pass that as a param.
Anyway, if you need to pass other params that are determined when you call schedule(), you can pass them in the closure.