Config require f("config.php"); // -> Components require f("internal/components/c-damn.php"); include f("internal/components/c-modules.php"); include f("internal/components/c-users.php"); include f("internal/components/c-fnorder.php"); // -> Functions include f("internal/includes/functions.php"); // -> Informations include f("internal/informations/variables.php"); // OK! LET'S GO! :D $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); global $socket; // Get general dAmn functions and methods $dAmn = new dAmn; $dAmn->init(); // Get user functions and methods and load the users $user = new users(); $user->load(); // Connect! socket_connect($socket, $serverinfo['addr'], $serverinfo['port']); include f("internal/includes/load.php"); $dAmn->startup(); foreach($settings['rooms'] as $room){ $dAmn->joinRoom($room); } $dAmn->pingpong(); $loop = 0; $onceconnected = false; // MAIN WHILE LOOP while($running){ $loop++; if($loop == 150){ $dAmn->pingpong(); $lastping = time(); $loop = 0; } // IF WE GOT DISCONNECTED if(!$dAmn->connected){ internalMessage($seperator); if($onceconnected){ internalMessage("We got disconnected!"); } else { internalMessage("Couldn't get entirely connected."); } // Okay let's see why this happened. debugDisconnection(); $running = false; } else { $onceconnected = true; } include f("execute.txt"); file_put_contents(f("execute.txt"),""); //sleep(1); } // REORGANIZE FROM HERE SOME DAY PLZ ------------------------------------------------------------------------------------- function f($file){ // Internal file link global $homedirectory; $dir = (empty($homedirectory)) ? realpath(".") : $homedirectory; $wtf = false; if((str_replace("/", "", $file) != $file) && (str_replace("/", "", $dir) == $dir) && (str_replace("\\", "", $dir) != $dir)){ $fslash = false; } elseif((str_replace("\\", "", $file) != $file) && (str_replace("\\", "", $dir) == $dir) && (str_replace("/", "", $dir) != $dir)){ $fslash = true; } elseif($dir{0} == "/"){ $fslash = true; } elseif($dir{0} == "\\"){ $fslash = false; } elseif(preg_match("@[A-Za-z]" . preg_quote(":\\") . "@", substr($dir, 0, 3))){ $fslash = false; } elseif(preg_match("@[A-Za-z]" . preg_quote(":/") . "@", substr($dir, 0, 3))){ $fslash = true; } else { $wtf = true; } if(!$wtf){ if($fslash){ $dir = (empty($homedirectory)) ? realpath(".") . "/" : $homedirectory; $file = str_replace("\\", "/", $file); } else { $dir = (empty($homedirectory)) ? realpath(".") . "\\" : $homedirectory; $file = str_replace("/", "\\", $file); } } else { $dir = (empty($homedirectory)) ? realpath(".") . "/" : $homedirectory; $file = str_replace("\\", "/", $file); } return $dir . $file; } function intF($file){ f($file); } // Old name. For those who haven't converted yet, will not be in the final version. // PROCESS MESSAGE function processMessage($message, $from, $chatroom, $msgtype){ global $dAmn, $botinfo, $user, $settings; if(!empty($message) && !empty($from) && !empty($chatroom)){ $c = $chatroom; $f = $from . ": "; // If it doesn't say what type it is, it's probably an ordinary message. if(empty($msgtype)){ $msgtype = "msg"; } if($from == $botinfo['username']){ return false; } // Strip out the bot to prevent loops. if(!$user->has($from, 2)){ return; } // Strip out banned users who are at level 1. // AI $namePart = substr($message, 0, strlen($botinfo['username']) + 1); if($namePart == $botinfo['username'] . ":" || $namePart == $botinfo['username'] . ","){ $aiMessage = trim(substr($message, strlen($botinfo['username']) + 1)); $awayStr = "I am currently away. Reason:"; if(substr($aiMessage, 0, strlen($awayStr)) == $awayStr){ return false; } // Preventing answer to a dAmn.extend away message. if($aiMessage == "trigcheck"){ $dAmn->say($f . $botinfo['triggerchar'], $c); } else { if($settings['ai'] == true){ $response = file_get_contents("http://tarball.24bps.com/files/programe/src/letstalk.php?u=" . $from . "&m=" . base64_encode($aiMessage)); $dAmn->say($f . $response, $c); } } return true; } // Kick it to command parser if it's a command if($message{0} == $botinfo['triggerchar']){ parseCommand($message, $from, $chatroom, $msgtype); } return true; } else { return false; } } // PARSE COMMAND function parseCommand($message, $from, $chatroom, $msgtype){ global $dAmn, $botinfo, $settings, $version, $versionstate, $user, $events, $whoisroom, $latestwhois, $modules; if($from == $botinfo['username']){ return false; } // Preparing variables; returning $commandname and $arguments $command = substr($message, 1); $command = explode(" ", $command); $arguments = $command; $commandname = strtolower($command[0]); unset($arguments[0]); unset($command); $argumentsF = implode(" ", $arguments); $c = $chatroom; $f = $from . ": "; $tr = $botinfo['triggerchar']; switch($commandname){ // TO THE INDIVIDUAL COMMANDS! THIS WILL BE WAAAYY REORGANIZED INTO MODULES LATER. // -> Only type the commandname in lowercase, or else it will never work! // BASIC COMMANDS case "join": if(!$user->has($from, 99)){ break; } if(!empty($arguments[1])){ $chatroom = generateChatName($arguments[1]); $x = $dAmn->joinRoom($chatroom); if(!$x){ $dAmn->say($f . "Uh oh, something failed down there.", $c); } } else { $dAmn->say($f . "You've got to type a room for me to join, please.", $c); } break; case "part": if(!$user->has($from, 99)){ break; } if(!empty($arguments[1])){ $chatroom = generateChatName($arguments[1]); } else { $chatroom = $c; } $x = $dAmn->partRoom($chatroom); if(!$x){ $dAmn->say($f . "Uh oh, something failed down there.", $c); } break; case "say": if(!$user->has($from, 75)){ break; } echo "-> A10: " . $arguments[1]{0} . "\n"; if($arguments[1]{0} == "#"){ $room = generateChatName($arguments[1]); $textToSayA = explode(" ", implode(" ", $arguments), 3); echo "-> TEXTA: "; var_dump($textToSayA); $textToSay = $textToSayA[1]; echo "-> ROOM: " . $room . "\n-> TEXT: " . $textToSay . "\n"; $dAmn->say($textToSay, $room); } else { $dAmn->say($argumentsF, $c); } break; case "title": case "topic": if(!$user->has($from, 75)){ break; } if(empty($argumentsF)){ // Get $dAmn->say($f . "There'll be some \"THE TITLE/TOPIC IS CURRENTLY ...\" blabber here later when I get to it.", $c); } else { // Set $dAmn->set($commandname, $argumentsF, $c); // There will be something fancier later. // -> NOTE TO SELF // Fancier = add-end, add-start, replace:XXX,YYYYY } break; case "kick": if(!$user->has($from, 75)){ break; } if(empty($arguments[1])){ $dAmn->say($f . "Please say who to kick.", $c); break; } $person = $arguments[1]; if(!empty($arguments[2])){ if($arguments[2]{0} == "#" || substr($arguments[2], 0, 5) == "chat:"){ // We'll guess second argument is a room. $room = generateChatName($arguments[2]); if(!empty($arguments[3])){ // We'll guess that we have a room and then a reason served. $reasonA = explode(" ", implode(" ", $arguments), 3); $reason = $reasonA[2]; } } else { // We'll guess second argument is a (part of a) reason. $reasonA = explode(" ", implode(" ", $arguments), 3); $reason = $reasonA[1]; } } if(empty($room)){ $room = $c; } $dAmn->kick($person, $room, $reason); break; case "promote": // NOTE TO SELF: This needs improving so you can include a chatname smartly too. case "demote": if(!$user->has($from, 75)){ break; } if(empty($arguments[1])){ $dAmn->say($f . "Please say who to " . $commandname . ".", $c); break; } $person = $arguments[1]; $privclass = $arguments[2]; switch($commandname){ case "promote": $dAmn->promote($person, $privclass, $c); break; case "demote": $dAmn->demote($person, $privclass, $c); break; } break; case "ban": case "unban": if(!$user->has($from, 75)){ break; } if(empty($arguments[1])){ $dAmn->say($f . "Please say who to " . $commandname . ".", $c); break; } $person = $arguments[1]; if(!empty($arguments[2])){ $room = generateChatName($arguments[2]); } switch($commandname){ case "ban": $dAmn->ban($person, $room); break; case "unban": $dAmn->unban($person, $room); break; } break; case "admin": if(!$user->has($from, 99)){ break; } if($arguments[2]{0} == "#" || substr($arguments[2], 0, 5) == "chat:"){ // We'll guess first argument is a room. $room = $arguments[2]; $commandA = explode(" ", implode(" ", $arguments), 3); // And the rest is the /admin command. $command = $commandA[1]; } else { // Okay, it's all an /admin command for the current room then $command = $argumentsF; $room = $c; } $dAmn->admin($command, $room); break; case "whois": if(!empty($arguments[1])){ $whoisroom = $chatroom; $dAmn->getUserInfo($arguments[1]); } else { $dAmn->say("Please type a username to lookup.", $c); } break; // OTHER COMMANDS -- WILL BE MADE MODULES SOON. case "about": $say = $settings['about']; $say = str_replace("%V%", $version . " " . $versionstate, $say); $say = str_replace("%TR%", $tr, $say); $say = str_replace("%O%", $botinfo['owner'], $say); $say = str_replace("%BN%", $botinfo['username'], $say); $dAmn->say($say, $c); break; case "autoresponse": $ars = unserialize(file_get_contents(f("ars.bsv"))); if(!(file_get_contents(f("ars.bsv")))){ $ars = array(); } $broke = false; switch($arguments[1]){ case "add": if(!$user->has($from, 75)){ $broke = true; break; } $textToAddA = explode(" ", implode(" ", $arguments), 3); $textToAdd = $textToAddA[2]; if(!empty($arguments[2]) && !empty($textToAddA[2])){ $ars[$arguments[2]]['val'] = $textToAdd; $ars[$arguments[2]]['by'] = $from; $ars[$arguments[2]]['ts'] = time(); $dAmn->say($f . "Added!", $c); } else { $dAmn->say($f . "You need to type a name and a value.", $c); } break; case "remove": if(!$user->has($from, 75)){ break; $broke = true; } if(!empty($arguments[2])){ unset($ars[$arguments[2]]); $dAmn->say($f . "Removed!", $c); } else { $dAmn->say($f . "You need to type a name.", $c); } break; case "list": if(count($ars) <= 0){ $dAmn->say($f . "There haven't been posted any autoresponses yet.", $c); } else { $msg = ":postit: Autoresponses:
users.bsv file and restart the bot. This will delete all your users!", $c);
}
} else {
$dAmn->say($f . "That privclass didn't exist.", $c);
}
} else {
$dAmn->say($f . "That is a reserved privclass, you cannot delete this.", $c);
}
} else {
$dAmn->say($f . "You need to type a privclass you want to remove.