View Single Post
  #1  
Old 24th March 2013, 00:31
joeroberts's Avatar
joeroberts joeroberts is offline
BT.Manager Owner
 
Join Date: Jan 2008
United States
Posts: 2,113
Default 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); 
__________________
Do not ask me to help you work on your site that is not phpMyBitTorrent
Do not ask me to make a mod for any other source
Do not Ask me to setup your site.
I will no longer help you setup your site, there is a setup script if you have trouble with it post in the forum here or in BT.Manager™ forum
My Current Demo is here http://demo.btmanager.org/
Reply With Quote