Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-04-04 12:42:08 +02:00
Родитель 30cf5c289b
Коммит 074d5e3062
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
2 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@ -75,6 +75,32 @@ class AddSamples extends Base {
);
}
try {
$this->service->find('', 'calculator');
} catch (DoesNotExistException $e) {
$commands[] = $this->service->create(
'',
'calculator',
'Calculator',
$appPath . '/sample-commands/calc.sh "{ARGUMENTS_DOUBLEQUOTE_ESCAPED}"',
Command::RESPONSE_USER,
Command::ENABLED_ALL
);
}
try {
$this->service->find('', 'calc');
} catch (DoesNotExistException $e) {
$commands[] = $this->service->create(
'',
'calc',
'Calculator',
'alias:calculator',
Command::RESPONSE_ALL,
Command::ENABLED_ALL
);
}
try {
$this->service->find('', 'hackernews');
} catch (DoesNotExistException $e) {

28
sample-commands/calc.sh Executable file
Просмотреть файл

@ -0,0 +1,28 @@
#!/usr/bin/env bash
while test $# -gt 0; do
case "$1" in
--help)
echo "/calc - A basic calculator for Nextcloud Talk based on gnu BC"
echo "See the official documentation for more information:"
echo "https://www.gnu.org/software/bc/manual/html_mono/bc.html"
echo " "
echo "Simple equations: /calc 3 + 4 * 5"
echo "Complex equations: /calc sin(3) + 3^3 * sqrt(5)"
exit 0
;;
*)
break
;;
esac
done
CALCULATOR=$(which "bc")
if ! [ -x "$CALCULATOR" ]; then
echo "Basic calculator package (bc) not found"
exit 1
fi
set -f
echo "$@ ="
echo $(echo "$@" | bc)