Advertisement
P22DX

irc.php

Jun 21st, 2020
1,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. function read_socket($socket)
  4. {
  5.     while($rawData = fgets($socket)) {
  6.         $data .= $rawData;
  7.     }
  8.     return $data;
  9. }
  10.  
  11. function send_message(string $channel, string $message)
  12. {
  13.     global $irc;
  14.     fprintf($irc, "PRIVMSG #%s :%s\n", $channel, $message);
  15. }
  16.  
  17. $host = 'irc.freenode.net';
  18. $port = '6667';
  19. $nick = 'Menhera_bot';
  20. $param = 'USER Linux 127.0.0.1 localhost';
  21. $channel = 'BHSec';
  22.  
  23. $irc = fsockopen($host, $port, $errno, $errstr, 30);
  24. stream_set_blocking($irc, 0);
  25.  
  26. if($irc) {
  27.     fprintf($irc, "USER %s\n", $param);
  28.     sleep(5);
  29.     fprintf($irc, "NICK %s\n", $nick);
  30.     echo read_socket($irc);
  31.     sleep(5);
  32.     fprintf($irc, "JOIN #%s\n", $channel);
  33.     echo read_socket($irc);
  34.     sleep(5);
  35.  
  36.     while(1)
  37.     {
  38.         $msg = readline('IRC: ');
  39.         $msg = trim($msg);
  40.  
  41.         if(empty($msg)) {
  42.             echo read_socket($irc);
  43.         } else {
  44.             send_message($channel, $msg);
  45.         }
  46.     }
  47. }
  48.  
  49. fclose($irc);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement