· 8 years ago · Jul 15, 2018, 07:22 PM
1<?php
2
3/**
4 * @author Omnipotent
5 * @copyright 2009
6 */
7
8set_time_limit(0);
9ini_set('display_errors','on');
10echo '0';
11$config = array(
12 'server' => 'localhost',
13 'port' => 6667,
14 'nick' => 'PHPBot',
15 'name' => 'PHPBot made by Omnipotent',
16 'pass' => 'pass'
17);
18
19class IRCBot {
20 var $sock;
21 var $s = array();
22
23 function __construct($config) {
24 echo '.5';
25 $this->sock = fsockopen($config['server'],$config['port'],$errno,$errstr);
26
27 echo '1';
28 flush();
29 $this->connect($config);
30 $this->main();
31 $this->send_data('JOIN', '#Welcome');
32 }
33
34 function send_data($cmd, $msg = null) {
35 if ($msg == null) {
36 fputs($this->sock,$cmd."\n");
37 echo '-> ' . $cmd. '<br />';
38 }
39 else {
40 fputs($this->sock,$cmd.' '.$msg."\n");
41 echo '-> '. $cmd.' '.$msg. '<br />';
42 }
43 flush();
44 }
45
46 function connect($config) {
47 $this->send_data('USER', $config['nick'].' gmail.com '.$config['nick'].' :'.$config['name']);
48 $this->send_data('NICK', $config['nick']);
49 }
50
51 function main() {
52 $data = fgets($this->sock,128);
53 echo '<- ' . nl2br($data);
54 flush();
55 $this->s = explode(' ', $data);
56
57 if ($this->s[0] == 'PING') {
58 $this->send_data('PONG', $this->s[1]);
59 }
60
61 $this->main();
62 }
63}
64
65$bot = new IRCBot($config);
66
67?>