Jump to content

Irc bot help


HueyJib

Recommended Posts

I wanna make a command that actually lets you do php from inside irc. For example, if I was in an irc channel and I typed:

 

! $words = "Hi"; echo $words;

 

Then the bot would respond by saying Hi in the channel.

 

How could I make a command like that?

 

<?php

set_time_limit(0);

$conf['nick'] = 'Bot';
$conf['server'] = 'irc.gtanet.com';
$conf['port'] = 6667;
$conf['ident'] = 'Bot';
$conf['realname'] = 'Bot';

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, $conf['server'], $conf['port']) || die("\nfailed conn\n");
socket_write($socket, 'NICK '.$conf['nick']."\r\n");
socket_write($socket, 'USER '.$conf['ident'].' email.com Simps :'.$conf['realname']."\r\n");

while(($line = socket_read($socket, 1024, PHP_NORMAL_READ)) !== false) {
    
    if (substr($line, 0, 5) == 'PING ') { socket_write($socket,'PONG '.substr($line,5)); continue; }
    else {
        echo $line;
        $ex = explode(' ', $line);
        if($ex[1] == '001') { socket_write($socket,'JOIN #gta'."\r\n"); }
        elseif($ex[1] == 'PRIVMSG') {
            unset($chan);
            list($nick,$addr) = explode('!',substr($ex[0],1));
            $text = substr(rtrim(implode(' ', array_slice($ex, 3))), 1);
            if (substr($ex[2], 0, 1) == '#') { $chan = $ex[2]; }
            if ($text == '!die') {
                if($chan) { socket_write($socket,'PRIVMSG '.$chan.' :Bye'."\r\n"); }
                else { socket_write($socket,'PRIVMSG '.$nick.' :Dying'."\r\n"); }
                die("\nRequested\n");
            }
}
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/120291-irc-bot-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.