een-php-irc-bot

Gesponsorde koppelingen

PHP script bestanden

  1. een-php-irc-bot

« Lees de omschrijving en reacties

- Voorbeeld scriptje

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
include("class.php");

$bot = new ZeroBot;

$bot->setServer("irc.chat4all.org");
$bot->setName("[B]Dae", "BOT");
$bot->setChannel("#test");
$bot->setAdmin("Dae");

// newOnText( String trigger, String Functie, Int required parameters [, Array parameter]);
$bot->newOnText('!say', 'msg', 1, Array("*chan", "*1-"));
$bot->newOnText('!msg', 'msg', 1, Array("*1", "*2-"));

$bot->newOnText('!op', 'op', 1, Array("*chan", "*1"));
$bot->newOnText('!op', 'op', 0, Array("*chan", "*nick"));

$bot->newOnText('!join', 'join', 2, Array("*1", "*2"));
$bot->newOnText('!join', 'join', 1, Array("*1"));

$bot->newOnText('!part', 'part', 1, Array("*1-"));
$bot->newOnText('!part', 'part', 0, Array("*chan"));

$bot->newOnText('!quit', 'quit', 1, Array("*1-"));
$bot->newOnText('!quit', 'quit', 0, Array("Quitting..."));

$bot->newOnText('!name', 'changeName', 1, Array("*1"));

// newOnText( String trigger, String functie, int required parameters [, Array parameters]);
$bot->newOnCtcp('version', 'ctcp', 0, Array("*nick", "( :: ZeroBot :: ) [v*version] ( :: by DaeDaluz :: )"));
$bot->newOnCtcp('time', 'ctcp', 0, Array("*nick", "*fulltime"));
$bot->newOnCtcp('finger', 'ctcp', 0, Array("*nick", "Nice ^^"));

// newOnUserMode(string usermode, string functie);
$bot->newOnUserMode('+w', 'perform');

// newOnNumerc(string numeric, string functie);
$bot->newOnNumeric('352', 'storeUsers');

// newOnJoin('String functie, Array parameters [, String on who ] [, String channel]);
$bot->newOnJoin('send', Array('who *chan'), '*me');

// newOnPart('String functie, Array parameters [, String on who ] [, String channel]);

$bot->connect();

while ($bot->connected()) {
    if ($bot->newData()) {
        $bot->printData();
        $bot->events();
    }

    usleep(100);
}

?>


- De klasse

class.php:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<?php
define("VERSION", "1.0");
set_time_limit(0); // Set time limit at 0, so it wont be cut off after 30sec
error_reporting(E_ALL); // Make it report all errors.

class ZeroBot {
    // Class variables
    var $CONFIG = Array();
    var
$con = array();
    var
$buffer = array();
    var
$perform = true;
    var
$onText = Array();
    var
$onJoin = Array();
    var
$onPart = Array();
    var
$onCtcp = Array();
    var
$onUserMode = Array();
    var
$onNumeric = Array();
    var
$channels = Array();
    var
$usersOnChannel = Array();

    function
ZeroBot ()  {
        // Define some default values.
        $this->CONFIG['nick'] = "ZeroBot";
        $this->CONFIG['ident'] = "Zero bot ". VERSION;
        $this->buffer['old_buffer'] = "";
        $this->buffer['new'] = false;
        $this->CONFIG['admin'] = "";
    }

    function
connect () {
        // if configured, connect.
        if (count($this->CONFIG) >= 4) {
            $this->con['socket'] = fsockopen($this->CONFIG['server'], $this->CONFIG['port']);
            if (!$this->con['socket']) {
                $this->error("Could not connect to: ". $this->CONFIG['server'] ." on port ". $this->CONFIG['port']);
            }
else {
                   $this->send("USER ". $this->CONFIG['nick'] ." ". $this->CONFIG['server'] ." ". $this->CONFIG['server'] ." :". $this->CONFIG['ident']);
                $this->send("NICK ". $this->CONFIG['nick'] ." ". $this->CONFIG['server']);
            }
        }
else {
            $this->error("Not configured correctly!");
        }
    }

    function
newData () {
        // check if there's new data to be read, and handle if ping.
        $this->buffer['new'] = false;
        $data = trim(fgets($this->con['socket']));
        if (!empty($data)) {
            $this->buffer['all'] = $data;
            if(substr($data, 0, 6) == 'PING :') {
                $this->send('PONG :'.substr($data, 6), false);
                if ($this->perform) {
                    $this->perform();                
                }

                return false;
            }

            $this->parse_buffer();
            $this->buffer['new'] = true;
            return true;
        }

        return false;
    }

    function
perform () {
        // actions to be done on connect.
        $this->join($this->CONFIG['chan'], $this->CONFIG['key']);
        $this->perform = false;    
    }
    
    function
printData () {
        //  output the data
        if ($this->buffer['new'] && count($this->buffer['parsed']) > 4) {
            echo date("[H:i:s]") ."{".$this->buffer['parsed']['username']." / ". $this->buffer['parsed']['command'] ." / ". $this->buffer['parsed']['channel'] ."} ". $this->buffer['parsed']['text']. "\n\r";
        }
    }

    function
writeToLog () {
        // Functie waarmee je logs kan maken.
        $file = "C:\web\www\bot2\Logs\\" . $this->buffer['parsed']['channel'] . ".txt";
        $fh = fopen($file, 'a');
        fwrite($fh, date("[H:i:s]") ."{".$this->buffer['parsed']['username']." / ". $this->buffer['parsed']['command'] ." / ". $this->buffer['parsed']['channel'] ."} ". $this->buffer['parsed']['text']. "\n");
        fclose($fh);
    }
    
    function
events () {
        // check which event needs to be triggered, and trigger it.
        if (!empty($this->buffer['parsed']['command'])) {
            if (strtoupper($this->buffer['parsed']['command']) == "PRIVMSG") {
                if (substr(trim($this->buffer['parsed']['text']),0,1) == chr(001)) {
                    $this->onCtcp(trim($this->buffer['parsed']['text']));
                }
elseif (!empty($this->CONFIG['admin']) && strtolower($this->buffer['parsed']['username']) == strtolower($this->CONFIG['admin'])) {
                    $this->onText(trim($this->buffer['parsed']['text']));
                }
            }

            if (strtoupper($this->buffer['parsed']['command']) == "NUMERIC") {
                $this->onNumeric($this->buffer['parsed']['text'], $this->buffer['parsed']['channel'], $this->buffer['parsed']['target']);
            }
    
            if (strtoupper($this->buffer['parsed']['command']) == "NICK") {
                $this->onNick($this->buffer['parsed']['old'], $this->buffer['parsed']['new']);
            }

            if (strtoupper($this->buffer['parsed']['command']) == "JOIN") {
                $this->onJoin($this->buffer['parsed']['username'], $this->buffer['parsed']['channel']);
            }

            if (strtoupper($this->buffer['parsed']['command']) == "PART") {
                $this->onPart($this->buffer['parsed']['username'], $this->buffer['parsed']['channel']);
            }

            if (strtoupper($this->buffer['parsed']['command']) == "MODE" && strtoupper($this->buffer['parsed']['channel']) != strtoupper($this->CONFIG['nick'])) {
                $this->onMode($this->buffer['parsed']['username'], $this->buffer['parsed']['channel'], $this->buffer['parsed']['text']);
            }

            elseif (strtoupper($this->buffer['parsed']['command']) == "MODE" && strtoupper($this->buffer['parsed']['channel']) == strtoupper($this->CONFIG['nick'])) {
                $this->onUserMode($this->buffer['parsed']['username'], $this->buffer['parsed']['text']);
            }
        }
    }
    

    function
setServer ($server, $port = 6667) {
        if (!empty($server)) {
            $this->CONFIG['server'] = $server;
            $this->CONFIG['port'] = $port;
        }
else {
            $this->error("Need valid server adres");
        }
    }

    function
setName ($name = "ZeroBot", $ident = false) {
        $this->CONFIG['nick'] = $name;
        if ($ident) {
            $this->CONFIG['ident'] = $ident . " [Zero bot v". VERSION . " by DaeDaluz]";
        }
    }

    function
setChannel ($chan, $key = "") {
        if (substr($chan,0,1) == "#") {
            $this->CONFIG['chan'] = $chan;
        }
else {
            $this->CONFIG['chan'] = "#" . $chan;
        }

        $this->CONFIG['key'] = $key;
    }

    function
setAdmin ($nick) {
        $this->CONFIG['admin'] = $nick;
    }

    function
error ($error) {
        trigger_error($error, E_USER_ERROR);
    }

    function
send ($data, $output = true) {
        if ($output) {
            echo date("[H:i:s]") ." -> " . $data . "\n";
        }

        fputs($this->con['socket'], $data."\n\r");
    }

    function
connected () {
        if (!feof($this->con['socket'])) {
            return true;
        }
else {
            return false;
        }
    }


    // Make sense of the input data.
    function parse_buffer() {
        $buffer = NUll;
        $this->buffer['parsed'] = Array();
        $buffer = $this->buffer['all'];
        $buffer = explode(" ", $buffer, 4);
        if (count($buffer) >= 3) {
            if (strpos($buffer['0'], "!")) {
                $buffer['username'] = substr($buffer[0], 1, strpos($buffer['0'], "!") - 1);
            }
else {
                $buffer['username'] = substr($buffer[0], 1);
            }

            $posExcl = strpos($buffer[0], "!");
            $posAt = strpos($buffer[0], "@");
            $buffer['identd'] = substr($buffer[0], $posExcl+1, $posAt-$posExcl-1);
            $buffer['hostname'] = substr($buffer[0], strpos($buffer[0], "@")+1);
            $buffer['user_host'] = substr($buffer[0],1);

            switch (strtoupper($buffer[1])) {
                case
"JOIN":
                    $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
                    $buffer['command'] = "JOIN";
                    $buffer['channel'] = $buffer[2];
                    if (substr($buffer['channel'],0,1) == ":") {
                        $buffer['channel'] = substr($buffer['channel'],1);
                    }

                break;
                case
"QUIT":
                    $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
                    $buffer['command'] = "QUIT";
                    $buffer['channel'] = "";
                break;
                case
"NOTICE":
                    $buffer['text'] = substr($buffer[3], 1);
                    $buffer['command'] = "NOTICE";
                    $buffer['channel'] = $buffer[2];
                break;
                case
"PART":
                    $buffer['text'] = $buffer['username']." ( ".$buffer['user_host']." )";
                    $buffer['command'] = "PART";
                    $buffer['channel'] = $buffer[2];
                break;
                case
"MODE":
                    if (substr($buffer[3], 0, 1) == ":") {
                        $buffer['text'] = substr($buffer[3], 1);
                    }
else {
                        $buffer['text'] = $buffer[3];
                    }

                    $buffer['command'] = "MODE";
                    $buffer['channel'] = $buffer[2];
                break;
                case
"NICK":
                    $buffer['text'] = $buffer['username']." => ". $buffer[2]." ( ".$buffer['user_host']." )";
                    $buffer['old'] = $buffer['username'];
                    $buffer['new'] = $buffer[2];
                    $buffer['command'] = "NICK";
                    $buffer['channel'] = "";
                break;
                case
is_numeric($buffer[1]) == true:
                    $buffer['text'] = $buffer[3];
                    $buffer['command'] = "NUMERIC";
                    $buffer['channel'] = $buffer[1];
                    $buffer['target'] = $buffer[2];
                break;
                default:

                    $buffer['command'] = $buffer[1];
                    if (strtoupper($buffer[2]) == strtoupper($this->CONFIG['nick'])) {
                        $buffer['channel'] = $buffer['username'];
                    }
else {
                        $buffer['channel'] = $buffer[2];
                    }

                    $buffer['text'] = substr($buffer[3], 1);
                break;
            }

            $this->buffer['parsed'] = $buffer;
        }
}

