Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** PHP IRC QuoterBot **
- *
- * ####TODO: Think and then some..
- * ####TODO: THINK of extras.
- */
- $qbot = QuoterBot::getInst();
- $qbot->config = array(
- 'serv' => 'localhost',
- 'port' => 6667,
- 'nick' => 'qbot',
- 'name' => 'qbot',
- 'chan' => array('#chats', '#test'),
- 'confs_data' => './config.db',
- 'quote_data' => './quotes.db',
- 'admin_data' => './admins.db',
- 'admin_logs' => './admin.log',
- 'admin_list' => array('Bansha', 'Test@localhost', 'Test2!user@localhost')
- );
- $qbot->Init();
- ###########################################################
- class QuoterBot
- {
- private $is_CLI = false;
- private $socket = null;
- private $ex = null;
- private $tstamp = '0000-00-00 00:00:00';
- private $nicks = array();
- private $chans = array();
- private $admins = array();
- private $quotes = array();
- private $primer = false;
- private $privmsg = false;
- private $curruser = null;
- private $currchan = null;
- private $cmdRated = false;
- private $cmdTicker = 0;
- private $cmdtstamp = '0000-00-00 00:00:00';
- private $userwhois = null;
- private $options = array(
- 'addquote' => 'on',
- 'autochat' => 'off',
- 'autojoke' => 'off',
- 'joketime' => '30',
- 'ratelimit' => '10/25'
- );
- public $config = array(
- 'serv' => 'please.change.me', # Bot Serv
- 'port' => 6667, # Bot Port
- 'nick' => 'qbot', # Bot Nick
- 'name' => 'QuoterBot', # Bot Name
- 'chan' => array('#chan1','#chan2'), # Chan to join
- 'confs_data' => './config.db', # Confs Stor DataFile
- 'quote_data' => './quotes.db', # Quote Stor DataFile
- 'admin_data' => './admins.db', # Admin User DataFile
- 'admin_logs' => './admin.log', # Admin Logs DataFile
- 'admin_list' => array('nick1',
- 'nick2@localhost',
- 'nick3!user@localhost') # Hardcoded Admin List
- );
- private $_addr_alloc = array(
- '199.27.128.0/21',
- '173.245.48.0/20',
- '103.21.244.0/22',
- '103.22.200.0/22',
- '103.31.4.0/22',
- '141.101.64.0/18',
- '108.162.192.0/18',
- '190.93.240.0/20',
- '188.114.96.0/20',
- '197.234.240.0/22',
- '198.41.128.0/17',
- '162.158.0.0/15',
- '104.16.0.0/12',
- '172.64.0.0/13'
- );
- private $_subd_alloc = array(
- 'mail',
- 'direct',
- 'direct-connect',
- 'cpanel',
- 'ftp',
- 'forum',
- 'forums',
- 'blog',
- 'blogs',
- 'test',
- 'dev',
- 'webmail',
- 'testing',
- 'secure',
- 'server',
- 'irc',
- 'cp',
- 'portal',
- 'ssl',
- 'www'
- );
- public static function getInst()
- {
- static $inst = null;
- if ($inst === null)
- {
- $inst = new self;
- }
- return $inst;
- }
- // Initital functions
- public function Init()
- {
- if(php_sapi_name() == 'cli')
- {
- $this->is_CLI = true;
- }
- else
- {
- if(!set_time_limit(0))
- {
- echo "<font color='red'><b>Unable to Set_Time_Limit();</b></font><br>" . PHP_EOL;
- }
- flush();
- }
- $this->initCore();
- }
- // Initital Core functions
- private function InitCore()
- {
- // FileDB Checks
- $this->chkFileDbs();
- // Timestamps
- $this->tstamp = date(time());
- $this->cmdtstamp = $this->tstamp;
- // Start connection to IRC
- $this->socket = fsockopen($this->config['serv'], $this->config['port']);
- // Send USER/NICK to IRC
- $this->sendData('USER', "{$this->config['nick']} irc.land {$this->config['nick']} :{$this->config['name']}\r\n");
- $this->sendData('NICK', "{$this->config['nick']}\r\n");
- while(true)
- {
- // Bot Core
- $this->ex = $this->recvData();
- // Play Ping-Pong
- if($this->ex[0] == 'PING')
- {
- $this->sendData('PONG', "{$this->ex[1]}");
- }
- // Auto Functions
- if($this->options['autojoke'] == 'on' &&
- $this->tstamp < date(time()) - (60 * (int)$this->options['joketime'])) // 60 seconds * minutes;
- {
- $this->tstamp = date(time());
- foreach($this->chans as $chan)
- {
- $this->randJoke($chan);
- }
- }
- // Set Current User/Chan
- $this->curruser = substr(explode('!', $this->ex[0])[0], 1);
- $this->currchan = @$this->ex[2];
- if($this->options['autochat'] == 'on')
- {
- if(@$this->ex[1] == 'PRIVMSG' && $this->ex[3] != ':!qbot' && $this->ex[3] != ':!chat')
- {
- $ex = $this->ex;
- $ex[3] = substr($ex[3], 1);
- foreach($ex as $key => $word)
- {
- if(trim($word) == $this->config['nick'])
- {
- unset($this->ex[$key]);
- $this->qbotChat(true);
- }
- }
- }
- }
- // Switch Functions
- $this->preSwitches();
- $this->cmdSwitches();
- } // While(true)
- }
- private function chkFileDbs()
- {
- // Check Admin Data
- if(file_exists($this->config['admin_data']))
- {
- $data = strtolower(file_get_contents($this->config['admin_data']));
- $this->admins = array_unique(array_merge(unserialize($data)));
- }
- else
- {
- $admins = $this->config['admin_list'];
- $this->admins = explode('|', strtolower(implode('|', $admins)));
- file_put_contents($this->config['admin_data'], '');
- file_put_contents($this->config['admin_data'], serialize($this->admins));
- }
- // Check Quote Data
- if(file_exists($this->config['quote_data']))
- {
- $data = file_get_contents($this->config['quote_data']);
- $this->quotes = unserialize($data);
- }
- else
- {
- file_put_contents($this->config['quote_data'], '');
- file_put_contents($this->config['quote_data'], serialize($this->quotes));
- }
- // Check Config Data
- if(file_exists($this->config['confs_data']))
- {
- $data = file_get_contents($this->config['confs_data']);
- $this->options = unserialize($data);
- }
- else
- {
- file_put_contents($this->config['confs_data'], '');
- file_put_contents($this->config['confs_data'], serialize($this->options));
- }
- }
- private function preSwitches()
- {
- // preSwitches include Pre commands, and post nick/join/kick/part/quit
- switch(@$this->ex[1])
- {
- case '001': // Check for time to join
- if(is_array($this->config['chan']))
- {
- foreach($this->config['chan'] as $chan)
- {
- $this->sendData('JOIN', "$chan\r\n");
- }
- }
- else
- {
- $this->sendData('JOIN', "{$this->config['chan']}\r\n");
- }
- break;
- #####################
- case '311': // Fetch Whois Info
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[6], $ex[7]);
- $this->userwhois = $ex;
- break;
- #####################
- case '353': // Fetch Nicks from Channel
- $ex = $this->ex;
- $chan = $ex[4];
- unset($ex[0], $ex[1], $ex[2], $ex[3], $ex[4]);
- $nicks = implode(' ', $ex);
- $nicks = str_replace(':', '', $nicks);
- $nicks = str_replace('@', '', $nicks);
- $this->nicks[$chan] = explode(' ', ucwords($nicks));
- break;
- #####################
- case '433': // Set random nick, if Nick inuse
- $randId = substr(mt_rand(), 0, strlen(mt_rand())/2);
- $this->sendData('NICK', "{$this->config['nick']}$randId\r\n");
- break;
- #####################
- case 'NICK': // Update Nicks array on Nick Change
- $olduser = trim(ucwords(str_replace(':', '', explode("!", substr($this->ex[0], 1))[0])));
- $newuser = trim(ucwords($this->ex[2]));
- if($olduser == ucwords($this->config['nick']))
- {
- $this->sendData('NICK', "{$this->config['nick']}\r\n");
- }
- foreach($this->chans as $chan)
- {
- foreach($this->nicks[$chan] as $nickId => $nick)
- {
- if($olduser == $nick)
- {
- $this->nicks[$chan][$nickId] = $newuser;
- }
- }
- }
- break;
- #####################
- case 'JOIN':
- $chan = trim(strtolower(substr($this->ex[2], 1)));
- $user = trim(ucwords(explode("!", substr($this->ex[0], 1))[0]));
- $this->chans[$chan] = $chan;
- $this->nicks[$chan][] = $user;
- break;
- #####################
- case 'KICK':
- $this->sendData('JOIN', "{$this->ex[2]}\r\n");
- break;
- #####################
- case 'PART':
- $olduser = trim(ucwords(str_replace(':', '', explode("!", substr($this->ex[0], 1))[0])));
- $this->currchan = trim($this->currchan);
- foreach($this->nicks[$this->currchan] as $nickId => $nick)
- {
- if($olduser == $nick)
- {
- unset($this->nicks[$this->currchan][$nickId]);
- }
- }
- break;
- #####################
- case 'QUIT':
- $olduser = trim(ucwords(str_replace(':', '', explode("!", substr($this->ex[0], 1))[0])));
- foreach($this->chans as $chan)
- {
- foreach($this->nicks[$chan] as $nickId => $nick)
- {
- if($olduser == $nick)
- {
- unset($this->nicks[$chan][$nickId]);
- }
- }
- }
- break;
- }
- }
- private function cmdSwitches()
- {
- // Executed Command
- $command = str_replace(array(chr(10), chr(13)), '', isset($this->ex[3])?$this->ex[3]:null);
- // User/Admin Command switches outside limiter
- switch($command)
- {
- case ':!qbot':
- case ':!chat':
- $this->qbotChat();
- break;
- ######################
- case ':!delquote':
- case ':!delquotes':
- if($this->isAdmin())
- {
- $this->delQuote();
- }
- break;
- #####################
- case ':!addadmin':
- if($this->isAdmin())
- {
- $this->addAdmin();
- }
- break;
- ######################
- case ':!deladmin':
- if($this->isAdmin())
- {
- $this->delAdmin();
- }
- break;
- ######################
- case ':!listadmin':
- case ':!listadmins':
- if($this->isAdmin())
- {
- $this->listAdmins();
- }
- break;
- ######################
- case ':!set':
- if($this->isAdmin())
- {
- $this->setOption();
- }
- break;
- ######################
- case ':!get':
- if($this->isAdmin())
- {
- $this->getOption();
- }
- break;
- #####################
- case ':!say':
- if($this->isAdmin())
- {
- $this->say2Chan();
- }
- break;
- ######################
- case ':!join':
- if($this->isAdmin())
- {
- $this->joinChan();
- }
- break;
- ######################
- case ':!part':
- if($this->isAdmin())
- {
- $this->partChan();
- }
- break;
- ######################
- case ':!restart':
- case ':!cycle':
- if($this->isAdmin())
- {
- $this->sendData("QUIT", "I'll be BACK...\r\n");
- sleep(2);
- $this->initCore();
- }
- break;
- ######################
- case ':!quit':
- case ':!kill':
- if($this->isAdmin())
- {
- $this->sendData("QUIT", "Bubye...\r\n");
- exit;
- }
- break;
- }
- // Ignore Privmsg to bot.
- if(@$this->ex[1] == 'PRIVMSG' && @$this->ex[2] == $this->config['nick'])
- {
- $this->privmsg = true;
- }
- // Rate Limits Cmds/Secs
- list($rateCmds, $rateSecs) = explode("/", $this->options['ratelimit']);
- // if ! command detected and
- // rate limiter not hit then
- // increment ticker if primer is false
- if(substr($command, 0, 2) == ':!' && $this->cmdTicker <= (int)$rateCmds)
- {
- // Check primer = false
- // to not trigger rate limiter
- // on Admin functions, or others
- if($this->primer == false)
- {
- $this->cmdtstamp = date(time());
- $this->cmdTicker++;
- }
- }
- // If Time in seconds hit
- // reset cmdTicker and cmdRated
- if($this->cmdtstamp < date(time()) - (int)$rateSecs) // Time in seconds
- {
- $this->cmdTicker = 0;
- $this->cmdRated = false;
- }
- // Check cmdTicker and not a privmsg
- if($this->cmdTicker <= (int)$rateCmds && $this->privmsg == false)
- {
- // User command switches
- switch($command)
- {
- case ':!help':
- case ':!info':
- $this->showHelp();
- break;
- ######################
- case ':!addquote':
- $this->addQuote();
- break;
- ######################
- case ':!quote':
- $this->listQuotes();
- break;
- ######################
- case ':!randquote':
- $this->randQuote();
- break;
- ######################
- case ':!joke':
- $this->randJoke();
- break;
- ######################
- case ':!wiki':
- $this->grabWiki();
- break;
- ######################
- case ':!google':
- $this->grabGoogle();
- break;
- ######################
- case ':!yahoo':
- $this->grabYahoo();
- break;
- ######################
- case ':!bing':
- $this->grabBing();
- break;
- ######################
- case ':!cf':
- $this->checkCloudflare();
- break;
- ######################
- case ':!ip':
- $this->getIp();
- break;
- ######################
- case ':!dns':
- $this->getDns();
- break;
- ######################
- case ':!url':
- $this->checkUrl();
- break;
- ######################
- case ':!port':
- $this->checkPort();
- break;
- ######################
- case ':!md5':
- $this->checkMD5();
- break;
- ######################
- case preg_match("/(www\.)?imdb\.com\/title\/[A-Za-z0-9]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("http://{$url[0]}");
- preg_match("/<title>(.*)<\/title>/siU", $page, $title);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "IMDb: {$url[0]} Title: {$title[1]}\r\n");
- break;
- ######################
- case preg_match("/(www\.)?pastebin\.com\/[a-zA-Z0-9]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("http://{$url[0]}");
- preg_match("/<title>(.*)<\/title>/siU", $page, $title);
- $title = htmlspecialchars_decode($title[1]);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Paste: {$url[0]} Title: $title\r\n");
- break;
- ######################
- case preg_match("/(www\.)?youtube\.com\/watch\?v=[a-zA-Z0-9-_]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("https://{$url[0]}");
- preg_match("/<title>(.*)<\/title>/siU", $page, $title);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "YouTube: {$url[0]} Title: {$title[1]}\r\n");
- break;
- ######################
- case preg_match("/(www\.)?twitter\.com\/[a-zA-Z0-9-_]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("https://{$url[0]}");
- preg_match("/<title>(.*)<\/title>/siU", $page, $title);
- $title = htmlspecialchars_decode($title[1]);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Twitter: {$url[0]} Title: $title\r\n");
- break;
- ######################
- case preg_match("/(www\.)?instagram\.com\/p\/[a-zA-Z0-9-_]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("https://{$url[0]}");
- preg_match("/<meta property=\"og:title\" content=\"(.*)\”\" \/>/siU", $page, $title);
- $title = htmlspecialchars_decode($title[1]);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "InstaGram: {$url[0]} Title: $title\r\n");
- break;
- ######################
- case preg_match("/(en\.)?wikipedia\.org\/wiki\/[a-zA-Z0-9-_]+/i", $command, $url) ? $command : !$command:
- $page = file_get_contents("https://{$url[0]}");
- preg_match("/<title>(.*)<\/title>/siU", $page, $title);
- $title = htmlspecialchars_decode($title[1]);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Twitter: {$url[0]} Title: $title\r\n");
- break;
- }
- }
- elseif($this->privmsg == true)
- {
- // Reset Privmsg check
- $this->privmsg = false;
- }
- else
- {
- // Show rate limit once
- if($this->cmdRated == false)
- {
- $this->cmdRated = true;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Rate Limit; Wait 30 seconds ({$rateCmds}cmds/{$rateSecs}secs)\r\n");
- }
- }
- // Reset primer check.
- $this->primer = false;
- }
- private function isAdmin($help = false)
- {
- // Set primer check true,
- // to not trigger rate limiter
- $this->primer = true;
- $command = (string)strtolower(str_replace(array(chr(10), chr(13)), '', isset($this->ex[3])?$this->ex[3]:''));
- $this->adminLog("'$command' executed by '{$this->ex[0]}'");
- if(count($this->admins) == 0)
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "No Admins exist\r\n");
- return false;
- }
- else
- {
- $data = strtolower(file_get_contents($this->config['admin_data']));
- $user = trim(substr($this->ex[0], 1));
- preg_match("/(.*)!(.*)@(.*)/", $user, $usermask);
- unset($usermask[0]);
- $usermask = strtolower(implode("|", $usermask));
- list($nickname, $username, $hostname) = explode("|", $usermask);
- $hostname = str_replace('127.0.0.1', 'localhost', $hostname);
- $hostname = str_replace('0::1', 'localhost', $hostname);
- if(in_array((string)"$nickname!$username@$hostname", $this->admins)) // Nickname!Username@Hostname
- {
- return true;
- }
- if(in_array((string)"$nickname@$hostname", $this->admins)) // Nickname@Hostname
- {
- return true;
- }
- if(in_array((string)"$nickname", $this->admins)) // Just Nickname
- {
- return true;
- }
- if($help == false)
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Unable to process; $nickname is not on the admin list\r\n");
- }
- return false;
- }
- }
- // Post User functions
- private function showHelp()
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "QuoterBot Help/Info sent over PM!\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "QuoterBot Help/Info ====\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "========================\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "User Functions:\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!quote BLANK|NICK|NICK ID\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!randquote\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!addquote TEXT\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!joke BLANK|NICK\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!wiki QUERY\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!google QUERY\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!yahoo QUERY\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!bing QUERY\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!cf DNS\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!ip DNS\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!dns IP\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!url IP|DNS|URI\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!port DNS|IP PORT\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!md5 STR|MD5\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!chat MSG\r\n");
- if($this->isAdmin(true))
- {
- $this->sendData("PRIVMSG {$this->curruser} :", "=========================\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "Admin Functions:\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!say CHAN MSG\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!join #CHAN & !part #CHAN\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!delquote BLANK|NICK QuoteID\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!listadmin & !addadmin NICK & !deladmin NICK\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!get addquote & !set addquote on|off\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!get autojoke & !set autojoke on|off\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!get joketime & !set joketime Minute(s)\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!get ratelimit & !set ratelimit Cmds/Secs\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "!restart & !quit\r\n");
- }
- }
- private function addQuote()
- {
- if($this->options['addquote'] == 'on')
- {
- $ex = $this->ex;
- $byuser = trim(strtolower(substr(explode('!', $ex[0])[0], 1)));
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $quotetxt = trim(implode(' ', $ex));
- $quotetxt = substr($quotetxt, 0, 128);
- if($quotetxt != '')
- {
- if(!in_array($quotetxt, $this->quotes[$byuser]))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Adding Quote by $byuser: [$quotetxt]\r\n");
- $this->quotes[$byuser][] = $quotetxt;
- file_put_contents($this->config['quote_data'], '');
- file_put_contents($this->config['quote_data'], (string)serialize($this->quotes));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "That quote already exists by $byuser: [$quotetxt]\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "A blank quote has been entered by $byuser: [$quotetxt]\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Add Quotes Disabled\r\n");
- }
- }
- private function delQuote()
- {
- $byuser = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- $quoteid = trim(isset($this->ex[5])?$this->ex[5]:null);
- if($quoteid != null)
- {
- if(is_array($this->quotes[$byuser]))
- {
- $quotetxt = $this->quotes[$byuser][$quoteid-1];
- unset($this->quotes[$byuser][$quoteid-1]);
- if(count($this->quotes[$byuser]) == 0)
- {
- unset($this->quotes[$byuser]);
- }
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Deleted Quote by $byuser with id#$quoteid: [$quotetxt]\r\n");
- file_put_contents($this->config['quote_data'], '');
- file_put_contents($this->config['quote_data'], (string)serialize($this->quotes));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Unable to Delete Quote by $byuser with id#$quoteid: [User quote doesn't exist]\r\n");
- }
- }
- else
- {
- if($byuser != null)
- {
- if(is_array(@$this->quotes[$byuser]))
- {
- foreach($this->quotes[$byuser] as $quoteid => $quotetxt)
- {
- unset($this->quotes[$byuser][$quoteid]);
- }
- unset($this->quotes[$byuser]);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Deleted all Quotes by $byuser\r\n");
- file_put_contents($this->config['quote_data'], '');
- file_put_contents($this->config['quote_data'], (string)serialize($this->quotes));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes by $byuser exist\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Unable to Delete Quote by $byuser [User Quotes don't exist]\r\n");
- }
- }
- }
- private function listQuotes()
- {
- $byuser = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- $quoteId = trim(isset($this->ex[5])?$this->ex[5]:null);
- if($byuser != null)
- {
- if($quoteId != null)
- {
- if(isset($this->quotes[$byuser][$quoteId-1]))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "$byuser#$quoteId) {$this->quotes[$byuser][$quoteId-1]}\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes by $byuser exists with ID: $quoteId\r\n");
- }
- }
- else
- {
- if(is_array($this->quotes[$byuser]))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Listing Quotes by $byuser over PM\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "Listing Quotes by $byuser\r\n");
- foreach($this->quotes[$byuser] as $quoteid => $quotetxt)
- {
- $quoteid++;
- $this->sendData("PRIVMSG {$this->curruser} :", "$quoteid) $quotetxt\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes by $byuser exist\r\n");
- }
- }
- }
- else
- {
- if(count($this->quotes) > 0)
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Listing Quotes over PM\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "Listing Quotes\r\n");
- foreach($this->quotes as $byuser => $quotes)
- {
- foreach($quotes as $quoteid => $quotetxt)
- {
- $quoteid++;
- if($quotetxt != null)
- {
- $this->sendData("PRIVMSG {$this->curruser} :", "$byuser#$quoteid) $quotetxt\r\n");
- }
- }
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes exist\r\n");
- }
- }
- }
- private function randQuote()
- {
- $byuser = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($byuser != null)
- {
- if(is_array($this->quotes[$byuser]))
- {
- $quoteId = array_rand($this->quotes[$byuser]);
- $quoteId++;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Quote: $byuser#$quoteId) {$this->quotes[$byuser][$quoteId-1]}\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes by $byuser exist\r\n");
- }
- }
- else
- {
- if(count($this->quotes) > 0)
- {
- $byuser = array_rand($this->quotes);
- $quotes = array_values($this->quotes);
- $quoteId = array_rand($this->quotes[$byuser]);
- $quoteId++;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Quote: {$this->quotes[$byuser][$quoteId-1]}\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Quotes exist\r\n");
- }
- }
- }
- private function randJoke($chan = null)
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $foruser = trim(ucwords(str_replace('\\', '', substr(implode(' ', $ex), 0, 20))));
- $chan = ($chan == null)?$this->ex[2]:$chan;
- $nickId = array_rand($this->nicks[$chan]);
- $nickRnd = $this->nicks[$chan][$nickId];
- if($foruser != '' && in_array($foruser, $this->nicks[$chan]))
- {
- $jokeAr = array_merge($this->fetchJoke($foruser), $this->fetchJoke($foruser));
- $jokeId = array_rand($jokeAr);
- $joke = $jokeAr[$jokeId];
- }
- else
- {
- $jokeAr = array_merge($this->fetchJoke($nickRnd), $this->fetchJoke($nickRnd));
- $jokeId = array_rand($jokeAr);
- $joke = $jokeAr[$jokeId];
- }
- $this->sendData("PRIVMSG $chan :", "Joke: $joke\r\n");
- }
- private function fetchJoke($nick = null)
- {
- $data = file_get_contents("http://api.icndb.com/jokes/random?firstName=".urlencode($nick));
- $data = json_decode($data, true)['value']['joke'];
- $data = str_replace(':', '', $data);
- $data = str_replace(' Norris', '', $data);
- $joke = htmlspecialchars_decode($data);
- $data2 = file_get_contents("http://api.yomomma.info/");
- $data2 = json_decode($data2, true)['joke'];
- $joke2 = htmlspecialchars_decode($data2);
- $joke2 = "$nick, $joke2";
- if($nick == null)
- {
- $data3 = file_get_contents("http://tambal.azurewebsites.net/joke/random");
- $data3 = json_decode($data3, true)['joke'];
- $joke3 = htmlspecialchars_decode($data3);
- $joke3 = "$joke3";
- $jokes = array_merge(array($joke), array($joke2), array($joke3));
- }
- else
- {
- $jokes = array_merge(array($joke), array($joke2));
- }
- return (count($jokes)==2||count($jokes)==3)?$jokes:false;
- }
- private function grabWiki()
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $searchtxt = trim(implode('+', $ex));
- $searchtxt = substr($searchtxt, 0, 128);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://en.wikipedia.org/w/index.php?search=$searchtxt&title=Special%3ASearch&go=Go");
- curl_setopt($ch, CURLOPT_HEADER, TRUE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $data = curl_exec($ch);
- if(preg_match('#Location: (.*)#', $data, $wikiUri))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Wiki: {$wikiUri[1]}\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Wiki: Unable to process search\r\n");
- }
- }
- private function grabGoogle()
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $searchtxt = trim(implode('+', $ex));
- $searchtxt = substr($searchtxt, 0, 128);
- $data = file_get_contents("https://search.disconnect.me/searchTerms/search?query=$searchtxt&lang=en&location=US&location_option=US&ses=Google&ses_nojs=Google&option=Web");
- preg_match("/<a href=\"(.*)\" class=\"title\">(.*)<\/a>/i", $data, $result);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Google: {$result[1]} Title: {$result[2]}\r\n");
- }
- private function grabYahoo()
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $searchtxt = trim(implode('+', $ex));
- $searchtxt = substr($searchtxt, 0, 128);
- $data = file_get_contents("https://search.disconnect.me/searchTerms/search?query=$searchtxt&lang=en&location=US&location_option=US&ses=Yahoo&ses_nojs=Yahoo&option=Web");
- preg_match("/<a href=\"(.*)\" class=\"title\">(.*)<\/a>/i", $data, $result);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Yahoo: {$result[1]} Title: {$result[2]}\r\n");
- }
- private function grabBing()
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $searchtxt = trim(implode('+', $ex));
- $searchtxt = substr($searchtxt, 0, 128);
- $data = file_get_contents("https://search.disconnect.me/searchTerms/search?query=$searchtxt&lang=en&location=US&location_option=US&ses=Bing&ses_nojs=Bing&option=Web");
- preg_match("/<a href=\"(.*)\" class=\"title\">(.*)<\/a>/i", $data, $result);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Bing: {$result[1]} Title: {$result[2]}\r\n");
- }
- private function checkCloudflare()
- {
- $dnsname = (string)trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($dnsname != null)
- {
- $dnsname = str_replace('http://', '', $dnsname);
- $dnsname = str_replace('https://', '', $dnsname);
- $protocol = '';
- if(fsockopen($dnsname, 80, $errno, $errstr, 1))
- {
- $protocol = 'http';
- }
- elseif(fsockopen($dnsname, 443, $errno, $errstr, 1))
- {
- $protocol = 'https';
- }
- if($protocol != '')
- {
- if(!$this->isValidUrl($dnsname))
- {
- $url = "$protocol://$dnsname";
- }
- if($this->isCloudFlare($url))
- {
- $host = parse_url($url)['host'];
- if(strstr($host, 'www.'))
- {
- $host = explode('www.', $host)[1];
- }
- foreach($this->_subd_alloc as $subdomain)
- {
- $host_pre_ = "{$subdomain}.{$host}";
- $host_ip = gethostbyname($host_pre_);
- if($this->isValidIp($host_ip))
- {
- if($this->isCloudFlare($host_ip))
- {
- # To show or not to show?
- //$this->sendData("PRIVMSG {$this->ex[2]} :", "{$host_pre_} - {$host_ip} is Cloudflare\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "{$host_pre_} - {$host_ip} is a Direct IP\r\n");
- }
- }
- }
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CFlare: Unable to continue, Perhaps no webserver is running?\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CFlare: You must enter a DNS Name\r\n");
- }
- }
- private function isCloudFlare($host)
- {
- if($this->isValidIp($host))
- {
- foreach($this->_addr_alloc as $addr_alloc)
- {
- if($this->cidr_match($host, $addr_alloc))
- {
- return true;
- }
- }
- return false;
- }
- elseif($this->isValidUrl($host))
- {
- $headers = implode("\n", get_headers($host));
- $headers = explode("cloudflare", $headers);
- return count($headers)>1 ? true : false;
- }
- }
- private function getIp()
- {
- $dnsname = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($dnsname != null)
- {
- $dnsname = str_replace('http://', '', $dnsname);
- $dnsname = str_replace('https://', '', $dnsname);
- $ipaddr = gethostbynamel($dnsname);
- $ipaddr = implode("|", $ipaddr);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "GetIP: $ipaddr DNS: $dnsname\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "GetIP: You must enter a DNS Name\r\n");
- }
- }
- private function getDns()
- {
- $ipaddr = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($ipaddr != null)
- {
- $ipaddr = str_replace('http://', '', $ipaddr);
- $ipaddr = str_replace('https://', '', $ipaddr);
- $dnsname = gethostbyaddr($ipaddr);
- $dnsname = ($dnsname!=$ipaddr)?$dnsname:'dns-not-set';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "GetDNS: $ipaddr DNS: $dnsname\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "GetDNS: You must enter an IP Address\r\n");
- }
- }
- private function checkUrl()
- {
- $forurl = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($forurl != null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "$forurl");
- curl_setopt($ch, CURLOPT_HEADER, FALSE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $data = curl_exec($ch);
- if(!curl_errno($ch))
- {
- $info = curl_getinfo($ch);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckUrl: {$info['url']} is UP and took {$info['total_time']} seconds to respond\r\n");
- }
- else
- {
- $info = curl_getinfo($ch);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckUrl: {$info['url']} is DOWN.\r\n");
- }
- curl_close($ch);
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckUrl: Please enter a URL to check, making sure to include the protocol\r\n");
- }
- }
- private function checkPort()
- {
- $dnsname = (string)trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- $portnum = (int)trim(isset($this->ex[5])?$this->ex[5]:0);
- if($dnsname != null)
- {
- if($portnum >= 1 && $portnum <= 65535)
- {
- $dnsname = str_replace('http://', '', $dnsname);
- $dnsname = str_replace('https://', '', $dnsname);
- if(@fsockopen($dnsname, $portnum, $errno, $errstr, 2))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckPort: $dnsname:$portnum is UP\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckPort: $dnsname:$portnum is DOWN\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckPort: You must enter a Port Number (1-65535)\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "CheckPort: You must enter a DNS Name\r\n");
- }
- }
- private function checkMD5()
- {
- $md5str = (string)trim(isset($this->ex[4])?$this->ex[4]:null);
- if($md5str != null)
- {
- if(preg_match('/^[a-f0-9]{32}$/i', $md5str))
- {
- $return = json_decode(file_get_contents("http://api.md5crack.com/crack/mZKoDn98W9l843ra/".$md5str));
- $return = ($return->phrase!='')?$return->phrase:$return->response;
- $len = strlen($return);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "MD5: $md5str String($len): $return\r\n");
- }
- else
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3]);
- $ex = trim(implode(" ", $ex));
- $return = json_decode(file_get_contents("http://api.md5crack.com/hash/mZKoDn98W9l843ra/".$ex));
- $len = strlen($ex);
- $this->sendData("PRIVMSG {$this->ex[2]} :", "MD5: {$return->phrase} String($len): $ex\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "MD5: You must enter a String or an MD5\r\n");
- }
- }
- private function qbotChat($privmsg = false)
- {
- // Set primer check true,
- // to not trigger rate limiter
- $this->primer = true;
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2]);
- if($privmsg == false)
- {
- unset($ex[3]);
- }
- $chattxt = trim(substr(implode(" ", $ex), 1));
- $byuser = substr(explode('!', $this->ex[0])[0], 1);
- $chattxt = urlencode($chattxt);
- $result = file_get_contents("http://www.simsimi.com/requestChat?lc=en&ft=1.0&req=$chattxt&uid=85422145");
- $chattxt = json_decode($result, true);
- if(strpos($chattxt['res'], 'I HAVE NO RESPONSE') === false)
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "$byuser, {$chattxt['res']}\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "$byuser, Does not compute!? I didn't understand that...\r\n");
- }
- }
- // Post Admin Functions
- private function addAdmin()
- {
- $foruser = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($foruser != null)
- {
- if(!in_array($foruser, $this->admins))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Adding Admin for $foruser\r\n");
- $this->admins[] = $foruser;
- file_put_contents($this->config['admin_data'], '');
- file_put_contents($this->config['admin_data'], (string)serialize($this->admins));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "The Admin for $foruser already exists\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You've entered a blank nickname\r\n");
- }
- }
- private function delAdmin()
- {
- $foruser = trim(strtolower(isset($this->ex[4])?$this->ex[4]:null));
- if($foruser != null)
- {
- if(in_array($foruser, $this->admins))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Deleting Admin for $foruser\r\n");
- foreach($this->admins as $adminId => $admin)
- {
- if($admin == $foruser)
- {
- unset($this->admins[$adminId]);
- }
- }
- file_put_contents($this->config['admin_data'], '');
- file_put_contents($this->config['admin_data'], (string)serialize($this->admins));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "The Admin for $foruser doesn't exist\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You've entered a blank nickname\r\n");
- }
- }
- private function listAdmins()
- {
- if(count($this->admins) >= 1 )
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Listing Admins over PM\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "Listing Admins\r\n");
- $this->admins = array_unique($this->admins);
- foreach($this->admins as $adminId => $admin)
- {
- $adminId++;
- $this->sendData("PRIVMSG {$this->curruser} :", "$adminId) $admin\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Currently no Admins exist\r\n");
- }
- }
- private function setOption()
- {
- $option = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($option != null)
- {
- $setting = trim(isset($this->ex[5])?$this->ex[5]:null);
- switch(strtolower($option))
- {
- case 'addquote':
- case 'addquotes':
- switch($setting)
- {
- case 'on':
- $this->options['addquote'] = 'on';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Add Quotes Enabled\r\n");
- break;
- case 'off':
- $this->options['addquote'] = 'off';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Add Quotes Disabled\r\n");
- break;
- default:
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Err: !set addquote on|off (To enable or disable adding quotes)\r\n");
- break;
- }
- break;
- case 'autochat':
- case 'autochats':
- switch($setting)
- {
- case 'on':
- $this->options['autochat'] = 'on';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Auto Chat Enabled\r\n");
- break;
- case 'off':
- $this->options['autochat'] = 'off';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Auto Chat Disabled\r\n");
- break;
- default:
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Err: !set autochat on|off (To enable or disable automatic chat)\r\n");
- break;
- }
- break;
- case 'autojoke':
- case 'autojoker':
- switch($setting)
- {
- case 'on':
- $this->options['autojoke'] = 'on';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Auto Joke Enabled\r\n");
- break;
- case 'off':
- $this->options['autojoke'] = 'off';
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Auto Joke Disabled\r\n");
- break;
- default:
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Err: !set joke on|off (To enable or disable auto joke)\r\n");
- break;
- }
- break;
- case 'joketime':
- case 'joketimer':
- if((int)$setting)
- {
- $this->options['joketime'] = $setting;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Auto joke timer set to $setting minute(s)\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Err: !set joketime Minute(s) (To set joke timer in Minutes(s))\r\n");
- }
- break;
- case 'ratelimit':
- case 'ratelimter':
- if((string)$setting)
- {
- $this->options['ratelimit'] = (string)$setting;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Rate Limiter set to $setting Commands in Second(s)\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Err: !set ratelimit Cmds/Secs (To set rate limter in Cmd/Secs ratio)\r\n");
- }
- break;
- }
- file_put_contents($this->config['confs_data'], '');
- file_put_contents($this->config['confs_data'], (string)serialize($this->options));
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You must choose an option!\r\n");
- $this->sendData("PRIVMSG {$this->ex[2]} :", "==========================\r\n");
- foreach($this->options as $opt => $val)
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "!set $opt on|off\r\n");
- }
- }
- }
- private function getOption()
- {
- $option = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($option != null)
- {
- switch(strtolower($option))
- {
- default:
- $optId = 0;
- foreach($this->options as $opt => $val)
- {
- $optId++;
- $this->sendData("PRIVMSG {$this->ex[2]} :", "$optId) Opt: $opt Val: $val\r\n");
- }
- break;
- case 'addquote':
- case 'addquotes':
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Opt: $option Val: {$this->options['addquote']}\r\n");
- break;
- case 'autochat':
- case 'autochats':
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Opt: $option Val: {$this->options['autochat']}\r\n");
- break;
- case 'autojoke':
- case 'autojoker':
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Opt: $option Val: {$this->options['autojoke']}\r\n");
- break;
- case 'joketime':
- case 'joketimer':
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Opt: $option Val: {$this->options['joketime']}\r\n");
- break;
- case 'ratelimit':
- case 'ratelimiter':
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Opt: $option Val: {$this->options['ratelimter']}\r\n");
- break;
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Options sent over PM\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "You must choose an option!\r\n");
- $this->sendData("PRIVMSG {$this->curruser} :", "==========================\r\n");
- foreach($this->options as $opt => $val)
- {
- $this->sendData("PRIVMSG {$this->curruser} :", "!get $opt\r\n");
- }
- }
- }
- private function say2Chan()
- {
- $ex = $this->ex;
- unset($ex[0], $ex[1], $ex[2], $ex[3], $ex[4]);
- $msg = implode(" ", $ex);
- $msg = trim($msg!=''?$msg:null);
- $chan = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($chan != null)
- {
- if($msg != null)
- {
- $this->sendData("PRIVMSG $chan :", "$msg\r\n");
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You must write a message! (!say chan msg)\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You must give a channel! (!say chan msg)\r\n");
- }
- }
- private function joinChan()
- {
- $chan = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($chan != null)
- {
- if(!isset($this->chans[$chan]))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Joining Channel $chan\r\n");
- $this->sendData("JOIN", "{$this->ex[4]}");
- $this->chans[$this->ex[4]] = $this->ex[4];
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Already joined to $chan\r\n");
- }
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "You must enter a channel to join!\r\n");
- }
- }
- private function partChan()
- {
- $chan = trim(isset($this->ex[4])?$this->ex[4]:null);
- if($chan != null)
- {
- if(isset($this->chans[$chan]))
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Parting Channel $chan\r\n");
- $this->sendData("PART", "{$this->ex[4]}");
- unset($this->chans[$chan]);
- }
- else
- {
- $this->sendData("PRIVMSG {$this->ex[2]} :", "Already parted from $chan\r\n");
- }
- }
- else
- {
- $this->sendData("PART", "{$this->ex[2]}");
- }
- }
- // Send/Recv/AdminLog Functions
- private function sendData($command, $message = null)
- {
- echo 'SND-MSG: ';
- if($message == null)
- {
- fputs($this->socket, (string)"$command\r\n");
- if($this->is_CLI)
- {
- echo "$command" . PHP_EOL;
- }
- else
- {
- echo "<font color='green'><b>$command</b></font><br>" . PHP_EOL;
- }
- }
- else
- {
- fputs($this->socket, (string)"$command $message\r\n");
- if($this->is_CLI)
- {
- echo "$command -> $message" . PHP_EOL;
- }
- else
- {
- echo "<font color='green'><b>$command -> $message</b></font><br>" . PHP_EOL;
- flush();
- }
- }
- }
- private function recvData()
- {
- $data = fgets($this->socket, 1024);
- if($data != '')
- {
- echo 'RCV-MSG: ';
- if($this->is_CLI)
- {
- echo "$data" . PHP_EOL;
- }
- else
- {
- echo "<font color='blue'><b>$data</b></font><br>" . PHP_EOL;
- flush();
- }
- }
- return explode(' ', $data);
- }
- private function adminLog($input = null)
- {
- echo 'SYS-MSG: ';
- if($this->is_CLI)
- {
- echo "Append Log: [$input]" . PHP_EOL . PHP_EOL;
- }
- else
- {
- echo "<font color='yellow'><b>Append Log: [$input]</b></font><br>" . PHP_EOL;
- }
- flush();
- file_put_contents($this->config['admin_logs'], (string)(new \DateTime())->format('Y-m-d H:i:s') . " $input" . PHP_EOL, FILE_APPEND);
- }
- // Misc Functions
- private function isValidIp($ip)
- {
- return filter_var($ip, FILTER_VALIDATE_IP) ? true : false;
- }
- private function isValidUrl($url)
- {
- return filter_var($url, FILTER_VALIDATE_URL) ? true : false;
- }
- private function cidr_match($ip, $range)
- {
- list ($subnet, $bits) = explode('/', $range);
- $ip = ip2long($ip);
- $subnet = ip2long($subnet);
- $mask = -1 << (32 - $bits);
- $subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned
- return ($ip & $mask) == $subnet;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment