public static function run(Command $command, Connection $connection, JsonConfig $config) { Logger::info(BashColor::HIGHLIGHT . "Nickname already in use."); $altNick = IRC::getInstance()->getConfig()->getData("alt_nickname", "FishIRC"); if (!$connection->isConnected() and $connection->getNick() !== $altNick) { $connection->changeNick($altNick); } }
public static function run(Command $command, Connection $connection, JsonConfig $config) { $channelName = $command->getArg(1); $userCount = $command->getArg(2); $args = $command->getArgs(); $topic = explode(":", implode(" ", $args), 2)[1]; $event = new ChannelListEvent($channelName, $userCount, $topic); $connection->getEventHandler()->callEvent($event); }
public static function getChannel(Connection $connection, string $name) { if (isset(self::$channels[$connection->getAddress()][$name])) { return self::$channels[$connection->getAddress()][$name]; } else { $channel = new Channel($connection, $name); self::$channels[$connection->getAddress()][$name] = $channel; return $channel; } }
public static function run(Command $command, Connection $connection, JsonConfig $config) { $ev = new PingEvent(); $connection->getEventHandler()->callEvent($ev); $ev = new PongEvent(); $connection->getEventHandler()->callEvent($ev); if (!$ev->isCancelled()) { $connection->lastPing = time(); $connection->sendData("PONG " . $command->getArgs()[0]); //Reply to Pings } }
public function __construct(string $name, array $json, Connection $connection) { if (file_exists("phar://plugins" . DIRECTORY_SEPARATOR . $name . ".phar" . DIRECTORY_SEPARATOR . "plugin.json")) { Logger::info(BashColor::GREEN . "Loading plugin " . BashColor::BLUE . $name); $this->name = $json["name"]; $this->description = $json["description"]; $this->apiVersion = $json["api"]; $this->version = $json["version"]; $this->author = $json["author"]; $this->main = $json["main"]; //Instantiating plugins $info = new \SplFileInfo("phar://plugins" . DIRECTORY_SEPARATOR . $name . ".phar" . DIRECTORY_SEPARATOR . $this->main); $class = new \ReflectionClass("\\" . $name . "\\" . $info->getBasename(".php")); //Taking care of using the correct namespace $this->class = $class->newInstanceWithoutConstructor(); $this->reflectionClass = $class; $this->class->connection = $connection; $this->class->plugin = $this; //Registering commands if (isset($json["commands"])) { $this->commands = $json["commands"]; foreach ($this->commands as $command => $settings) { // Set description $description = !empty($settings["description"]) ? $settings["description"] : ""; // Set usage help $usage = !empty($settings["usage"]) ? $settings["usage"] : $command; // Set required permission $permission = !empty($settings["permission"]) ? $settings["permission"] : false; //Default permission is false $command = new Command($command, $this->class, $permission, $description, $usage); // Add aliases if (isset($settings["aliases"]) && is_array($settings["aliases"])) { foreach ($settings["aliases"] as $alias) { $command->addAlias($alias); } } $connection->getCommandMap()->registerCommand($command, $this); } } } }
public static function run(Command $command, Connection $connection, JsonConfig $config) { $ev = new ConnectionFinishedEvent($connection); $connection->getEventHandler()->callEvent($ev); if (!$ev->isCancelled()) { $config = IRC::getInstance()->getConfig()->getData("connections"); if (!empty($config[$connection->getAddress()]["nickserv"])) { $connection->getNickServ()->identify($config[$connection->getAddress()]["nickserv"]); //Identify with NickServ } if (!empty($config[$connection->getAddress()]["channels"])) { $channels = $config[$connection->getAddress()]["channels"]; foreach ($channels as $channel) { $connection->joinChannel(Channel::getChannel($connection, $channel)); //Join these channels } } } }
public function getScheduler() : Scheduler { return $this->connection->getScheduler(); }
/** * Close a connection * @param Connection $connection * @param String $quitMessage * @return bool */ public function removeConnection(Connection $connection, string $quitMessage = null) : bool { if ($this->isConnected($connection->getAddress())) { Logger::info(BashColor::RED . "Disconnecting " . $connection->getAddress() . ":" . $connection->getPort()); if ($quitMessage === null) { $quitMessage = $this->config->getData("default_quitmsg", "Leaving"); } $connection->disconnect($quitMessage); unset($this->connections[$connection->getAddress()]); return true; } else { unset($this->connections[$connection->getAddress()]); return true; //These statements are kept for reasons of backwards-compatibility } }
public function testIncomingMessageIsParsedCorrectly() { $result = $this->connection->check("fish~!someone@example.com KICK #fish-irc fish"); $this->assertInstanceOf("\\IRC\\Command", $result); }
public function __construct(Connection $connection) { $connection->getCommandMap()->registerCommand(new JoinCommand($connection)); $connection->getCommandMap()->registerCommand(new PartCommand($connection)); $connection->getCommandMap()->registerCommand(new HelpCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginLoadCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginUnloadCommand($connection)); $connection->getCommandMap()->registerCommand(new PluginsListCommand($connection)); $connection->getCommandMap()->registerCommand(new WhoamiCommand($connection)); $connection->getCommandMap()->registerCommand(new RawCommand($connection)); $connection->getCommandMap()->registerCommand(new SayCommand($connection)); $connection->getCommandMap()->registerCommand(new NickCommand($connection)); $connection->getCommandMap()->registerCommand(new ReloadCommand($connection)); $connection->getCommandMap()->registerCommand(new StopCommand($connection)); }
/** * @param Connection $connection * @param $name * @return bool */ public static function removeUser(Connection $connection, $name) { if (isset(self::$users[$connection->getAddress()][$name])) { unset(self::$users[$connection->getAddress()][$name]); return true; } return false; }