    function
meIson ($chan) {
        if (in_array(strtolower($chan), $this->channels)) {
            return true;
        }
else {
            return false;
        }
    }

    function
join ($chan, $key = "") {
        $this->send("JOIN " . $chan . " " . $key);
    }

    function
msg ($chan, $msg) {
            $this->send('PRIVMSG '. $chan .' :'.$msg);
    }

    function
ctcp ($to, $msg) {
        $split = explode(" ", $msg, 2);
        $this->send("NOTICE ". $to ." :" . chr(001) . strtoupper($split[0]) . " " . $split[1] . chr(001));
    }

    function
part ($chan) {
        $this->send("PART " . $chan);
    }

    function
quit ($msg = "Zerobot singing off..") {
        $this->send("QUIT :" . $msg);
    }

    function
mode ($chan, $modes) {
        $this->send("MODE ". $chan . " " . $modes);
    }

    function
Op ($chan, $nick) {
        $this->mode ($chan, "+o " . $nick);
    }

    function
deOp ($chan, $nick) {
        $this->mode ($chan, "-o " . $nick);
    }
    
    function
changeName ($name) {
        $this->send("NICK :" . $name);
    }
    
    function
randomName () {
        $newName = substr($this->CONFIG['nick'],0,3) . rand(1000,9999);
        $this->changeName($newName);
    }
    
    function
storeUsers () {
        $text = $this->buffer['parsed']['text'];
        $exp = explode(" ", $text, 8);
        $exp[0] = strtolower($exp[0]);
        
        if (in_array($exp[0], array_keys($this->usersOnChannel))) {
            $getal = count($this->usersOnChannel[$exp[0]]);
        }
else {
            $getal = 0;
        }

        $this->usersOnChannel[$exp[0]][$getal]['nick'] = $exp[4];
        $this->usersOnChannel[$exp[0]][$getal]['ident'] = $exp[1];
        $this->usersOnChannel[$exp[0]][$getal]['host'] = $exp[2];
        $this->usersOnChannel[$exp[0]][$getal]['info'] = $exp[7];
    }
    
    
    function
ison ($chan, $nick) {
        $chan = strtolower($chan);
        foreach ($this->usersOnChannel[$chan] as $value) {
            if (strtolower($value['nick']) == strtolower($nick)) {
                    return true;
            }
        }

        return false;
    }
    
    function
onMode ($nick, $chan, $modes) {
        $split = explode(" ", $modes);
        $extra = count($split) - 1;
        $extrac = 1;
        $specials = Array("o", "v", "h", "q", "a", "k");
        for ($i = 0; $i < strlen($split[0]); $i++) {
                $value = substr($split[0], $i, 1);
                if ($value == "+") {
                    $temp = true;
                }
elseif ($value == "-") {
                    $temp = false;
                }
else {
                    if ($temp) {
                        $tmp['mode'] = $value;
                        if (in_array($value, $specials) && $extra > 0) {
                            $tmp['ex'] = $split[$extrac];
                            if ($value == "o") {
                                $this->onOp($nick, $chan, $split[$extrac]);
                            }

                            $extrac++;
                        }

                        $plus[] = $tmp;
                    }
else {
                        $tmp['mode'] = $value;
                        if (in_array($value, $specials) && $extra > 0) {
                            $tmp['ex'] = $split[$extrac];
                            if ($value == "o") {
                                $this->onDeop($nick, $chan, $split[$extrac]);
                            }

                            $extrac++;
                        }

                        $min[] = $tmp;
                    }
                }            
        }
    }

