|
-
Oct 22nd, 2006, 02:04 AM
#1
Thread Starter
Lively Member
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!
-
Oct 22nd, 2006, 07:46 AM
#2
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.
-
Oct 23rd, 2006, 03:23 AM
#3
Thread Starter
Lively Member
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.
-
Oct 23rd, 2006, 04:03 AM
#4
Re: IRC Bot
Um, why?
What is this, a web application or a command line application?
-
Oct 23rd, 2006, 06:49 AM
#5
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.
-
Oct 24th, 2006, 02:41 AM
#6
Thread Starter
Lively Member
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.
-
Oct 24th, 2006, 03:42 AM
#7
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.
-
Oct 24th, 2006, 04:05 AM
#8
Thread Starter
Lively Member
Re: IRC Bot
yeah... so... it's not reading messages all the time, so as soon as it is idle it exits.
-
Oct 24th, 2006, 04:12 AM
#9
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.
-
Oct 24th, 2006, 04:24 AM
#10
Thread Starter
Lively Member
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.
-
Oct 24th, 2006, 04:28 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|