<commit_before><?php
/*
 *  botOS by Birkhoff (http://b.irkhoff.com)
 *  https://github.com/BirkhoffLee/botOS
 *
 *  ==License
 *  This script open to everybody,
 *  you can change everything in 
 *  this script, BUT DO NOT REMOVE 
 *  THE AUTHOR'S NAME AND URL!
 *  ==End License
 *
*/
$startTime = microtime(true);
$root = dirname(__FILE__) . DIRECTORY_SEPARATOR;
define('DEBUG', false);
set_time_limit(0);
ini_set('display_errors', 'on');
if(DEBUG == true){
    error_reporting(E_ALL);
} else {
    error_reporting(0);
}
header("Content-type: text/html; charset=utf-8");
require 'config.php';

class botOS {
        var $socket;
        var $data;
        var $serverMessages;
        var $SayName;
        var $SayCMD;
        var $SayTarget;
        var $SayContent;
        var $shutup = false;
        var $standby = false;
        var $disableBlock;
        var $arguments;
        var $extraDir;

        public function __construct(){
            global $config;
        	$this->Submitlog("botOS by Birkhoff Version {$config['version']} Started.");
            $this->Submitlog("=============================================");
            $this->Submitlog("Server: {$config['server']}:{$config['port']}");
            $this->Submitlog("Bot name: {$config['nick']}");
            $this->Submitlog("Channel: {$config['channel']}");
            $this->Submitlog("Admin: {$config['admin']}");
            $this->Submitlog("=============================================");
            echo '<script type="text/javascript">function pageScroll(){window.scrollBy(0,3000);scrolldelay = setTimeout(\'pageScroll()\',100);}pageScroll();</script>';
            $this->socket = fsockopen($config['server'], $config['port']);
            $this->send_data('USER ' . $config['nick'] . ' b.irkhoff.com ' . $config['nick'] . ' :' . $config['name']);
            $this->send_data('NICK ' . $config['nick']);
            $this->send_data('JOIN ' . $config['channel']);
            $this->extraDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cmd' . DIRECTORY_SEPARATOR . 'extra' . DIRECTORY_SEPARATOR;
            $this->main();
        }

        public function Submitlog($log){
        	global $config;
            print('[' . date("Y-m-d H:i:s", mktime(date("H")+8, date("i"), date("s"), date("m"), date("d"), date("Y"))) . "] : $log <br />");
            ob_flush();
            flush();
            usleep(750);
        }

        public function main(){
        		global $config;
                $this->data = str_replace("\r\n", '', trim(fgets($this->socket, 256)));

                if(!isset($this->data) or $this->data == null or $this->data == ''){
					self::main();
				}

                if(strpos($this->data, 'Nickname is already in use.') !== false){
                	self::Submitlog("Received ServerMessage -> <strong><span style='color:#3b5998'>{$this->data}</span></strong>");
                	self::Submitlog('<strong>登入失敗：上次登入 Session 尚未過期或暱稱被盜用。</strong>');
                	exit;
                }

                $checkChating = explode(' ', $this->data);
                if(@$checkChating[1] != 'PRIVMSG'){
                    // 非聊天階段
                    self::_serv_msg();
                } else {
                    // 聊天階段
                    global $config;
        			self::_parse();
                    
                    if(!isset($this->SayName) or !isset($this->SayTarget) or !isset($this->SayUID) or !isset($this->SayContent) or $this->SayName == '' or $this->SayTarget == '' or $this->SayUID == '' or $this->SayContent == ''){
                    	// 資料錯誤
                    	self::Submitlog("<span style='color:red'><strong>Error with parsing data information!</strong></span>");
                    }

                    self::Submitlog("<strong>[CHAT] {$this->SayName}</strong>: {$this->SayContent}");
                    self::_process_chat();
            	}
                usleep(780);
                self::main();
        }

