Ejemplo n.º 1
0
 /**
  *
  */
 protected function init()
 {
     if (Cerberus::isExecAvailable()) {
         exec('gpio -v', $outputArray);
         $output = implode(' ', $outputArray);
         $pos = strpos($output, 'Raspberry Pi');
         if ($pos !== false) {
             $info = substr($output, $pos);
             preg_match_all('/Type:\\s*([^,:]+),\\s*Revision:\\s*([^,:]+),\\s*Memory:\\s*([^,:]+),\\s*Maker:\\s*([^,:]+)\\s*$/i', $info, $matches, PREG_SET_ORDER);
             $this->info['type'] = $matches[0][1];
             $this->info['revision'] = $matches[0][2];
             $this->info['memory'] = $matches[0][3];
             $this->info['maker'] = $matches[0][4];
             $this->setOut(self::LED_GREEN);
             $this->setOut(self::LED_BLUE);
             $this->setOut(self::LED_RED);
             $this->blink(self::LED_GREEN);
             $this->blink(self::LED_BLUE);
             $this->blink(self::LED_RED);
             $this->setIn(self::DHT);
             $this->addEvent('onPrivmsg');
             $this->addEvent('onJoin');
             $this->addEvent('onPart');
             $this->addEvent('onQuit');
             $this->addEvent('onShutdown');
             $this->addEvent('onControl');
             $this->addCron('0 * * * *', 'privmsgCpuTemp');
         } else {
             $this->sysinfo('This Plugin is only for the RaspberryPi with WiringPi.');
             $this->sysinfo('http://www.raspberrypi.org');
             $this->sysinfo('http://wiringpi.com');
         }
     } else {
         $this->sysinfo('Can\'t use this Plugin, because "exec" is disabled');
     }
 }
Ejemplo n.º 2
0
 * with this program; if not, see <http://www.gnu.org/licenses/>.
 */
# m     h       dom     mon     dow     command
# */1   *       *       *       *       php -f /home/user/projects/cerberus/bin/autostart.php >/dev/null
chdir(__DIR__);
if (file_exists('../vendor/autoload.php')) {
    require_once '../vendor/autoload.php';
} else {
    echo 'You must set up the project dependencies, run the following commands:' . PHP_EOL;
    echo 'curl -s https://getcomposer.org/installer | php' . PHP_EOL;
    echo 'php composer.phar install' . PHP_EOL;
    exit;
}
use Cerberus\Cerberus;
use Cerberus\Db;
if (Cerberus::isExecAvailable() === false) {
    echo 'Can\'t run the bot, because "exec" is disabled' . PHP_EOL;
    exit;
}
if (is_dir('../.git') === true) {
    chdir(dirname(__DIR__));
    exec('git pull', $output);
    $console = Cerberus::getConsole();
    $console->writeln('<comment>git pull</comment>');
    foreach ($output as $line) {
        $console->writeln('<info>' . $line . '</info>');
    }
    unset($output);
    chdir(__DIR__);
}
if (file_exists('../vendor/bin/phpunit') === true) {
Ejemplo n.º 3
0
 /**
  * @param string $text
  * @param bool $escape
  * @param mixed $length
  * @param bool $break
  * @param bool $wordwrap
  * @param int $offset
  * @return string
  */
 public function prepare($text, $escape = true, $length = null, $break = true, $wordwrap = true, $offset = 0)
 {
     if (isset($this->param) && is_array($this->param) && in_array('-noconsole', $this->param, true)) {
         return $escape ? $this->escape($text) : $text;
     }
     $formatter = FormatterFactory::console();
     $text = $formatter->bold($text);
     $text = $formatter->underline($text);
     $text = $formatter->color($text);
     if ($length === false) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     if ($length === null) {
         if (Cerberus::isExecAvailable() === false) {
             return $escape ? $this->escape($text) : $text;
         }
         preg_match('/columns\\s([0-9]+);/', strtolower(exec('stty -a | grep columns')), $matches);
         if (isset($matches[1]) === false) {
             return $escape ? $this->escape($text) : $text;
         }
         $length = $matches[1];
     }
     $length = $length - $offset;
     if ($this->len($text) <= $length) {
         $text .= substr($text, -1) === '\\' ? ' ' : '';
         return $escape ? $this->escape($text) : $text;
     }
     $text = utf8_decode($text);
     if ($break === true) {
         if ($wordwrap === true) {
             $text = $this->wordwrap($text, $length);
         } else {
             $text = $this->split($text, $length, PHP_EOL);
         }
         $text = str_replace(PHP_EOL, PHP_EOL . str_repeat(' ', $offset), $text);
     } else {
         $text = $this->cut($text, $length - 3) . '...';
         if (strpos($text, "") !== false) {
             $text .= "";
         }
     }
     $text = utf8_encode($text);
     $text .= substr($text, -1) === '\\' ? ' ' : '';
     return $escape ? $this->escape($text) : $text;
 }
Ejemplo n.º 4
0
 /**
  * @param Event $event
  */
 protected static function runPhpUnit(Event $event)
 {
     $io = $event->getIO();
     if (file_exists(Cerberus::getPath() . '/vendor/bin/phpunit') === false) {
         $io->write('<error>Can\'t find "PHPUnit".</error>');
     } elseif (Cerberus::isExecAvailable() === false) {
         $io->write('<error>Can\'t run "PHPUnit", because "exec" is disabled.</error>');
     } else {
         $output = [];
         exec(Cerberus::getPath() . '/vendor/bin/phpunit', $output);
         foreach ($output as $line) {
             $io->write('<comment>' . $line . '</comment>');
         }
     }
 }