- Code: Select all
001 <?php
002
003 // BotScript made by Paradox.
004
005 set_time_limit(0);
006
007 ini_set('display_errors', 'off');
008
009
010 //Bot connection .
011
012 $config = array(
013 'server' => 'lightirc.com', //Do not change the server, everything else.
014 'port' => 6667,
015 'nick' => 'Bot Name',
016 'name' => 'Name here',
017 'pass' => 'Password here',
018 );
019
020
021 class IRCBot {
022
023 //This is going to store our TCP/IP connection data
024
025 var $socket;
026
027
028
029 //This is going to hold all of the data both server and client
030
031 var $ex = array();
032
033
034
035 /*
036
037 Constructive, This logs the bot in
038
039
040
041 @param array
042
043 */
044
045 function __construct($config)
046
047 {
048
049 $this->socket = fsockopen($config['server'], $config['port']);
050
051 $this->login($config);
052
053 $this->main();
054
055 $this->send_data('JOIN', '#chat'); //Change #chat to your Chat room name.
056
057 }
058
059
060
061 /*
062
063 Logs the bot in on the server
064
065
066
067 @param array
068
069 */
070
071 function login($config)
072
073 {
074
075 $this->send_data('USER', $config['nick'].' acidavengers.co.uk '.$config['nick'].' :'.$config['name']);
076
077 $this->send_data('NICK', $config['nick']);
078
079 }
080
081
082
083 /*
084
085 This is the work function, uses data from the server and displays it
086
087 */
088
089 function main()
090
091 {
092
093 $data = fgets($this->socket, 128);
094
095 echo nl2br($data);
096
097 flush();
098
099 $this->ex = explode(' ', $data);
100
101
102
103 if($this->ex[0] == 'PING')
104
105 {
106
107 $this->send_data('PONG', $this->ex[1]); //The bot will say pong when connected
108
109 }
110
111
112
113 $command = str_replace(array(chr(10), chr(13)), '', $this->ex[3]);
114
115
116
117 switch($command) //List of commands the bot will recall.
118
119 {
120
121 case ':!join':
122
123 $this->join_channel($this->ex[4]);
124
125 break; //This is the socket where the bot will join the server
126
127
128
129 case ':!quit':
130
131 $this->send_data('QUIT', 'Paradox made Bot');
132
133 break;
134
135
136
137 case ':!op':
138
139 $this->op_user();
140
141 break;
142
143
144
145 case ':!deop':
146
147 $this->op_user('','', false);
148
149 break;
150
151
152
153 case ':!protect':
154
155 $this->protect_user();
156
157 break;
158
159 }
160
161
162
163 $this->main();
164
165 }
166
167
168
169 function send_data($cmd, $msg = null) //displays stuff to the broswer and sends data to the server.
170
171 {
172
173 if($msg == null)
174
175 {
176
177 fputs($this->socket, $cmd."\r\n");
178
179 echo '<strong>'.$cmd.'</strong><br />';
180
181 } else {
182
183 fputs($this->socket, $cmd.' '.$msg."\r\n");
184
185 echo '<strong>'.$cmd.' '.$msg.'</strong><br />';
186
187 }
188
189 }
190
191
192
193 function join_channel($channel) //Joins a channel, used in the join function.
194
195 {
196
197 if(is_array($channel))
198
199 {
200
201 foreach($channel as $chan)
202
203 {
204
205 $this->send_data('JOIN', $chan);
206
207 }
208
209 } else {
210
211 $this->send_data('JOIN', $channel);
212
213 }
214
215 }
216
217
218
219 function protect_user($user = '')
220
221 {
222
223 if($user == '')
224
225 {
226
227 if(php_version() >= '5.3.0')
228 {
229 $user = strstr($this->ex[0], '!', true);
230 } else {
231 $length = strstr($this->ex[0], '!');
232 $user = substr($this->ex[0], 0, $length);
233 }
234 }
235
236 }
237
238
239
240 $this->send_data('MODE', $this->ex[2] . ' +a ' . $user);
241
242 }
243
244
245
246 function op_user($channel = '', $user = '', $op = true)
247
248 {
249
250 if($channel == '' || $user == '')
251
252 {
253
254 if($channel == '')
255
256 {
257
258 $channel = $this->ex[2];
259
260 }
261
262
263
264 if($user == '')
265
266 {
267
268 if(php_version() >= '5.3.0')
269 {
270 $user = strstr($this->ex[0], '!', true);
271 } else {
272 $length = strstr($this->ex[0], '!');
273 $user = substr($this->ex[0], 0, $length);
274 }
275 }
276
277 }
278
279
280
281 if($op)
282
283 {
284
285 $this->send_data('MODE', $channel . ' +o ' . $user);
286
287 } else {
288
289 $this->send_data('MODE', $channel . ' -o ' . $user);
290
291 }
292
293 }
294
295 }
296
297
298 $bot = new IRCBot($config);
299
300 ?>
Well that's the code, copy and paste it to notepad, and follow the instructions. instructions = //Sentence here.