-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlizardbot.php
2209 lines (2179 loc) · 87.3 KB
/
lizardbot.php
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/php
<?php
error_reporting(E_ALL & ~E_NOTICE);
$cmdcount = 0;
$pingcount = 0;
$ctcpcount = 0;
$aicount = 0;
$insultcount = 0;
$fishcount = 0;
echo "Determining what configuration file we should use...\r\n";
$dir = $_SERVER['argv'][1];
$cfg = FALSE;
if(!$dir) {
$dir = 'lizardbot.conf.php';
$cfg = TRUE;
}
if($cfg) {
echo "{$c_green}Will use the default configuration file, {$dir}{$c_n}\r\n";
} else {
echo "{$c_green}Will use the user-specified config file {$dir}{$c_n}\r\n";
}
echo "Loading essential config files...\r\n";
$rehash = TRUE;
require("default.conf.php");
require($dir);
$rehash = FALSE;
//Load hasPriv function
function hasPriv($priv) {
global $privgroups, $users, $d, $setIsOnWindows, $setUsePCREs;
$parsed = $d[0];
foreach( $users as $user => $group ) {
if($setUsePCREs || $setIsOnWindows) {
if($user == "*!*@*") continue;
if( preg_match( $user, $parsed/*['n!u@h']*/ ) ) {
if( isset( $privgroups[$group][$priv] ) ) {
return $privgroups[$group][$priv];
} else {
return 0;
}
}
} elseif (!$setUsePCREs && !$setIsOnWindows) {
if( fnmatch( $user, $parsed/*['n!u@h']*/ ) ) {
if( isset( $privgroups[$group][$priv] ) ) {
return $privgroups[$group][$priv];
} else {
return 0;
}
}
}
}
$d[0] = $parsed;
}
echo "OK!\r\n";
if(!$setIsOnWindows) {
$c_n = chr(27) . "[0m";
$c_dark = chr(27) . "[01;90m";
$c_red = chr(27) . "[01;91m";
$c_green = chr(27) . "[01;92m";
$c_yellow = chr(27) . "[01;93m";
$c_blue = chr(27) . "[01;94m";
$c_pink = chr(27) . "[01;95m";
$c_cyan = chr(27) . "[01;96m";
$c_bold = chr(27) . "[01;1m";
$c_ul = chr(27) . "[01;4m";
$c_b_dark = chr(27) . "[01;5m";
$c_b_light = chr(27) . "[01;7m";
$c_b_red = chr(27) . "[01;41m";
$c_b_green = chr(27) . "[01;42m";
$c_b_yellow = chr(27) . "[01;43m";
$c_b_blue = chr(27) . "[01;44m";
$c_b_pink = chr(27) . "[01;45m";
$c_b_cyan = chr(27) . "[01;46m";
$c_b_light_bold = chr(27) . "[01;47m";
}
echo $c_green;
?>
*******************************************************************************
_ _______ _________ __________ _______ ____
| | |__ __||_______/ /| _______ | | |___| | | || \
| | | | / / | | | | | |___| | | | | |
| | | | / / | |______| | | |___|_| | | | | BOT
| |___ __| |__ ___/ /__ | |______| | | | \ \ | |_| |
|_____||_______| |________||_| |_| |_| \__\ |____/
-=- http://fastlizard4.org/wiki/LizardBot -=-
LizardBot for PHP: IRC bot developed by FastLizard4 (who else?) and the LizardBot Development Team
Version 7.3.0.0b (major.minor.build.revision) BETA
Licensed under the General Public License 2.0 (GPL) or later at your option
For licensing details, contact me or read this page:
http://creativecommons.org/licenses/GPL/2.0/
*Report bugs to BugZilla at http://fastlizard4.org/bugzilla/
*You may also report issues or submit your own patches at GitHub:
https://github.com/FastLizard4/LizardBot-PHP
LICENSING DETAILS:
LizardBot for PHP (IRC bot) written by FastLizard4 and the LizardBot Development Team
Copyright (C) 2008-2013 FastLizard4 and the LizardBot Development Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A human-readable version of the complete license is available at
http://creativecommons.org/licenses/GPL/2.0/
The full text of the license can be found here:
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
PandoraBot extension courtesy of Ttech (PHP-5 OOP)
*************************************************************************************
<?php
//Check for updates
echo "{$c_yellow}Checking for updates...\r\n";
$version = "7.3.0.0b";
$upfp = @fopen('http://fastlizard4.org/w/index.php?title=LizardBot/Latest&action=raw', 'r');
$data = @fgets($upfp);
@fclose($upfp);
if(!$data) {
echo "{$_bold}Check for updates failed!{$c_n}\r\n";
}
if($data == $version) {
echo "{$c_green}>>>>You have the stable latest version, {$version}<<<<{$c_n}\r\n";
} else {
echo "{$c_red}>>>>You do not have the latest version, {$data}<<<<{$c_n}\r\n";
echo "{$c_red}This could mean that you're running an older version, or a newer\r\n";
echo "not yet stable version....{$c_n}\r\n";
}
/**********************************************
BEGIN PANDORABOT
**********************************************/
echo "Loading pandorabot extension...\r\n";
// *PHP 5* ONLY
class pandorabot {
public $botid;
public $_Pipe; // This will be our cURL handle in a bit
public $timout = 50;
public $default_response = "Probably"; // Use the function to set this.
private $path_url = "http://www.pandorabots.com/pandora/talk?botid="; // So we can easily change url if needed
// private $path_url = "http://localhost/~fastlizard4/blank.html";
/* Sanity Checking Function */
public function pandorabot($botid=""){
/* Run all init and such now. */
$botid = trim($botid);
if(isset($botid)){
// Init Curl
$this->_Pipe = curl_init();
curl_setopt($this->_Pipe, CURLOPT_URL, $this->path_url.$botid);
curl_setopt($this->_Pipe, CURLOPT_POST, 1);
curl_setopt($this->_Pipe, CURLOPT_RETURNTRANSFER, 1);
}
}
public function default_response($response=""){
/* Check to see if $response is set otherwise we return the default */
if(isset($response)){
// Check to make sure new response is actually there
if(!$this->sanitize($response) == FALSE){
$this->default_response = $this->sanitize($response); // Set response
}
} else {
// No new response set, return the already set one.
return $this->default_response;
}
}
public function say($user_input){
$name = "input"; // Used to submit the form post
$input = $this->sanitize($user_input);
// Stupid debug stuff
// echo $this->timeout."<br />";
curl_setopt($this->_Pipe, CURLOPT_TIMEOUT, $this->timout);
curl_setopt ($this->_Pipe, CURLOPT_POSTFIELDS, "Name=$name&input=$input");
curl_setopt ($this->_Pipe, CURLOPT_FOLLOWLOCATION, 1);
$reply = curl_exec($this->_Pipe);
if(isset($reply) && !preg_match('/^\s*$/', $reply)){
return $this->get_say($reply);
} elseif(!isset($reply) || preg_match('/^\s*$/', $reply)) {
return $this->default_response;
}
curl_close($this->_Pipe);
}
public function set_timeout($int){
if(!is_int($int)){
$this->timeout = 60;
return FALSE;
} else {
$this->timeout = $int;
return TRUE;
}
}
private function sanitize($string){
$string = trim(str_replace("\n", "", stripslashes(html_entity_decode($string))));
if(!empty($string)){
return $string;
} else { // Nothing is returned, return false
return FALSE;
}
}
private function get_say($input, $tag='font'){
// Do a little regex to get the bot reply
$pattern = "#<$tag color=\"\\w+\">(.*?)</$tag>#";
$var = preg_match($pattern, $input, $matches);
$result = $this->sanitize($matches[1]); // Get outout and send for validation
/* Simple Sanity Check - Null */
if($result == FALSE OR empty($result)){
return $this->default_response();
} else {
return $result; // Return valid string.
}
}
}
echo "Pandorabot class loaded!\r\n";
echo "Preparing fishb0t module...\r\n";
$fishCresponses = array
(
'/hampster/i' => '%n: There is no \'p\' in hamster you retard.',
'/vinegar.*aftershock/i' => 'Ah, a true connoisseur!',
'/aftershock.*vinegar/i' => 'Ah, a true connoisseur!',
'/^some people are being fangoriously devoured by a gelatinous monster$/i'
=> 'Hillary\'s legs are being digested.',
'/^ag$/i' => 'Ag, ag ag ag ag ag AG AG AG!',
'/^(fishbot|%f) owns$/i' => 'Aye, I do.',
'/vinegar/i' => 'Nope, too sober for vinegar. Try later.',
'/martian/i' => 'Don\'t run! We are your friends!',
'/^just then, he fell into the sea$/i'
=> 'Ooops!',
'/aftershock/i' => 'mmmm, Aftershock.',
'/^why are you here\?$/i' => 'Same reason. I love candy.',
'/^spoon$/i' => 'There is no spoon.',
'/^(bounce|wertle)$/i' => 'moo',
'/^crack$/i' => 'Doh, there goes another bench!',
'/^you can\'t just pick people at random!$/i'
=> 'I can do anything I like, %n, I\'m eccentric! Rrarrrrrgh! Go!',
'/^flibble$/i' => 'plob',
'/(the fishbot has created splidge|fishbot created splidge)/i'
=> 'omg no! Think I could show my face around here if I was responsible for THAT?',
'/^now there\'s more than one of them\?$/i'
=> 'A lot more.',
'/^i want everything$/i' => 'Would that include a bullet from this gun?',
'/we are getting aggravated/i' => 'Yes, we are.',
'/^how old are you, (fishbot|%f)\?$/i'
=> chr(1).'ACTION is older than time itself!'.chr(1),
'/^atlantis$/i' => 'Beware the underwater headquarters of the trout and their bass henchmen. From there they plan their attacks on other continents.',
'/^oh god$/i' => 'fishbot will suffice.',
'/^(fishbot|%f)$/i' => 'Yes?',
'/^what is the matrix\?$/i' => 'No-one can be told what the matrix is. You have to see it for yourself.',
'/^what do you need\?$/i' => 'Guns. Lots of guns.',
'/^i know kungfu$/i' => 'Show me.',
'/^cake$/i' => 'fish',
'/^trout go m[o0][o0]$/i' => 'Aye, that\'s cos they\'re fish.',
'/^kangaroo$/i' => 'The kangaroo is a four winged stinging insect.',
'/^sea bass$/i' => 'Beware of the mutant sea bass and their laser cannons!',
'/^trout$/i' => 'Trout are freshwater fish and have underwater weapons.',
'/has returned from playing counterstrike/i'
=> 'like we care fs :(',
'/^where are we\?$/i' => 'Last time I looked, we were in %c.',
'/^where do you want to go today\?$/i'
=> 'anywhere but redmond :(.',
'/^fish go m[o0][o0]$/i' => chr(1).'ACTION notes that %n is truly enlightened.'.chr(1),
'/^(.*) go m[o0][o0]$/i' => '%n: only when they are impersonating fish.',
'/^fish go (.+)$/i' => '%n LIES! Fish don\'t go %1! fish go m00!',
'/^you know who else (.*)$/i' => '%n: YA MUM!',
'/^if there\'s one thing i know for sure, it\'s that fish don\'t m00\.?$/i'
=> '%n: HERETIC! UNBELIEVER!',
'/^(fishbot|%f): muahahaha\. ph33r the dark side\. :\)$/i'
=> '%n: You smell :P',
'/^ammuu\?$/i' => '%n: fish go m00 oh yes they do!',
'/^fish$/i' => '%n: fish go m00!',
'/^snake$/i' => 'Ah snake a snake! Snake, a snake! Ooooh, it\'s a snake!',
'/^carrots handbags cheese$/i' => 'toilets russians planets hamsters weddings poets stalin KUALA LUMPUR! pygmies budgies KUALA LUMPUR!',
'/sledgehammer/i' => 'sledgehammers go quack!',
'/^badger badger badger badger badger badger badger badger badger badger badger badger$/i'
=> 'mushroom mushroom!',
'/^moo\?$/i' => 'To moo, or not to moo, that is the question. Whether \'tis nobler in the mind to suffer the slings and arrows of outrageous fish...',
'/^herring$/i' => 'herring(n): Useful device for chopping down tall trees. Also moos (see fish).',
'/www\.outwar\.com/i' => 'would you please GO AWAY with that outwar rubbish!',
'/^god$/i' => 'Sometimes the garbage disposal gods demand a spoon.',
'/stupid bot[!?.]*$/i' => '%n: Stupid human.',
'/fail bot[!?.]*$/i' => '%n: Fail human.',
'/good bot[!?.]*$/i' => chr(1).'ACTION purrs at %n'.chr(1),
'/^I am the Doctor,? and you are the Daleks!?$/i' => 'WE ARE THE DALEKS!! Exterminate! EXTEEERRRRMIIINAAAATE!',
'/^ping$/i' => 'pong',
'/^pong$/i' => 'pang',
'/^pang$/i' => 'pung',
'/^pung$/i' => 'derp'
);
$fishAresponses = array
(
'/hampster/i' => '%n: There is no \'p\' in hamster you retard.',
'/^feeds (fishbot|%f) hundreds and thousands$/i'
=> 'MEDI.. er.. FISHBOT',
'/(vinegar.*aftershock|aftershock.*vinegar)/i'
=> 'Ah, a true connoisseur!',
'/vinegar/i' => 'Nope, too sober for vinegar. Try later.',
'/martians/i' => 'Don\'t run! We are your friends!',
'/aftershock/i' => 'mmmm, Aftershock.',
'/(the fishbot has created splidge|fishbot created splidge)/i'
=> 'omg no! Think I could show my face around here if I was responsible for THAT?',
'/we are getting aggravated/i' => 'Yes, we are.',
'/^strokes (fishbot|%f)$/i' => chr(1).'ACTION m00s loudly at %n.'.chr(1),
'/^slaps (.*) around a bit with a large trout$/i'
=> 'trouted!',
'/has returned from playing counterstrike/i'
=> 'like we care fs :(',
'/^fish go m[o0][o0]$/i' => chr(1).'ACTION notes that %n is truly enlightened.'.chr(1),
'/^(.*) go m[o0][o0]$/i' => '%n: only when they are impersonating fish.',
'/^fish go (.+)$/i' => '%n LIES! Fish don\'t go %1! fish go m00!',
'/^you know who else (.*)$/i' => '%n: YA MUM!',
'/^thinks happy thoughts about pretty (.*)$/i'
=> chr(1).'ACTION has plenty of pretty %1. Would you like one %n?'.chr(1),
'/^snaffles a (.*) off (fishbot|%f).?$/i'
=> ':(',
'/stupid bot[!?.]*$/i' => '%n: Stupid human.',
'/fail bot[!?.]*$/i' => '%n: Fail human.',
'/good bot[!?.]*$/i' => chr(1).'ACTION purrs at %n'.chr(1),
'/^ping$/i' => 'pong',
'/^pong$/i' => 'pang',
'/^pang$/i' => 'pung',
'/^pung$/i' => 'derp'
);
echo "Fishb0t module readied! FISH GO M00 OH YES THEY DO! [citation needed]\r\n";
/**********************************************
END PANDORABOT
**********************************************/
$rehash = FALSE;
function tr(&$var) {
$var = trim($var);
}
if($setIsOnWindows) {
echo "Will skip signal handlers, we're running on Windows...\r\n";
} else {
echo "Preparing signal handlers...\r\n";
declare(ticks = 1);
function SIGHUP() {
global $users, $privgroups, $dir;
echo "-!- Caught SIGHUP (1), now rehasing\r\n";
$rehash = TRUE;
require("default.conf.php");
include($dir);
if($setMySQLTablePre) {
$setMySQLTablePre .= "_";
}
$rehash = FALSE;
echo "-!- Rehash complete.\r\n";
}
function SIGTERM() {
global $c_n, $c_red;
// die();
global $ircc, $irc;
fwrite($ircc, "QUIT :Oh noes! :O Caught deadly signal 15 SIGTERM!!\r\n");
echo <<<IRCO
{$c_red}-!- QUIT :Oh noes! :O Caught deadly signal 15 SIGTERM!!\n
*** DISCONNECTING FROM {$irc['address']}!\n
IRCO;
fclose($ircc);
die("Caught SIGTERM!\n{$c_n}");
}
function SIGINT() {
global $c_n, $c_red;
global $ircc, $irc;
fwrite($ircc, "QUIT :Oh noes! :O Caught deadly SIGINT (^C) from terminal!!!\r\n");
echo <<<IRCO
{$c_red}-!- QUIT :Oh noes! :O Caught deadly SIGINT!!\n
*** DISCONNECTING FROM {$irc['address']}!\n
IRCO;
fclose($ircc);
die("Caught SIGINT!\n{$c_n}");
}
echo "Initializing Signal Handlers...\r\n";
// setup signal handlers
pcntl_signal(SIGHUP, "SIGHUP");
pcntl_signal(SIGTERM, "SIGTERM");
pcntl_signal(SIGINT, "SIGINT");
echo "Success!\r\n";
}
//PHP Bot for FastLizard4
echo "Welcome to the interface for LizardBot-1!\r\n";
echo "Determining what configuration file we should use...\r\n";
$dir = $_SERVER['argv'][1];
$cfg = FALSE;
if(!$dir) {
$dir = 'lizardbot.conf.php';
$cfg = TRUE;
}
if($cfg) {
echo "{$c_green}Will use the default configuration file, {$dir}{$c_n}\r\n";
} else {
echo "{$c_green}Will use the user-specified config file {$dir}{$c_n}\r\n";
}
echo "Loading essential config files...\r\n";
require("default.conf.php");
require($dir);
echo "OK!\r\n";
echo "Verifying required settings are present...\r\n";
if(!$users) {
die("{$c_red}Users array missing.{$c_n}\r\n");
}
if(!$privgroups) {
die("{$c_red}Privgroups array missing.{$c_n}\r\n");
}
if(!$nickname) {
die("{$c_red}Default nickname missing from config file.{$c_n}\r\n");
}
if(!$setTrigger) {
$setTrigger = "@";
}
if(!$setEnableMySQL) {
echo "{$c_yellow}MySQL and all commands requiring MySQL are disabled.{$c_n}\r\n";
}
if($setEnableMySQL) {
echo "{$c_green}MySQL support enabled!{$c_n}\r\n";
if(!$setMySQLHost) {
die("{$c_red}MySQL database server address not specified (\$setMySQLHost)!{$c_n}\r\n");
} elseif(!$setMySQLPort) {
echo "{$c_yellow}No port for connecting to the MySQL server specified, will use\r\n";
echo "default of 3306...{$c_n}\r\n";
$setMySQLPort = 3306;
} elseif(!$setMySQLUserName) {
die("{$c_red}No MySQL database connection username specified!{$c_n}\r\n");
} elseif(!$setMySQLPassword) {
echo "{$c_yellow}Really? No password for connecting to MySQL specified.\r\n";
echo "If none is needed, you're doing it wrong....{$c_n}\r\n";
} elseif(!$setMySQLDB) {
die("{$c_red}No MySQL database to use specified in the config file!{$c_n}\r\n");
}
if($setMySQLTablePre) {
$setMySQLTablePre .= "_";
}
}
echo "Creating the MySQL-related functions....\r\n";
if(!$setEnableMySQL) {
echo "You might be wondering why this is happening even though MySQL\r\n";
echo "is disabled. The functions are being created so that you can\r\n";
echo "enable MySQL support while the bot is running without crashing\r\n";
echo "the bot. However, before you try to do this (enable MySQL\r\n";
echo "support while the bot is running), make sure that you have read\r\n";
echo "the MySQL documentation on the wiki *COMPLETELY*, or bad stuff\r\n";
echo "*WILL* happen.\r\n";
}
function dbConnect() {
global $setMySQLHost, $setMySQLPort, $setMySQLUserName, $setMySQLPassword, $setMySQLDB;
$mysql = mysqli_connect($setMySQLHost, $setMySQLUserName, $setMySQLPassword, $setMySQLDB, $setMySQLPort) OR
print("{$c_red}Failed to connect to the MySQL server! Details:\r\n" .
mysqli_connect_error() . "{$c_n}\r\n");
return $mysql;
}
function mkSane($mysql, $data) {
return trim(mysqli_real_escape_string($mysql, $data));
}
function dbQuery($mysql, $query, &$result) {
$result = mysqli_query($mysql, $query);
if(!$result) {
echo "\r\nERROR: An error occured in the database query:\r\n";
echo "\t" . $query . "\r\n";
echo "MySQL returned the following error:\r\n";
echo "\t" . mysqli_error($mysql) . "\r\n";
return "An error occured in the MySQL database query. Please check the console for details.";
} else {
return false;
}
}
if($setEnableMySQL) {
echo "Verifying connection to MySQL database....";
$mysql = dbConnect();
if(!mysql) {die();}
mysqli_close($mysql);
echo "{$_green} done!{$c_n}\r\n";
}
if(!$setBitlyAPISleep || !is_int($setBitlyAPISleep)) {
$setBitlyAPISleep = 30;
}
if(!$timezone) {
echo <<<EOD
{$c_red}WARNING! You did not specify a time zone! This means you are using
the timezone being used by your computer or in your PHP configuration file. It
is strongly recommended that you set the timezone using the \$timezone variable in
your LizardBot configuration file! You have been warned!{$c_n}\r\n
EOD;
} else {
date_default_timezone_set($timezone);
}
echo "OK!";
if($autoconnect['enabled']) {
echo <<<EOD
\r\n{$c_yellow}ATTENTION! Autoconnect directives are enabled in your configuration file!\r\n
The bot will begin autoconnecting in 7 seconds... press ^C NOW if you do not want this to happen!{$c_n}\r\n
EOD;
sleep(7);
}
echo <<<CONSOLEOUTPUT
\n{$c_bold}Please enter the FULL address of the network you wish to join.\r\n
Specify it as address:port. If no port is specified, 6667 is used.\r\n
{$c_ul}For example: irc.myircnetwork.com:8001 (REQUIRED):
CONSOLEOUTPUT;
if($autoconnect['enabled'] && $autoconnect['network']) {
$irc['address'] = $autoconnect['network'];
if(stristr($irc['address'], ":")) {
$temp = explode(":", $irc['address']);
$irc['address'] = $temp[0];
$irc['port'] = $temp[1];
}
} elseif($autoconnect['enabled'] && !$autoconnect['network']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no network was given in config file.{$c_n}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$irc['address']) {
$irc['address'] = fgets(STDIN);
tr($irc['address']);
if(stristr($irc['address'], ":")) {
$temp = explode(":", $irc['address']);
$irc['address'] = $temp[0];
$irc['port'] = $temp[1];
}
}
}
if(!$irc['address']) {
die("${c_red}No address given.{$c_n}\r\n");
}
//$nick = $setNick;
echo <<<EOD
{$c_n}{$c_green}Input of "{$irc['address']}" received!{$c_n}\r\n
{$c_bold}Please enter the desired nickname for your bot. If you enter "." and strike
enter, the default (in brackets) will be used\r\n
{$c_ul}Nickname [$nickname]:
EOD;
if($autoconnect['enabled'] && $autoconnect['nick']) {
$nick = $autoconnect['nick'];
} elseif($autoconnect['enabled'] && !$autoconnect['nick']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickname was given in config file.{$c_n}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$nick) {
fscanf(STDIN, "%s", $nick);
}
}
if($nick == ".") {
$nick = $nickname;
echo <<<EOD
{$c_n}{$c_green}No nickname received, using default of $nickname.{$c_n}\r\n
EOD;
} else {
echo <<<EOD
{$c_n}{$c_green}Input of {$nick} received, using that as our nick.{$c_n}\r\n
EOD;
}
echo <<<EOD
{$c_bold}Now checking validity of the nickname using standard regex tests...\r\n
EOD;
if(!preg_match('/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/', $nick)) {
echo <<<EOD
{$c_n}{$c_red}The regex does not match the nick, meaning that the IRC daemon of the server
you are attempting to connect to would likely reject your registration signal.
Please restart the program and select a valid nick.\r\n
A valid nick is: First character is any letter A-Z or a-z, all other characters
up to 12 can be A-Z, a-z, 0-9, _, -, or ^.\r\n
EOD;
die($c_n);
}
echo <<<EOD
{$c_ul}Should I send identification information to NickServ? (yes/no, default no):
EOD;
if($autoconnect['enabled'] && $autoconnect['identify']) {
$irc['identify'] = $autoconnect['identify'];
} elseif($autoconnect['enabled'] && !$autoconnect['identify']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no id mode was given in the config file.{$c_n}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$irc['identify']) {
fscanf(STDIN, "%s", $irc['identify']);
}
}
switch ($irc['identify']) {
case "yes":
case "y":
echo "{$c_n}{$c_green}OK, will send identification info to NickServ.{$c_n}\r\n";
$irc['get-ident'] = true;
$irc['identify'] = true;
break;
case "no":
case "n":
default:
echo "{$c_n}{$c_green}OK, will not send identification info to NickServ.${c_n}\r\n";
$irc['get-ident'] = false;
$irc['identify'] = false;
break;
}
if(!$setNSUsername) {
$irc['default-ns'] = " ";
} else {
$irc['default-ns'] = " [$setNSUsername]: ";
}
if($irc['get-ident']) {
echo <<<EOD
{$c_bold}You will shortly be requested to enter the primary nickname of your account.
Note that this is only usable on Atheme, and cannot be used with other daemons,
such as Anope to the point that identification will fail. It is recommended
you use this function with Atheme to guarantee your bot correctly identifies.\r\n
To send the default (if present), enter "." and strike enter. To send NO
primary username, enter "#" and strike enter. Otherwise, enter the username
you would like to use and strike enter.\r\n
Please note that this is not the same as the bot nickname.\r\n
{$c_ul}OK, what is the primary username on the account?{$irc['default-ns']}
EOD;
if($autoconnect['enabled'] && $autoconnect['id-nick']) {
$NSUsername = $autoconnect['id-nick'];
} elseif($autoconnect['enabled'] && !$autoconnect['id-nick']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickserv username is in the config file.{$c_white}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$NSUsername) {
fscanf(STDIN, "%s", $NSUsername);
}
}
if($NSUsername == ".") {
$irc['ns-username'] = $setNSUsername . " ";
echo <<<EOD
{$c_n}{$c_green}No input received, using default {$setNSUsername}.{$c_n}\r\n
EOD;
} elseif($NSUsername == "#") {
echo <<<EOD
{$c_n}{$c_green}"#" received, will not send a username to NickServ.{$c_n}\r\n
EOD;
$irc['ns-username'] = NULL;
} else {
$irc['ns-username'] = $NSUsername . " ";
echo <<<EOD
{$c_n}{$c_green}Input of {$NSUsername} received, using that to identify.{$c_n}\r\n
EOD;
}
echo <<<EOD
{$c_bold}You will now be prompted to enter the NickServ password. Please note that THE
PASSWORD IS NOT SAVED and it will be VISIBLE IN THE CONSOLE IN CLEAR TEXT, but
should disappear when it leaves the screen buffer. For this reason, you should
make sure any files containg a shell log should only be readable by you and
only priveleged others.\r\n
IF YOU DO NOT WANT TO ENTER A PASSWORD AND ABORT IDENTIFICATION, ENTER "." AND
STRIKE ENTER AT THIS PROMPT.\r\n
{$c_ul}OK, what is the password?
EOD;
if($autoconnect['enabled'] && $autoconnect['id-pass']) {
$NSPassword = $autoconnect['id-pass'];
} elseif($autoconnect['enabled'] && !$autoconnect['id-pass']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickserv password was given in config.{$c_n}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$NSPassword) {
fscanf(STDIN, "%s", $NSPassword);
}
}
if($NSPassword == ".") {
echo "{$c_n}{$c_yellow}No input received, WILL NOT IDENTIFY!\r\n";
$irc['identify'] = false;
} else {
$irc['ns-password'] = $NSPassword;
unset($NSPassword);
echo "{$c_n}{$c_green}Input received, using that to identify.\r\n";
$irc['identify'] = true;
}
unset($autoconnect['id-pass']); //For security purposes
}
/*foreach($irc as $key => $val) {
echo "$key => $val\r\n";
}*/
echo <<<CONSOLEOUTPUT
{$c_n}Attempting to connect to "{$irc['address']}"...\n
Now commencing connection process...\n
Opening socket...\n
CONSOLEOUTPUT;
$n = 0;
$open = false;
//$fp = array();
while(!$open) {
if(isset($fp[$n])) {
$n++;
} else {
$open = true;
if(!$irc['port']) { $irc['port'] = 6667; }
// echo $irc . "\r\n";
try {
if(!$fp[$n] = fsockopen($irc['address'], $irc['port'], $error, $error2, 15)) {
if(stristr($error2, "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.")) {
$error2 .= "(Connection Timed Out)";
}
throw new Exception("Could not open socket! (ERRNO: 1)\r\nTechnical details:\r\nE1: $error\r\nE2: $error2");
}
} catch (Exception $e) {
echo "{$c_red}Could not connect because: " . $e->getMessage() . "\n";
die($c_n);
}
echo <<<CONSOLEOUTPUT
Socket to {$irc['address']} opened on port {$irc['port']}...\n
Socket ID is: $n\n
-!- CONNECTING TO {$irc['address']}:{$irc['port']} ...\n
CONSOLEOUTPUT;
echo <<<STDOUT
Sleeping for 5 seconds to make sure we are connected before registering...\r\n
STDOUT;
sleep(5);
}
}
if(!$setIdent) $setIdent = "bot";
if(!$setGecos) $setGecos = "bot";
if($fp[$n]) {
$connected = false;
for($i = 1; $i <=2; $i++) {
global $fp;
fwrite($fp[$n], "USER $setIdent bot bot :$setGecos\r\n");
echo <<<IRCO
-!- USER $setIdent bot bot :$setGecos\r\n
IRCO;
fwrite($fp[$n], "NICK $nick\r\n");
echo <<<IRCO
-!- NICK $nick\r\n
IRCO;
if($i == 1) {
echo "Waiting 2 seconds before resending registration for good measure...\r\n";
sleep(2);
}
}
}
if($irc['identify']) {
echo "Waiting 2 seconds before sending identification information to make sure we're registered...\r\n";
sleep(2);
fwrite($fp[$n], "PRIVMSG NickServ :IDENTIFY " . $irc['ns-username'] . $irc['ns-password'] . "\r\n");
echo <<<IRCO
*** ID INFO SENT\r\n
IRCO;
$irc['ns-username'] = NULL;
}
echo "Waiting 5 seconds to make sure we're all good to begin the sync process...\r\n";
sleep(5);
if($setAutoModes) {
echo "Now setting usermode(s) +{$setAutoModes} on myself...\r\n";
fwrite($fp[$n], "MODE {$nick} +{$setAutoModes}\r\n");
}
echo <<<CONSOLEOUTPUT
\n{$c_ul}Please enter a comma-delimited list of channels to join:
CONSOLEOUTPUT;
if($autoconnect['enabled'] && $autoconnect['channels']) {
$irc['channels'] = $autoconnect['channels'];
} elseif($autoconnect['enabled'] && !$autoconnect['channels']) {
die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no channels were specified in config file.{$c_n}\r\n");
} elseif(!$autoconnect['enabled']) {
while(!$irc['channels']) {
fscanf(STDIN, "%s", $irc['channels']);
}
}
echo <<<CONSOLEOUTPUT
{$c_n}{$c_green}Input of "{$irc['channels']}" received!{$c_n}\n
Joining...\n
CONSOLEOUTPUT;
$uptime['start'] = time();
$irc['channels'] = explode(",", $irc['channels']);
foreach($irc['channels'] AS $channel) {
fwrite($fp[$n], "JOIN $channel\r\n");
echo <<<IRCO
-!- JOIN $channel\n
IRCO;
}
$ircc = $fp[$n];
$delimiter = "@";
/*foreach($irc['channels'] AS $channel) {
fwrite($ircc, "PRIVMSG $channel :LizardBot is now online!! :DD\r\n");
}*/
echo <<<IRCO
*** Sent join messages\n
IRCO;
while(!feof($fp[$n])) {//While connected to IRC...
/* if(fscanf(STDIN, "%s", $irc['command']) == 1) {
//if($irc['command']) {
fwrite($ircc, "{$irc['command']}\r\n");
echo "{$irc['command']}\n";
echo <<<CONSOLEOUTPUT
Input of "{$irc['command']}" received!\n
CONSOLEOUTPUT;
} */
$toRead = array($ircc, $ircc);
$toWrite = NULL;
$toExcept = NULL;
$toTimeout = 15;
if(stream_select($toRead, $toWrite, $toExcept, $toTimeout) || $setEnableDelays) {
$data = str_replace(array("\n", "\r"), '', fgets($ircc, 1024));
echo $data . "\n";
} else {
$data = NULL;
}
$data2 = str_replace(":", "", $data);
$data3 = str_replace("$$", ":", $data2);
$d = explode(' ', $data3);
$c = $d[2];
if(!$muted) {
if($d[3] == "{$setTrigger}test"&& hasPriv('*')) {
$cmdcount++;
fwrite($ircc, "PRIVMSG $c :OLOL!\r\n");
echo <<<IRCO
-!- PRIVMSG #lobby :OLOL!\n
IRCO;
}
if($d[3] == "{$setTrigger}die" && hasPriv('die')) {
$cmdcount++; // 9_9
if(true) {
fwrite($ircc, "QUIT :Ordered to death by {$d[0]}!\r\n");
echo <<<IRCO
{$c_red}-!- QUIT :Ordered to death!\n
*** DISCONNECTING FROM {$irc['address']}!\n
IRCO;
fclose($ircc);
die("Terminated!\n{$c_n}");
} else {
// fwrite($ircc, "NOTICE $c :*** WARNING: (PING FastLizard4) {$d[0]} ({$d[2]}) attempted to kill me!\r\n");
echo <<<IRCO
*** @die access violation logged!\n
IRCO;
}
}
if(hasPriv('say')) {
if($d[3] == "{$setTrigger}say") {
$cmdcount++;
if($d[2] != $nick) {
$ndata = explode(":{$setTrigger}say ", $data);
$rdata = $ndata[1];
fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
echo <<<IRCO
-!- PRIVMSG $c :$rdata\n
IRCO;
} else {
$kdata = explode(":{$setTrigger}say ", $data);
$cdata = $kdata[1];
$ndata = explode(" ", $cdata);
$c = $ndata[0];
$ndata[0] = NULL;
$rdata = trim(implode(" ", $ndata));
fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
echo <<<IRCO
-!- PRIVMSG $c :$rdata\n
IRCO;
}
}
}
if(hasPriv('do')) {
if($d[3] == "{$setTrigger}do") {
$cmdcount++;
if($d[2] != $nick) {
$ndata = explode(":{$setTrigger}do ", $data);
$ddata = $ndata[1];
$rdata = chr(001) . "ACTION $ddata" . chr(001);
fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
echo <<<IRCO
-!- CTCP $c ACTION $rdata\n
IRCO;
} else {
$kdata = explode(":{$setTrigger}do ", $data);
$cdata = $kdata[1];
$ndata = explode(" ", $cdata);
$c = $ndata[0];
$ndata[0] = NULL;
$ddata = implode(" ", $ndata);
$me = trim($ddata);
$rdata = trim(chr(001) . "ACTION $me" . chr(001));
fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
echo <<<IRCO
-!- CTCP $c ACTION $rdata\n
IRCO;
}
}
}
if($d[3] == "{$setTrigger}join" && hasPriv('join')) {
$cmdcount++;
fwrite($ircc, "JOIN {$d[4]}\r\n");
fwrite($ircc, "PRIVMSG {$d[4]} :{$d[0]} has ordered me to join the channel.\r\n");
echo <<<IRCO
-!- JOIN {$d[4]}\n
IRCO;
}
if($d[3] == "{$setTrigger}part" && hasPriv('part')) {
$cmdcount++;
fwrite($ircc, "PART {$d[4]} :Ordered to death by {$d[0]}!\r\n");
echo <<<IRCO
-!- PART {$d[4]}\n
IRCO;
}
if(hasPriv('notice')) {
if($d[3] == "{$setTrigger}notice") {
$cmdcount++;
if($d[2] != $nick) {
$ndata = explode(":{$setTrigger}notice ", $data);
$rdata = $ndata[1];
fwrite($ircc, "NOTICE $c :$rdata\r\n");
echo <<<IRCO
-!- NOTICE $c :$rdata\n
IRCO;
} else {
$kdata = explode(":{$setTrigger}notice ", $data);
$cdata = $kdata[1];
$ndata = explode(" ", $cdata);
$c = $ndata[0];
$ndata[0] = NULL;
$rdata = implode(" ", $ndata);
fwrite($ircc, "NOTICE $c :$rdata\r\n");
echo <<<IRCO
-!- NOTICE $c :$rdata\n
IRCO;
}
}
}
if($d[3] == "{$setTrigger}raw" && hasPriv('raw')) {
$cmdcount++;
if(true) {
$kdata = explode("{$setTrigger}raw ", $data);
$rdata = $kdata[1];
fwrite($ircc, "$rdata\r\n");
echo <<<IRCO
-!- MANUAL RAW COMMAND ISSUED BY {$d[0]}: $rdata\n
IRCO;
} else {
fwrite($ircc, "PRIVMSG $c :Access denied.\r\n");
echo <<<IRCO
PRIVMSG $c :Access denied.\r\n
IRCO;
}
}
if($d[0] == 'PING') {
$pingcount++;
fwrite($ircc, "PONG {$d[1]}\r\n");
echo <<<IRCO
PONG {$d[1]}\n
IRCO;
}
if($d[3] == "{$setTrigger}fap" && hasPriv('fap')) {
$cmdcount++;
if(!$d[4]) {
$who = explode("!", $d[0]);
$who2 = $who[0];
} else {
$who2 = $d[4];
}
fwrite($ircc, "PRIVMSG $c :Ceiling_Cat is watching $who2 masturbate\r\n");
echo <<<IRCO
PRIVMSG $c :Ceiling_Cat is watching $who2 masturbate\n
IRCO;
}
if(hasPriv('op')) {
if($d[3] == "{$setTrigger}kick") {
$cmdcount++;
//$data1 = explode("{$setTrigger}kick ", $data);
if($d[2] != $nick) {
$kdata = explode(":{$setTrigger}kick ", $data);
$cdata = $kdata[1];
$ndata = explode(" ", $cdata);
$target = $ndata[0];
$ndata[0] = NULL;
$comment = implode(" ", $ndata);
} else {
$kdata = explode(":{$setTrigger}kick ", $data);
$cdata = $kdata[1];
$ndata = explode(" ", $cdata);
$c = $ndata[0];
$target = $ndata[1];
$ndata[0] = NULL;
$ndata[1] = NULL;
$comment = implode(" ", $ndata);
}
fwrite($ircc, "KICK $c $target :$comment\r\n");
echo <<<IRCO
-!- KICK $c $target :$comment\n
IRCO;
}
}
if($d[3] == "{$setTrigger}op" && hasPriv('op')) {
$cmdcount++;
fwrite($ircc, "PRIVMSG ChanServ :OP $c\r\n");
echo <<<IRCO
PRIVMSG ChanServ :OP $c\n
IRCO;
}
if($d[3] == "{$setTrigger}deop" && hasPriv('op')) {
$cmdcount++;
fwrite($ircc, "MODE $c -o {$nick}\r\n");
echo <<<IRCO
MODE $c -o LizardBot-1\n
IRCO;
}
if($d[3] == chr(001) . "VERSION" . chr(001)) {
$ctcpcount++;
$target = explode("!", $d[0]);