Taking time to write about development

Sending messages to an Eggdrop via PHP

So if you frequent IRC often like I do, you may notice some eggdrop bots displaying messages which come from a website. The most common times you will see this sort of script in action is when they are hooked into forum posts or torrent listings. You will more than likely have seen messages saying “New forum topic…X Y by Z” or “[PRE]”. Today I’m going to show you how to do that by sending messages to an eggdrop via PHP.

It’s actually relatively easy (as you are about to see) and really only requires a few lines of PHP code on the web end and the same again in TCL on the eggdrop. The general idea is that the eggdrop will open up a socket and sit listening waiting for data to come through before displaying the message. For the PHP end it is as simple as connecting to said socket and sending through some data.

First things first, the TCL script sock-listen.tcl:

That’s it! Simple enough. Create a socket which will sit and listen waiting for something to connect and send through data. Once a connection is made call the ‘action’ function which will  send a message to the channel with the host, port and socket data.

To get that up and running just copy sock-listen.tcl into the scripts folder of your eggdrop and include it in your config file. Don’t forget to change the channel, IP address and port. Once you rehash or reconnect the bot the socket will automatically start listening.

Now to send messages from PHP is very straight forward, just open up a socket and connect to the IP/port specified in the TCL script. Send through a message and watch it come out the other end (IRC channel).

To do this we create a php file called send.php and place the following code:

Again, easy enough. Make sure you set the correct IP address and port and then upload the file. Point your browser to it and watch the magic happen. You should see the following message appear on the IRC channel: | 7878 | Sent from a PHP page

To make it easier I’ve added a small form which will allow you to customize the message to your liking. Again send.php:

It isn’t all that secure but gives you a general idea of what you can do. To implement it into the examples I posted at the start all you really need to do is edit the submit/post PHP files and place the socket code above with a customized message in.

This isn’t limited to just PHP. Something similar could easily be set up in a number or any other languages as well. Simply by opening the socket and sending the data.

Something simple for  the day. Have a play around and let me know if you make any improvements. Feel free to ask any questions, I’ll do my best to answer them 🙂

Also feel free to follow me on twitter: @JAGracie


, , , ,

One thought on “Sending messages to an Eggdrop via PHP

Leave a Reply

Your email address will not be published. Required fields are marked *