        private function _process_chat(){
            $arguments = @explode(' ', str_replace('   ', ' ', str_replace('  ', ' ', $this->SayContent)));
            $cmd = @str_replace("\\", '', str_replace('/', '', str_replace('.', '', str_replace('~', '', trim($arguments[0])))));
            $cmdDir = @dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cmd' . DIRECTORY_SEPARATOR;
            if(@$cmd != 'index'){
                if(filter_var($this->SayContent, FILTER_VALIDATE_URL)){
                    if(strpos($this->SayContent, '://goo.gl/')!==false){
                        include($this->extraDir . 'google_short_expand.php');
                    }
                    @include($this->extraDir . 'title_process.php');
                } elseif(substr($this->SayContent, 0, 1) == '~'){
                    global $config;
                    self::Submitlog('<strong>命令被解析: ' . $cmd . '</strong>');
                    if($this->SayName == $config['admin']){
                        $cmdFileName = $cmdDir . 'admin' . DIRECTORY_SEPARATOR . $cmd . '.php';
                        $this->arguments = $arguments;
                        if(file_exists($cmdFileName)){
                            include($cmdFileName);
                        }
                    }
                    if($this->shutup == false or $cmd == 'shutup'){
                        $cmdFileName = $cmdDir . 'user' . DIRECTORY_SEPARATOR . $cmd . '.php';
                        $this->arguments = $arguments;
                        if(file_exists($cmdFileName)){
                            include($cmdFileName);
                        }
                    }
                } else {
                    self::_reply();
                }
            }
        }

        private function _serv_msg(){
        	if($this->data != '' and $this->data != null and $this->data != ' '){
        		global $config;
            	self::Submitlog("Received ServerMessage -> <strong><span style='color:#3b5998'>{$this->data}</span></strong>");
            	if(stripos($this->data, 'End of /NAMES list') !== false and $this->standby == false){
            		$this->standby = true;
                	self::say('Bot 連線成功', 'Notice');
                	self::say('[System] botOS ' . $config['version'] . ' is up.', 'Information', $config['admin']);
            	} elseif(substr($this->data, 0, 6) === 'PING :'){
                    $this->send_data(str_replace('PING :', 'PONG :', $this->data));
                } elseif(stripos($this->data, ' JOIN ' . $config['channel'])!==false){
                	$nameTemp = explode('!', $this->data);
                	$name = str_replace(':', '', $nameTemp[0]);
                    $ip = explode('@', $this->data);
                    $ip = explode(' ', $ip[1]);
                    $ip = $ip[0];
                    $query = @unserialize(file_get_contents('http://ip-api.com/php/' . $ip));
                    if($query && $query['status'] == 'success' && $name != $config['nick'] && $query['country']!='' && $query['city'] != '') {
                        self::say('好久不見，來自 ' . $query['country'] . '-' . $query['city'] . ' 的 ' . $name . '!');
                    } elseif(strpos($this->data, 'gateway/')!==false){
                    	$ip = explode('ip.', $this->data);
                    	$ip = explode(' ', $ip[1]);
                    	$ip = $ip[0];
                    	$query = @unserialize(file_get_contents('http://ip-api.com/php/' . $ip));
                    	if($query && $query['status'] == 'success' && $name != $config['nick'] && $query['country']!='' && $query['city'] != '') {
                        	self::say('好久不見，來自 ' . $query['country'] . '-' . $query['city'] . ' 的 ' . $name . '!');
                    	}
                    } elseif($name != $config['nick']){
                        self::say('好久不見，' . $name . '!');
                    }
                }
            }
        }

