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

Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

kettle_drum wrote:In the class constructor set_time_limit(0); means that the script wont timeout by itself due to a maximum execution time (usually 30 seconds). Hope that answers whoevers question that was.
Aha.

So it *is* a persistently running script. Some (most?) virtual hosting companies disable the ability to do set_time_limit. Further, running the script persistently would generally only be usable via CLI.. web browsers close.
kettle_drum wrote: The other thing is that the bot sometimes disconnects unexpectely if you run if from a browser - but works A LOT better if you run it from a shell/cli.
I would bet its not so unexpected - web has TTL's, and other issues and if the script missed it JUST ONCE, it would time out. So yeah, you'd need to run it from a shell/cli. Since many people don't have that capability, thats why I asked how it worked..

I didn't understand that part, and now I do. Different fundamental assumptions.
kettle_drum wrote: And finally, im currently updating this bot to make it bigger and better by using modules - so that a framework bot can be made to do whatever you like by adding other modules to it e.g. chanserv, nickserv, operserv, logging, newsserv, search etc - and by adding a "fake stack" to queue commands/processes so it runs like it uses threads and so speeds it up and keeps a constant flow of data coming in through the socket connection - which also helps to ensure that it never pings out, tests so far have had it online for just over 2 days with no interruptions.

Ill keep you posted as to the arrival of the new one incase anybody wants to have a play with it.
I definitely would. While I don't think its appropriate/perfect for all needs, I see signifigant value in it. :)
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

[13:13:05] -NiceGuyIRCbot- You must be a level 2 user to use this command.
umm how do i get level 2? its my bot..
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You set it in the database:

#holds access details to the bots controls
CREATE TABLE access (
user varchar(20) NOT NULL,
level tinyint(1) NOT NULL default '1',
channel varchar(255) NOT NULL,
server varchar(255) NOT NULL
);

First set yourself as level 9, and then you can use the !adduser command.
stormchaser
Forum Newbie
Posts: 1
Joined: Tue Aug 10, 2004 2:44 pm

Post by stormchaser »

There is a designers flaw in the message parsing engine within the core engine, namely this:

Code: Select all

$message = str_replace("$params[2]", "", $message);
This will replace every instance of the word, same as channel or user (wasn't tested on user) with null... Not good... It's better to use

Code: Select all

$message = substr($message,strlen($params[2]));
MrSomeone
Forum Newbie
Posts: 7
Joined: Sun Oct 10, 2004 8:36 am

Post by MrSomeone »

Just wanted to thank you for that link in your weather function, it was very useful to me. ;)
jl
Forum Commoner
Posts: 53
Joined: Tue Nov 09, 2004 12:05 am

Great!!

Post by jl »

Wow, this is great.. worked first time and a great base to start messing with PHP bots from IRC.

Couple of questions...

1. Has anyone worked on this - any updates anywhere, or other sites/projects that might be useful for IRC bots?

2. I PMed the author about this, but would like other feedback: when I do !help in channel, the bot messages me the help fine, but it does it at about 1 line per second - and I can't see why that would be from the code.. anyone suggest why it does this? It's not lag, i'm on a single IRC server, and other commands, e.g. !weather pop back their result immediately.

Thanks for any help.
jl
Forum Commoner
Posts: 53
Joined: Tue Nov 09, 2004 12:05 am

Post by jl »

Just in case anyone's reading this thread, there's a PEAR IRC class called Net_SmartIRC that pretty much makes writing your own PHP IRC class re-inventing the wheel - it does everything I need from a PHP class at the moment and is probably a good base to start from if you need a class to do something else.
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post by genetix »

Does anyone know of any good tutorials on making bots with PHP?

I cant seem to find any.
jl
Forum Commoner
Posts: 53
Joined: Tue Nov 09, 2004 12:05 am

Post by jl »

See my previous post ( !!! ) , RTFM for that and you'll be all set to make your own IRC bot.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I believe genetix was asking for some tutorials rather than IRC classes. That may well be a very useful link but telling someone to RTFM is a bit too strong.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

When i wrote this bot I couldnt find any tutorials and so just wrote it checking with the RFC to see what the protocol was. Once you have the connection done then it is very simple to interact with an IRC server - just have a play about, try and look at the RFC and see how things are done in the source code to this bot....if you can work your way through the mess.

To help you out a bit ive cleaned the basic code used to connect the bot up and put it into a more simple class to deal with getting the bot connected to the server - you just need to provide a loop for it to run in and then parse the response from the IRC server as you like - you can find the class here:

http://www.redvodkajelly.com/code/5

Again its nothing special, but it will help you get on the right tracks.
jl
Forum Commoner
Posts: 53
Joined: Tue Nov 09, 2004 12:05 am

Post by jl »

Yeah sorry, RTFM was a bit strong for that, I meant 'rtm', as the docs for Net_SmartIRC include a lot of very useful pretty easy to understand and tweak examples, which would get you going pretty quick. A simple 'bot' that actually does something is 10 lines of code with Net_SmartIRC, so it's very easy to get going.
PhantomCircuit
Forum Newbie
Posts: 3
Joined: Sat Jan 08, 2005 5:13 am

Post by PhantomCircuit »

Unfortunatly this IRC bot is incompatable with the common UnrealIRCD IRC server but could be made to work by changing the simple pong reply to a "PONG".substr($msg,6)

as UnrealIRCD sends ping 98590mf and you must reply back pong 98590mf
Dojo08
Forum Newbie
Posts: 1
Joined: Sat Jun 21, 2008 2:00 pm

Re: PHP IRC Bot Class

Post by Dojo08 »

hm, trying to use the phpurple extension, has anyone already expierienced it?

http://thinker.rubay.de/archives/20-PHP ... l#extended
ch1zra
Forum Newbie
Posts: 2
Joined: Wed Oct 15, 2008 12:20 am

Re: PHP IRC Bot Class

Post by ch1zra »

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 :]
Post Reply