Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Community Cafe (http://www.bvlist.com/forumdisplay.php?f=18)
-   -   IRC message function (http://www.bvlist.com/showthread.php?t=9013)

joeroberts 24th March 2013 00:31

IRC message function
 
some one else may find use for this so I thought I would post it here

this function well connect to your IRC server and channel send one message and log back out

PHP Code:

function send_irc($string)
{
    
$ircServer "irc.p2p-network.net"#Set your irc sever
    
$ircPort "6668"#Set your IRC Port
    
$ircChannel "#phpmybittorrent"#sSet your IRC Channel
    
$output $string;
    
set_time_limit(0);
    
#connect to server
    
$socket fsockopen($ircServer$ircPort$errno$errstr);
    if(
$socket)
    {
        
// Make the socket blocking and set the read/write timeout to 10 seconds.
            
stream_set_blocking($sockettrue);
            
stream_set_timeout($socket10);
        
// Get machine's hostname (UNIX only)
            
$local_hostname trim(@file_get_contents("/etc/hostname"));
            if (!
$local_hostname$local_hostname "localhost"// Non-UNIX OSes
        // Log in.
            
fwrite($socket"NICK Rawr" rand() . "\n");
            
fwrite($socket"USER BT.Manager-bot {$local_hostname} {$ircServer} :PhpIrc Bot 0.0.2\n");
            
$cmd '';
            
$i=0;
            while(
$i 15)
            {    
            
// Read data from socket.
                
$data fread($socket1024);
                
$cmd .= $data;
                if (
strpos($cmd"\n") === false) continue;
                
$exData explode(' '$data);
                if(
$i == '14')
                {
                
//Join room
                    
fwrite($socket"JOIN " $ircChannel "\n");
                
//Send message
                    
fwrite($socket"PRIVMSG {$ircChannel} :{$output}\n");
                    break;
                }
                if(
$exData[0] == "PING")
                {
                    
fwrite($socket"PONG ".$exData[1]."\n");
                }
                
$i++;
            }
         
//Log off server
         
fwrite($socket"QUIT :Compile error!");
    }
                
//close fsockopn()
                
@fclose($socket);
                return;


to use it just call
PHP Code:

$string 'Hello irc channel and good by';
send_irc($string); 


lafouine022 24th March 2013 15:12

Nice thx


All times are GMT +2. The time now is 13:38.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.