        private function _title_url_process(){
            $url = $this->SayContent;
            $urlParse = parse_url($url);
            if(isset($urlParse['query'])){
                $query = '?' . $urlParse['query'];
            } else {
                $query = '';
            }
            $url = $urlParse['scheme'] . '://' . $urlParse['host'] . $urlParse['path'] . $query;
            ini_set("user_agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
            if($str = file_get_contents($this->SayContent)){
                $titleTemp = explode('<title', $str);
                $titleTemp = explode('>', $titleTemp[1]);
                $titleTemp = explode('<', $titleTemp[1]);
                $urlTemp = explode('\\', str_replace('https://', '', str_replace('http://', '', $this->SayContent)));
                if(strpos($urlTemp[0], '/')!==false){
                    $temp = explode('/', $urlTemp[0]);
                    $host = $temp[0];
                }
                self::say("[ {$titleTemp[0]} ] - $host", 'Default');<commit_msg>Skip error<commit_after><?php
/*
 *  botOS by Birkhoff (http://b.irkhoff.com)
 *  https://github.com/BirkhoffLee/botOS
 *
 *  ==License
 *  This script open to everybody,
 *  you can change everything in 
 *  this script, BUT DO NOT REMOVE 
 *  THE AUTHOR'S NAME AND URL!
 *  ==End License
 *
*/
$startTime = microtime(true);
$root = dirname(__FILE__) . DIRECTORY_SEPARATOR;
define('DEBUG', false);
set_time_limit(0);
ini_set('display_errors', 'on');
if(DEBUG == true){
    error_reporting(E_ALL);
} else {
    error_reporting(0);
}
header("Content-type: text/html; charset=utf-8");
require 'config.php';

class botOS {
        var $socket;
        var $data;
        var $serverMessages;
        var $SayName;
        var $SayCMD;
        var $SayTarget;
        var $SayContent;
        var $shutup = false;
        var $standby = false;
        var $disableBlock;
        var $arguments;
        var $extraDir;

        public function __construct(){
            global $config;
        	$this->Submitlog("botOS by Birkhoff Version {$config['version']} Started.");
            $this->Submitlog("=============================================");
            $this->Submitlog("Server: {$config['server']}:{$config['port']}");
            $this->Submitlog("Bot name: {$config['nick']}");
            $this->Submitlog("Channel: {$config['channel']}");
            $this->Submitlog("Admin: {$config['admin']}");
            $this->Submitlog("=============================================");
            echo '<script type="text/javascript">function pageScroll(){window.scrollBy(0,3000);scrolldelay = setTimeout(\'pageScroll()\',100);}pageScroll();</script>';
            $this->socket = fsockopen($config['server'], $config['port']);
            $this->send_data('USER ' . $config['nick'] . ' b.irkhoff.com ' . $config['nick'] . ' :' . $config['name']);
            $this->send_data('NICK ' . $config['nick']);
            $this->send_data('JOIN ' . $config['channel']);
            $this->extraDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cmd' . DIRECTORY_SEPARATOR . 'extra' . DIRECTORY_SEPARATOR;
            $this->main();
        }

        public function Submitlog($log){
        	global $config;
            print('[' . date("Y-m-d H:i:s", mktime(date("H")+8, date("i"), date("s"), date("m"), date("d"), date("Y"))) . "] : $log <br />");
            ob_flush();
            flush();
            usleep(750);
        }

        public function main(){
        		global $config;
                $this->data = str_replace("\r\n", '', trim(fgets($this->socket, 256)));

                if(!isset($this->data) or $this->data == null or $this->data == ''){
					self::main();
				}

                if(strpos($this->data, 'Nickname is already in use.') !== false){
                	self::Submitlog("Received ServerMessage -> <strong><span style='color:#3b5998'>{$this->data}</span></strong>");
                	self::Submitlog('<strong>登入失敗：上次登入 Session 尚未過期或暱稱被盜用。</strong>');
                	exit;
                }

                $checkChating = explode(' ', $this->data);
                if(@$checkChating[1] != 'PRIVMSG'){
                    // 非聊天階段
                    self::_serv_msg();
                } else {
                    // 聊天階段
                    global $config;
        			self::_parse();
                    
                    if(!isset($this->SayName) or !isset($this->SayTarget) or !isset($this->SayUID) or !isset($this->SayContent) or $this->SayName == '' or $this->SayTarget == '' or $this->SayUID == '' or $this->SayContent == ''){
                    	// 資料錯誤
                    	self::Submitlog("<span style='color:red'><strong>Error with parsing data information!</strong></span>");
                    }

                    self::Submitlog("<strong>[CHAT] {$this->SayName}</strong>: {$this->SayContent}");
                    self::_process_chat();
            	}
                usleep(780);
                self::main();
        }

        private function _process_chat(){
            $arguments = @explode(' ', str_replace('   ', ' ', str_replace('  ', ' ', $this->SayContent)));
            $cmd = @str_replace("\\", '', str_replace('/', '', str_replace('.', '', str_replace('~', '', trim($arguments[0])))));
            $cmdDir = @dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cmd' . DIRECTORY_SEPARATOR;
            if(@$cmd != 'index'){
                if(filter_var($this->SayContent, FILTER_VALIDATE_URL)){
                    if(strpos($this->SayContent, '://goo.gl/')!==false){
                        include($this->extraDir . 'google_short_expand.php');
                    }
                    @include($this->extraDir . 'title_process.php');
                } elseif(substr($this->SayContent, 0, 1) == '~'){
                    global $config;
                    self::Submitlog('<strong>命令被解析: ' . $cmd . '</strong>');
                    if($this->SayName == $config['admin']){
                        $cmdFileName = $cmdDir . 'admin' . DIRECTORY_SEPARATOR . $cmd . '.php';
                        $this->arguments = $arguments;
                        if(file_exists($cmdFileName)){
                            include($cmdFileName);
                        }
                    }
                    if($this->shutup == false or $cmd == 'shutup'){
                        $cmdFileName = $cmdDir . 'user' . DIRECTORY_SEPARATOR . $cmd . '.php';
                        $this->arguments = $arguments;
                        if(file_exists($cmdFileName)){
                            include($cmdFileName);
                        }
                    }
                } else {
                    self::_reply();
                }
            }
        }

        private function _serv_msg(){
        	if($this->data != '' and $this->data != null and $this->data != ' '){
        		global $config;
            	self::Submitlog("Received ServerMessage -> <strong><span style='color:#3b5998'>{$this->data}</span></strong>");
            	if(stripos($this->data, 'End of /NAMES list') !== false and $this->standby == false){
            		$this->standby = true;
                	self::say('Bot 連線成功', 'Notice');
                	self::say('[System] botOS ' . $config['version'] . ' is up.', 'Information', $config['admin']);
            	} elseif(substr($this->data, 0, 6) === 'PING :'){
                    $this->send_data(str_replace('PING :', 'PONG :', $this->data));
                } elseif(stripos($this->data, ' JOIN ' . $config['channel'])!==false){
                	$nameTemp = explode('!', $this->data);
                	$name = str_replace(':', '', $nameTemp[0]);
                    $ip = @explode('@', $this->data);
                    $ip = @explode(' ', $ip[1]);
                    $ip = @$ip[0];
                    $query = @unserialize(file_get_contents('http://ip-api.com/php/' . $ip));
                    if($query && $query['status'] == 'success' && $name != $config['nick'] && $query['country']!='' && $query['city'] != '') {
                        self::say('好久不見，來自 ' . $query['country'] . '-' . $query['city'] . ' 的 ' . $name . '!');
                    } elseif(strpos($this->data, 'gateway/')!==false){
                    	$ip = @explode('ip.', $this->data);
                    	$ip = @explode(' ', $ip[1]);
                    	$ip = @$ip[0];
                    	$query = @unserialize(file_get_contents('http://ip-api.com/php/' . $ip));
                    	if($query && $query['status'] == 'success' && $name != $config['nick'] && $query['country']!='' && $query['city'] != '') {
                        	self::say('好久不見，來自 ' . $query['country'] . '-' . $query['city'] . ' 的 ' . $name . '!');
                    	}
                    } elseif($name != $config['nick']){
                        self::say('好久不見，' . $name . '!');
                    }
                }
            }
        }

        private function _title_url_process(){
            $url = $this->SayContent;
            $urlParse = parse_url($url);
            if(isset($urlParse['query'])){
                $query = '?' . $urlParse['query'];
            } else {
                $query = '';
            }
            $url = $urlParse['scheme'] . '://' . $urlParse['host'] . $urlParse['path'] . $query;
            ini_set("user_agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
            if($str = file_get_contents($this->SayContent)){
                $titleTemp = explode('<title', $str);
                $titleTemp = explode('>', $titleTemp[1]);
                $titleTemp = explode('<', $titleTemp[1]);
                $urlTemp = explode('\\', str_replace('https://', '', str_replace('http://', '', $this->SayContent)));
                if(strpos($urlTemp[0], '/')!==false){
                    $temp = explode('/', $urlTemp[0]);
                    $host = $temp[0];
                }
                self::say("[ {$titleTemp[0]} ] - $host", 'Default');
{'fraction_non_alphanumeric': 0.20354424754180322, 'fraction_numerical': 0.008221765457474585, 'mean_word_length': 1.7627378759975445, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 169, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3561888', 'n_tokens_mistral': 5536, 'n_tokens_neox': 5235, 'n_words': 880}