/** * @param string $event * @param string|string[] $type * @param Event $payload */ private function trigger($event, $type = null, $payload = null) { NielsBot::getInstance()->triggerEvent($event, $type, $payload); }
use NielsBot\Core\NielsBot; use NielsBot\Plugins\Plugin; use NielsBot\Plugins\CommandEvent; $commonPlugin = new Plugin('Common', 'Basic functions for bot'); $commonPlugin->on('command', ['plugins'], function (CommandEvent $event) { $message = '*Plugin list*' . PHP_EOL . PHP_EOL; foreach (NielsBot::getInstance()->getPlugins() as $plugin) { $message .= '*' . $plugin->getName() . '*' . PHP_EOL; $message .= $plugin->getDescription() . PHP_EOL; $message .= PHP_EOL; } $event->getChat()->sendMessage($message); }); $commonPlugin->on('command', ['help', 'commands'], function (CommandEvent $event) { $message = '*Command list*' . PHP_EOL . PHP_EOL; foreach (NielsBot::getInstance()->getPlugins() as $plugin) { $message .= '*' . $plugin->getName() . '*' . PHP_EOL; $i = 0; foreach ($plugin->getEvents() as $type => $commands) { if ($type === 'command') { foreach ($commands as $command => $exec) { $i++; $message .= '/' . $command . PHP_EOL; } } } if ($i == 0) { $message .= '_No commands_' . PHP_EOL; } $message .= PHP_EOL; }
/** * @param string $string */ public function sendMessage($string) { Telegram::api('sendMessage', ['chat_id' => $this->id, 'text' => NielsBot::getInstance()->getEmojiParser()->parse($string), 'parse_mode' => 'markdown']); }
public function __construct($name, $description) { $this->name = $name; $this->description = $description; NielsBot::getInstance()->registerPlugin($this); }