    function
onUserMode ($nick, $modes) {
        $split = explode(" ", $modes);
        $extra = count($split) - 1;
        $extrac = 1;
        for ($i = 0; $i < strlen($split[0]); $i++) {
            $value = substr($split[0], $i, 1);
            if ($value == "+") {
                $temp = true;
            }
elseif ($value == "-") {
                $temp = false;
            }
else {
                if ($temp) {
                    foreach ($this->onUserMode as $key => $val) {
                        if ("+" . $value . "" == $val['mode']) {
                            call_user_func(Array(&$this, $val['cmd']));
                            break;
                        }
                    }
                }
else {
                    foreach ($this->onUserMode as $key => $val) {
                        if ("-" . $value . "" == $val['mode']) {
                            call_user_func(Array(&$this, $val['cmd']));
                            break;
                        }
                    }
                }
            }            
        }
    }
    
    function
onNumeric ($text, $numeric) {
        if ($this->buffer['parsed']['target'] != $this->CONFIG['nick'] && $this->buffer['parsed']['target'] != "*") {
            $this->CONFIG['nick'] = $this->buffer['parsed']['target'];
        }

        if ($numeric == '433') {
            $exp = explode(" ", $text);
            if ($exp[0] == $this->CONFIG['nick']) {
                $this->randomName();
            }
        }

        foreach ($this->onNumeric as $key => $val) {
            if ($numeric == $val['numeric']) {
                call_user_func(Array(&$this, $val['cmd']));
                break;
            }
        }
    }
    
    function
onNick ($old, $new) {
        if ($this->buffer['parsed']['old'] == $this->CONFIG['nick']) {
            $this->CONFIG['nick'] = $this->buffer['parsed']['new'];
        }
    }

    function
onOp ($by, $chan, $on) {
        if (strtolower($on) == strtolower($this->CONFIG['nick']) && strtolower($chan) == strtolower($this->CONFIG['chan'])) {
            $this->CONFIG['secured'] = true;
            $this->mode($chan, '+ims');
        }
    }


    function
onDeop ($by, $chan, $on) {
        if (strtolower($on) == strtolower($this->CONFIG['admin']) && strtolower($on) != strtolower($by)) {
            $this->deop($chan, $by);
            $this->op($chan, $on);
        }
    }

    function
onPart($nick, $chan) {
        if (strtoupper($nick) == strtoupper($this->CONFIG['nick'])) {
            if (in_array(strtolower($chan), $this->channels)) {
                $this->channels[] = strtolower($chan);
            }
        }
else {
            if (!empty($chan) && !empty($nick)) {
                if (count($this->onPart) > 0) {
                    foreach ($this->onPart as $key => $val) {
                        $this->JPProcess($val, $key);
                    }
                }
            }
        }
    }

    function
onJoin($nick, $chan) {
        if (strtoupper($nick) == strtoupper($this->CONFIG['nick'])) {
            if (!in_array(strtolower($chan), $this->channels)) {
                $key = Array_search(strtolower($chan), $this->channels);
                unset($this->channels[$key]);
            }
        }

        if (!empty($chan) && !empty($nick)) {
            if (count($this->onJoin) > 0) {
                foreach ($this->onJoin as $key => $val) {
                    $this->JPProcess($val, $key);
                }
            }
        }
    }

