protected function pong() { /* tell me where i need to send pong? */ if (Config::getServerName() == 'quakenet') { $this->message($this->bot->getMessage(), null, IRC::PING, true); } else { $this->message(Config::$server . ':' . Config::$port, null, IRC::PING, true); } }
public function fillBuffer($text, $type, $target = null, $prio = false) { $text = str_replace([chr(9), chr(10), chr(11), chr(13), chr(0)], '', $text); $text = trim($text); $filters = (new Filter())->filterList(); if ($type == IRC::PRIVMSG && $filters) { foreach ($filters as $filter) { if (isset($filter['serverBlock']) && in_array(Config::getServerName(), $filter['serverBlock'])) { continue; } if (isset($filter['serverAllow']) && !in_array(Config::getServerName(), $filter['serverAllow'])) { continue; } if (isset($filter['channelBlock']) && in_array($target, $filter['channelBlock'])) { continue; } if (isset($filter['channelAllow']) && !in_array($target, $filter['channelAllow'])) { continue; } if (is_callable($filter['callback'])) { $text = call_user_func($filter['callback'], $text); } } } if (!$text) { echo 'You sent nothing' . PHP_EOL; return false; } while (true) { switch ($type) { case IRC::PRIVMSG: $message = IRC::PRIVMSG . ' ' . $target . ' :' . $text; break; case IRC::MODE: $message = IRC::MODE . ' ' . $target . ' ' . $text; break; case IRC::NICK: $message = IRC::NICK . ' ' . $text; break; case IRC::TOPIC: break; case IRC::PART: $message = IRC::PART . ' ' . $target . ' :' . $text; break; case IRC::QUIT: $message = IRC::QUIT . ' :' . $text; break; case IRC::JOIN: $message = IRC::JOIN . ' ' . $text; break; case IRC::KICK: $message = IRC::KICK . ' ' . $target . ' ' . $text; break; case IRC::NOTICE: $message = IRC::NOTICE . ' ' . $target . ' :' . $text; break; case IRC::INVITE: break; case IRC::IDENTIFY: $message = IRC::IDENTIFY . ' ' . $text; break; case IRC::PING: $message = IRC::PONG . ' ' . $text; break; default: return; } if (strlen($message) > 508) { $lastWhiteSpace = strrpos(substr($message, 0, 508), ' '); $position = $lastWhiteSpace !== false ? $lastWhiteSpace : strlen(substr($message, 0, 508)); $text = substr($message, $position + 1); $this->buffer[] = substr($message, 0, $position); } else { $this->buffer[] = $message; break; } } while ($prio && $this->buffer) { $this->flushBuffer(); } }
public function saveData($out = false) { $timestamp = '[' . date('H:i') . ']'; $source = $this->bot->getSource(); $message = $this->bot->getMessage(); $userNick = $this->bot->getUserNick(); $folder = implode(DIRECTORY_SEPARATOR, [Config::$logFolder, Config::getServerName()]); /* $userName = $this->getUserName(); */ /* $userHost = $this->getUserHost(); */ if (!$out) { switch ($this->bot->getType()) { case IRC::PRIVMSG: $text = "{$timestamp} <{$userNick}> {$message}" . IRC_EOL; if (strpos($source, '#') === 0) { $filename = $source . '_' . date('Y-m-d'); $filepatch = implode(DIRECTORY_SEPARATOR, [$folder, substr($source, 1)]); } else { $filename = $source; $filepatch = $folder; } static::push($text, $filepatch, $filename . '.log'); return $text; case IRC::JOIN: break; /* $text = "{$timestamp} {$userNick} (~{$userName}@{$userHost}) has joined.\r\n"; $filename = $message; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ /* $text = "{$timestamp} {$userNick} (~{$userName}@{$userHost}) has joined.\r\n"; $filename = $message; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ case IRC::PART: break; /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has parted.' . $info . "\r\n"; $filename = $this->source; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has parted.' . $info . "\r\n"; $filename = $this->source; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ case IRC::QUIT: break; /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has quit.' . $info . "\r\n"; $filename = 'QUIT'; //$this->msgChan; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $text = $timestamp . ' ' . $this->userNick . ' (~' . $this->userName . '@' . $this->userHost . ') has quit.' . $info . "\r\n"; $filename = 'QUIT'; //$this->msgChan; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ case IRC::KICK: break; /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $special = explode(' ', $this->source); $text = $timestamp . ' * ' . $special [1] . ' was kicked by ' . $special[0] . ' ' . $info . "\r\n"; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ /* $info = ($this->message) ? ' (' . $this->message . ')' : ''; $special = explode(' ', $this->source); $text = $timestamp . ' * ' . $special [1] . ' was kicked by ' . $special[0] . ' ' . $info . "\r\n"; return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ case IRC::NOTICE: break; /* return \Library\IRC\SaveData::push($text, $filepatch, $filename . '.log'); */ } } else { } }
private function settingFile($mode, $content = null, $object = null) { $object = $object ? $object : $this; $filename = (new ReflectionClass($object))->getShortName() . '.json'; switch ($mode) { case self::FILE_LOAD: $pathname = implode(DIRECTORY_SEPARATOR, [ROOT_DIR, self::SETTING_PATHNAME, Config::getServerName(), $filename]); if (!file_exists($pathname)) { return false; } return file_get_contents($pathname); case self::FILE_SAVE: $pathname = implode(DIRECTORY_SEPARATOR, [ROOT_DIR, self::SETTING_PATHNAME, Config::getServerName()]); if (!is_dir($pathname)) { mkdir($pathname, 0755, true); } $pathname = implode(DIRECTORY_SEPARATOR, [$pathname, $filename]); return file_put_contents($pathname, $content); } return false; }