Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Sqwack/Command/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected function configure()
$this->addOption('device', 'd', InputOption::VALUE_REQUIRED, 'The name of camera to use. Use `imagesnap -l` to find a list of available devices.');
$this->addOption('team', 't', InputOption::VALUE_REQUIRED, 'The team domain, e.g. "test" if you access Slack on https://test.slack.com.');
$this->addOption('sleep', 's', InputOption::VALUE_REQUIRED, 'The number of minutes to wait before taking the next photo. Defaults to 3.');
$this->addOption('slack-app-open', 'a', InputOption::VALUE_OPTIONAL, "Don't snap if Slack.app is not running. Default to 0.");
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -42,6 +43,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$snapOptions['--team'] = $input->getOption('team');
}

if ($input->getOption('slack-app-open')) {
$snapOptions['--slack-app-open'] = $input->getOption('slack-app-open');
}

$snapInput = new ArrayInput($snapOptions);

while (true) {
Expand Down
12 changes: 12 additions & 0 deletions src/Sqwack/Command/SnapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected function configure()

$this->addOption('device', 'd', InputOption::VALUE_REQUIRED, 'The name of camera to use. Use `imagesnap -l` to find a list of available devices.');
$this->addOption('team', 't', InputOption::VALUE_REQUIRED, 'The team domain, e.g. "test" if you access Slack on https://test.slack.com.');
$this->addOption('slack-app-open', 'a', InputOption::VALUE_OPTIONAL, "Don't snap if Slack.app is not running. Default to 0.");
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -38,6 +39,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \InvalidArgumentException('The team domain option --team must be provided');
}

if ($input->getOption('slack-app-open')) {
$exec_result=null;
// Next command tries to see if Slack.app is running, if so, we get back a 1 with some spaces as a result
// if not we get back a 0 with some spaces before
exec('ps aux | grep "[S]lack.app" | wc -l',$exec_result);
$slackapp_is_running = $exec_result[0]*1;
if(!$slackapp_is_running) {
$output->writeln('<error>slack-app-open option is set but Slack.app is not running</error>');
}
}

$client = new Client([
'base_url' => sprintf('https://%s.slack.com', $team),
'defaults' => [
Expand Down