-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.php
115 lines (109 loc) · 3.43 KB
/
bot.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
#!/usr/bin/php -q
<?php
function bot() {
include("Config.php");
include("Functions.php");
include("Cache.php");
$Readbuffer = "";
$Running = FALSE;
//Command list
$Commands = Command_List($Removed_Commands);
$Admin_Commands = Admin_Command_List($Removed_Commands);
//Refresh Cache Database
Cache_Initiate($db);
while(1) {
if (!$fp) {
//echo $errstr." (".$errno.")\n";
$fp = fsockopen($Host, $Port, $Erno, $Errstr, 30);
}
else {
// write data through the socket to join the channel
fwrite($fp, "NICK ".$Nick."\r\n");
fwrite($fp, "USER ".$Ident." ".$Host." bla :".$RealName."\r\n");
fwrite($fp, "PRIVMSG NickServ :IDENTIFY " .$Password. "\r\n");
foreach($Channels as $Channel) {
fwrite($fp, "JOIN :".$Channel."\r\n");
}
foreach($Part_Channels as $Channel) {
fwrite($fp, "PART :".$Channel."\r");
}
// loop through each line to look for ping
while (!feof($fp)) {
$Line = split("[ ]+", fgets($fp, 1024));
$Username = split("!", str_replace(":", "", $Line[0]));
if (isset($Line[1]) && $Line[1] == "PRIVMSG") {
$Command = str_replace(":", "", str_replace($Admin_Prefix, "", str_replace($User_Prefix, "", trim($Line[3]))));
$Command1 = preg_split("//", $Line[3]);
if ($Line[2] == $Nick) {
$Chan = $Username[0];
}
else {
$Chan = $Line[2];
}
if ($Command1[2] == $User_Prefix) {
if ($Commands[$Command] == 1) {
require("Commands/".$Command.".php");
}
elseif ($Command == "source") {
fwrite($fp, "PRIVMSG ".$Line[2]." :Here you go " .$Source_Code. "\r\n");
}
}
elseif ($Command1[2] == $Admin_Prefix) {
if ($Admin_Commands[$Command] == 1) {
if (in_array($Username[1], $Admins)) {
require("Commands/Admin/".$Command.".php");
}
elseif ($Command == "login") {
require("Commands/Admin/".$Command.".php");
}
else {
fwrite($fp, "PRIVMSG ".$Username[0]." :Admin Only.\r\n");
}
}
}
}
elseif (isset($Line[1]) && $Line[1] == "QUIT") {
if (in_array($Username[1], $Admins)) {
unset($Admins[$Username[0]]);
print_r($Admins);
}
Cache_Quit(trim($Username[0]), $db);
}
elseif (isset($Line[1]) && $Line[1] == "JOIN") {
$Channel = split(":", $Line[2]);
if (in_array(trim($Channel[1]), $Auto_Voice_Channels)) {
fwrite($fp, "MODE " .trim($Channel[1]). " +v " .trim($Username[0]). "\r\n");
}
if (in_array(trim($Channel[1]), $Auto_OP_Channels)) {
fwrite($fp, "MODE " .trim($Channel[1]). " +o " .trim($Username[0]). "\r\n");
}
if ($Username != $Nick) {
Cache_Join(trim($Username[0]), trim($Channel[1]), $db);
}
}
elseif (isset($Line[1]) && $Line[1] == "PART") {
Cache_Part(trim($Username[0]), trim($Channel[1]), $db);
}
elseif (isset($Line[1]) && $Line[1] == 332) {
Cache_Channel($Line, $db);
}
elseif (isset($Line[1]) && $Line[1] == 353) {
Cache_Who($Line, $db);
}
elseif (isset($Line[1]) && $Line[1] == "NICK") {
Cache_Nick(trim($Username[0]), trim($Line[2]), $db);
}
elseif (isset($Line[1]) && $Line[1] == "KICK") {
Cache_Kick(trim($Username[0]), trim($Line[2]), $db);
}
elseif ($Line[0] == "PING") {
fwrite($fp, "PONG ".$Line[1]."\r\n");
}
else {
}
}
}
}
}
fclose($fp);
?>