/** * Dynamically loads a plugin by name. * * @param string $className Fully qualified plugin class name * @param array $options Options * * @throws \Exception */ public function load($className, $options) { if (!class_exists($className)) { throw new \Exception('The plugin class "' . $className . '" could not be found.'); } // make sure the class implements the plugin interface if (!in_array(PluginInterface::class, class_implements($className))) { throw new \Exception('The class "' . $className . '" is not a plugin.'); } try { /** @var PluginInterface $instance */ $instance = new $className($this->bot, $this); foreach ($options as $key => $value) { if (property_exists($instance, $key)) { $instance->{$key} = $value; } else { throw new \Exception('Unknown plugin parameter: ' . $key); } } $instance->enable(); $this->plugins[$className] = $instance; $this->bot->getApplication()->getLogger()->info('Plugin initialized: ' . $className); } catch (\Exception $exception) { throw new \Exception('Error in loading plugin "' . $className . '": ' . $exception->getMessage()); } }
public function run() { $options = getopt('hc:', ['help', 'config:']); if (isset($options['h']) || isset($options['help'])) { $this->showHelp(); exit(0); } try { $this->initLogger(); $this->initConfig($options); $bot = new Bot($this); $bot->run(); } catch (FileNotFoundException $exception) { $this->error(1, 'Config file was not found. Use -c option to specify config path or provide slacky.json root file.'); } catch (\Exception $exception) { $this->error(2, $exception->getMessage()); } }
/** * Messaging helper. Sends message to last message channel with sender username mentioning. * * @param $message */ public function reply($message) { $this->bot->say(sprintf('%s, %s', $this->lastMessageUser->getUsername(), $message), $this->lastMessageChannel); }