    function
JPProcess ($val, $key) {
        if (!empty($val['chan'])) {
            if (is_array($val['chan'])) {
                if (in_array_i($key, $val['chan'])) {
                    $chan_s = true;
                }
else {
                    $chan_s = false;
                }
            }
elseif (strtoupper($val['chan']) == strtoupper($chan)) {
                $chan_s = true;
            }
else {
                $chan_s = false;
            }
        }
else {
            $chan_s = true;
        }

        if (!empty($val['nick'])) {
            $val['nick'] = str_replace("*me", $this->CONFIG['nick'] , $val['nick']);
            if (is_array($val['nick'])) {
                if (in_array_i($this->buffer['parsed']['username'], $val['nick'])) {
                    $nick_s = true;
                }
else {
                    $nick_s = false;
                }
            }
elseif (strtoupper($val['nick']) == strtoupper($this->buffer['parsed']['username'])) {
                $nick_s = true;
            }
else {
                $nick_s = false;
            }
        }
else {
            $nick_s = true;
        }

        if ($nick_s && $chan_s) {
            if (is_array($val['para'])) {
                foreach ($val['para'] as $waarde) {
                    $par = str_replace("*nick", $this->buffer['parsed']['username'] , $waarde);
                    $para[] = str_replace("*chan", $this->buffer['parsed']['channel'] , $par);
                }

                call_user_func_array(Array(&$this, $val['cmd']), $para);
            }
else {
                call_user_func(Array(&$this, $val['cmd']));
            }
        }
    }

    function
onCtcp ($text) {
        if (count($this->onCtcp) > 0) {
            $text = str_replace(chr(001), "", $text);
            $trig = explode(" ", $text, 2);
            $trig = $trig[0];
            $text = $trig[1];
            $word = explode(" ", $text);    
            foreach ($this->onCtcp as $key => $val) {
                if (strtoupper($trig) == strtoupper($val['trigger']) && (count($word) - 1) >= $val['req']) {
                    if (is_array($val['para'])) {
                        foreach ($val['para'] as $sleutell => $par) {
                            $par = str_replace("*fulltime", date("D M j G:i:s Y"), $par);
                            $par = str_replace("*version", VERSION , $par);
                            $par = str_replace("*nick", $this->buffer['parsed']['username'] , $par);
                            $par = str_replace("*time", date('H:i:s') , $par);
                            $para[] = $par;
                        }

                        call_user_func_array(Array(&$this, $val['cmd']), $para);
                    }
else {
                        call_user_func(Array(&$this, $val['cmd']));
                    }

                    break;
                }
            }
        }
    }

    function
tokenRep ($string, $zin) {
        preg_match_all("*\*[0-9]{1,2}\-*", $string, $output, PREG_SET_ORDER);
        foreach ($output as $value) {
            $val = str_replace("*", "", $value[0]);
            $val = str_replace("-", "", $val);
            settype($val, "int");
            $split = explode(" ", $zin, $val);
            if (!empty($split[$val -1])) {
                $string = str_replace($value[0], $split[$val -1], $string);
            }
        }

        preg_match_all("*\*[0-9]{1,2}*", $string, $output, PREG_SET_ORDER);
        foreach ($output as $value) {
            $val = str_replace("*", "", $value[0]);
            settype($val, "int");
            $split = explode(" ", $zin);
            if (!empty($split[$val - 1])) {
                $string = str_replace($value[0], $split[$val - 1], $string);
            }
        }

        return $string;
    }

    function
onText ($text) {
        if (count($this->onText) > 0) {
            $word = explode(" ", $text);
            $trig = explode(" ", $text, 2);
            foreach ($this->onText as $key => $val) {
                if (strtoupper($word[0]) == strtoupper($val['trigger']) && (count($word) - 1) >= $val['req']) {
                    if (is_array($val['para'])) {
                        foreach ($val['para'] as $sleutel => $waarde) {
                            if (count($trig) < 2) {
                                break;
                            }
else {
                                $val['para'][$sleutel] = $this->tokenRep($waarde, $trig[1]);
                            }
                        }

                        foreach ($val['para'] as $sleutell => $par) {
                            $par = str_replace("*fulltime", date("D M j G:i:s Y"), $par);
                            $par = str_replace("*version", VERSION , $par);
                            $par = str_replace("*nick", $this->buffer['parsed']['username'] , $par);
                            $par = str_replace("*time", date('H:i:s') , $par);
                            $para[] = str_replace("*chan", $this->buffer['parsed']['channel'] , $par);
                        }

                        call_user_func_array(Array(&$this, $val['cmd']), $para);
                    }
else {
                        call_user_func(Array(&$this, $val['cmd']));
                    }

                    break;
                }
            }
        }
    }

