Menu

Messages to channel on a timer?

Help
2003-03-10
2003-04-12
  • Brandt Lofton

    Brandt Lofton - 2003-03-10

    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? 

     
    • Alice Beabee

      Alice Beabee - 2003-03-10

      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

       
    • Elberet

      Elberet - 2003-03-24

      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.

       
    • Jeremy Muhlich

      Jeremy Muhlich - 2003-04-12

      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.

       
    • Jeremy Muhlich

      Jeremy Muhlich - 2003-04-12

      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.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.