Results 1 to 11 of 11

Thread: IRC Bot

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    IRC Bot

    Hi guys,

    I've started making a bot in php (run from the command line) for IRC. I am finding it fairly simple to do what i want except one thing. How do i stop my script from terminating once it has executed? I can connect to an IRC server and join channels but once there is nothing for the bot to do it just terminates. Any ideas for a main loop? OR are there any existing modules that do this?

    Thanks in advance!

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: IRC Bot

    Not sure that PHP is the right language for this; it is not very good at event-driven programming. You will hit the maximum execution time if you have a loop; although you can alter that setting, it's still not an ideal platform for such an application.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: IRC Bot

    OK... I may have a go in C. Having said that, how would i go about a php scripting interface for a C program.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: IRC Bot

    Um, why?

    What is this, a web application or a command line application?

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: IRC Bot

    Command line PHP scripts don't have an execution time limit, I think. Nothing wrong with doing this in PHP.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: IRC Bot

    It is a command line application... And I don't think that is correct. Once i execute the script i can see that the bot has joined but then it disconnects once the script reach its end. I think PERL would be much more suited to this. But if i can do it in PHP that would be fantastic.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: IRC Bot

    Well, the script should block on reading messages, not just end.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: IRC Bot

    yeah... so... it's not reading messages all the time, so as soon as it is idle it exits.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: IRC Bot

    Well, then you need to make it wait until a message is available. How do you read messages in the first place?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    110

    Re: IRC Bot

    socket_read()? problem is i haven't got that far. There is not point working out how i'm gonna read new messages if i can't get the thing to stay alive.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: IRC Bot

    Of course there is! Reading new messages is the key to staying alive. socket_read() will block until data is available, keeping your program alive. Then you process the data, act on it, and start over.
    Code:
    while(running) {
      data = read data;
      process data into messages;
      for every message {
        if message is control command {
          respond to message;
        }
        if message is quit command {
          running = false;
        }
      }
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width