    function
newOnText ($trigger, $cmd, $reqPar = 0, $para = "") {
        if (is_callable(array('ZeroBot', $cmd))) {
            if (!empty($trigger)) {
                if (is_int($reqPar)) {
                    $getal = count($this->onText);
                    $this->onText[$getal]['trigger'] = $trigger;
                    $this->onText[$getal]['cmd'] = $cmd;
                    $this->onText[$getal]['req'] = $reqPar;
                    $this->onText[$getal]['para'] = $para;
                }
else {
                    $this->error("The number of required parameters must be an INT");
                }
            }
else {
                $this->error("Trigger required");
            }
        }
else {
            $this->error("Not callable function! :" . $cmd);
        }
    }

    function
newOnCtcp ($trigger, $cmd, $reqPar = 0, $para = "") {
        if (is_callable(array('ZeroBot', $cmd))) {
            if (!empty($trigger)) {
                if (is_int($reqPar)) {
                    $getal = count($this->onCtcp);
                    $this->onCtcp[$getal]['trigger'] = $trigger;
                    $this->onCtcp[$getal]['cmd'] = $cmd;
                    $this->onCtcp[$getal]['req'] = $reqPar;
                    $this->onCtcp[$getal]['para'] = $para;
                }
else {
                    $this->error("The number of required parameters must be an INT");
                }
            }
else {
                $this->error("Trigger required");
            }
        }
else {
        $this->error("Not callable function! :" . $cmd);
        }
    }

    function
newOnJoin ($cmd, $para = "", $nick = "", $chan = "") {
        if (is_callable(array('ZeroBot', $cmd))) {
            if (is_array($para)) {
                $getal = count($this->onJoin);
                $this->onJoin[$getal]['cmd'] = $cmd;
                $this->onJoin[$getal]['para'] = $para;
                $this->onJoin[$getal]['nick'] = $nick;
                $this->onJoin[$getal]['chan'] = $chan;
            }
else {
                $this->error("Parameters must be in array format!");
            }
        }
else {
            $this->error("Not callable function! :" . $cmd);
        }
    }

    function
newOnPart ($cmd, $para = "", $nick = "", $chan = "") {
        if (is_callable(array('ZeroBot', $cmd))) {
            if (is_array($para)) {
                $getal = count($this->onPart);
                $this->onPart[$getal]['cmd'] = $cmd;
                $this->onPart[$getal]['para'] = $para;
                $this->onPart[$getal]['nick'] = $nick;
                $this->onPart[$getal]['chan'] = $chan;
            }
else {
                $this->error("Parameters must be in array format!");
            }
        }
else {
            $this->error("Not callable function! :" . $cmd);
        }
    }

    function
newOnUserMode ($mode, $cmd) {
        if (is_callable(array('ZeroBot', $cmd))) {
            $getal = count($this->onUserMode);
            $this->onUserMode[$getal]['mode'] = $mode;
            $this->onUserMode[$getal]['cmd'] = $cmd;
        }
else {
            $this->error("Not callable function! :" . $cmd);
        }
    }

    function
newOnNumeric ($numeric, $cmd) {
        if (is_callable(array('ZeroBot', $cmd))) {
            $getal = count($this->onNumeric);
            $this->onNumeric[$getal]['numeric'] = $numeric;
            $this->onNumeric[$getal]['cmd'] = $cmd;
        }
else {
            $this->error("Not callable function! :" . $cmd);
        }
    }
}

function
in_array_i($search, &$array) {
  $search = strtolower($search);
  foreach ($array as $item)
    if (strtolower($item) == $search)
        return TRUE;
  return FALSE;
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.