/** * Executes a command. * @param CommandEvent $e The data received. */ public function execCommand($e) { if (empty($e->getParams())) { $this->bot->say('Not enough parameters. Usage: exec [code to execute]'); return; } $this->bot->log('Running command "{command}"', array('command' => implode(' ', $e->getParams())), LogLevels::INFO); eval(implode(' ', $e->getParams())); }
/** * The help command itself. * @param CommandEvent $e The data received. */ public function helpCommand($e) { $commands = $this->evman()->getEvent('BotCommand')->getCommands(); if (empty($e->getParams())) { // All commands are... $this->bot->say('Available commands: ' . implode(', ', $commands)); } else { $command = strtolower($e->getParams()[0]); if (!in_array($command, $commands)) { $this->bot->say('Command ' . $command . ' does not exist or is not known to me.'); return; } if (!array_key_exists($command, $this->strings)) { $this->bot->say('There is no help available for command ' . $command); return; } $this->bot->say($command . ': ' . $this->strings[$command]); } }
/** * The Say command. * @param CommandEvent $e The data received. */ public function sayCommand($e) { if (empty($e->getParams())) { return; } if (Validation::isChannel($e->getParams()[0])) { $args = $e->getParams(); $to = array_shift($args); $message = implode(' ', $args); } else { $to = $e->getMessage()->getTargets(); $message = implode(' ', $e->getParams()); } if ($to === null) { return; } $this->bot->say($to, $message); }
/** * The Part command. * @param CommandEvent $e The last data received. */ public function partCommand(CommandEvent $e) { // If no argument specified, attempt to leave the current channel. if (empty($e->getParams())) { $c = array($e->getMessage()->getChannel()); } else { $c = $e->getParams(); } foreach ($c as $chan) { $this->bot->sendData('PART ' . $chan); } }
/** * Try to get a channel out of the gathered data. * @param CommandEvent $e The last data received. * @return false|string False on failure, channel as string on success. */ public function parseChannel($e) { if (empty($e->getParams())) { return false; } $parts = $e->getParams(); if (Validation::isChannel($parts[0])) { $chan = array_shift($parts); } else { $chan = $e->getMessage()->getTargets(); } if ($chan === null) { return false; } return $chan; }