PHP IRC Bot Class

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP IRC Bot Class

Post by John Cartwright »

ch1zra wrote:this is awesome :)
I'm a former mIRC scripter that finaly decided to move on to php, so the first logical step was to make a php irc bot :]
I've found this tutorial and it was pretty basic and easy to understand, but i have a problem now.
the bot connects and echoes all that is being said in channel, but if i refresh bot.php page in my browser, it gets stuck and bot dies.
so i was wondering how to fix this algorhytm :

Code: Select all

accessing bot.php via browser
if (bot is already connected to server) {
   just start displaying echo msgs from server
}
else {
   connect to irc server
   start echoing msgs from server
}
now, i've noticed that this is quite old thread, so I dont rly know will some1 answer, but it would be great to get some help :)
thanx in advance :]
Please do not hijack. Feel free to create a new thread and reference this if needed.
ch1zra
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2008 12:20 am

Re: PHP IRC Bot Class

Post by ch1zra »

I apologise, it was not my intention to hijack.
User avatar
techkid
Forum Commoner
Posts: 54
Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives

Re: PHP IRC Bot Class

Post by techkid »

Does this really works? I've tried many IRC Bots! None of those worked! DamN
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: PHP IRC Bot Class

Post by markusn00b »

This has possibly been brought up already - I haven't read the whole discussion.

You are not surrounding your array indexes with quotes, be it single or double. Now, while you may have error reporting off, this still incurs overhead as the PHP engine sees these identifiers that have no literal meaning to the engine. It first checks to see if there are any constants of the same name, and then, as a fallback, replaces them with a string of the same value, that is, bot becomes the string 'bot'. Whereas, if you (and you most certainly should) wrap the indexes with quotes (more preferably single - no parsing occurs on the string) the PHP engine knows it is a string. This is not only good practice, it is the correct way to do it. Think of the whole 'bug or feature?' discussion.

Mark.
Post Reply