Example #1
0
 /**
  * Execute the console command.
  *
  * @param Repository $config
  * @param Container $container
  *
  * @return mixed
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \LogicException
  * @throws \Exception
  */
 public function handle(Repository $config, Container $container)
 {
     $started = Carbon::now();
     $client = Client::make($config->get('gitter.token'), $this->argument('room'));
     $stream = $container->make(Room::class)->listen();
     $this->line(sprintf(' Gitter Bot %s started at %s', Client::VERSION, $started->toDateTimeString()));
     $client->getEventLoop()->addPeriodicTimer(1, function () use($started) {
         $memory = number_format(memory_get_usage(true) / 1000 / 1000, 2);
         $uptime = Carbon::now()->diff($started);
         $this->output->write("\r" . sprintf('[memory: %smb] [uptime: %s]%60s', $memory, $uptime->format('%Y.%M.%D %H:%I:%S'), ''));
     });
     $startClient = function () use($client) {
         $this->makePidFile();
         $client->run();
     };
     $startClient();
     $this->removePidFile();
 }
Example #2
0
 /**
  * @param Repository $config
  * @param Container $container
  */
 public function syncUsers(Repository $config, Container $container)
 {
     $this->output->write('Start user sync...');
     $config->set('gitter.output', false);
     $client = Client::make($config->get('gitter.token'), $this->argument('room'));
     $room = $container->make(Room::class);
     $users = $client->request('room.users', ['roomId' => $room->id]);
     $message = "\r<comment>[%s/%s]</comment> %s%80s";
     $count = count($users);
     $current = 1;
     foreach ($users as $user) {
         $user = User::fromGitterObject($user);
         $this->output->write(sprintf($message, $current, $count, $user->login, ''));
         $current++;
     }
     $this->output->write(sprintf($message, $count, $count, 'OK', ''));
 }