blob: 3aca4e063909b48f506db9f5d72e582419ae4772 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# Chat commands
!!! note
For security reasons commands can only be added via the
command line. `./occ talk:command:add --help` gives you
a short overview of the required arguments, but they are
explained here in more depth.
---
## "Add command" arguments
| Argument | Allowed chars | Description |
|------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cmd` | [a-z0-9] | The keyword the user has to type to run this command (min. 1, max. 64 characters) |
| `name` | * | The author name of the response that is posted by the command (min. 1, max. 64 characters) |
| `script` | * | Actual command that is being ran. The script must be executable by the user of your webserver and has to use absolute paths only! See the parameter table below for options. The script is invoked with `--help` as argument on set up, to check if it can be executed correctly. |
| `response` | 0-2 | Who should see the response: 0 - No one, 1 - User who executed the command, 2 - Everyone |
| `enabled` | 0-3 | Who can use the command: 0 - No one, 1 - Moderators of the room, 2 - Logged in users, 3 - Everyone |
## Script parameter
| Parameter | Description |
|---------------|----------------------------------------------------|
| `{ROOM}` | The token of the room the command was used in |
| `{USER}` | ID of the user that called the command |
| `{ARGUMENTS}` | Everything the user write after the actual command |
## Example
### Create `/path/to/calc.sh`
```
while test $# -gt 0; do
case "$1" in
--help)
echo "/calc - A Nextcloud Talk chat wrapper for gnome-calculator"
echo " "
echo "Simple equations: /calc 3 + 4 * 5"
echo "Complex equations: /calc sin(3) + 3^3 * sqrt(5)"
exit 0
;;
*)
break
;;
esac
done
set -f
echo "$@ ="
echo $(gnome-calculator --solve="$@")
```
Please note, that your command should also understand the argument `--help`.
It should return a useful description, the first line is also displayed in a list of all commands when the user just types `/help`.
### Register command
Make sure to use the absolute path to your script when registering the command:
```
./occ talk:command:add calculator calculator "/path/to/calc.sh {ARGUMENTS} {ROOM} {USER}" 1 3
```
### Explanation
* User input by user `my user id` in the chat of room `index.php/call/4tf349j`:
```
/calculator 1 + 2 + 3 + "hello"
```
* Executed shell command:
```
/path/to/calc.sh '1 + 2 + 3 + "hello"' '4tf349j' 'my user id'
```
## Aliases
It is also possible to define an alias for a command. This allows e.g. to get the `/help` command also with the german word `/hilfe`.
An alias for the `/calculator` command from above could be created using the following command:
```
./occ talk:command:add calc calculator "alias:calculator" 1 3
```
Now `/calculator 1 + 2 + 3` and `/calc 1 + 2 + 3` result in the same message.
!!! note
The enabled and response flag of the alias are ignored and the flags of the original command will be used and respected.
|