Skip to content

Commit

Permalink
fix(chat): Remove commands
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Apr 12, 2024
1 parent a2bc199 commit 0488b36
Show file tree
Hide file tree
Showing 34 changed files with 15 additions and 2,024 deletions.
9 changes: 0 additions & 9 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<step>OCA\Talk\Migration\FixNamespaceInDatabaseTables</step>
</pre-migration>
<post-migration>
<step>OCA\Talk\Migration\CreateHelpCommand</step>
<step>OCA\Talk\Migration\ClearResourceAccessCache</step>
<step>OCA\Talk\Migration\CacheUserDisplayNames</step>
</post-migration>
<install>
<step>OCA\Talk\Migration\CreateHelpCommand</step>
</install>
</repair-steps>

<commands>
Expand All @@ -89,11 +85,6 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<command>OCA\Talk\Command\Bot\State</command>
<command>OCA\Talk\Command\Bot\Setup</command>
<command>OCA\Talk\Command\Bot\Uninstall</command>
<command>OCA\Talk\Command\Command\Add</command>
<command>OCA\Talk\Command\Command\AddSamples</command>
<command>OCA\Talk\Command\Command\Delete</command>
<command>OCA\Talk\Command\Command\ListCommand</command>
<command>OCA\Talk\Command\Command\Update</command>
<command>OCA\Talk\Command\Developer\UpdateDocs</command>
<command>OCA\Talk\Command\Monitor\Calls</command>
<command>OCA\Talk\Command\Monitor\HasActiveCalls</command>
Expand Down
1 change: 0 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
include(__DIR__ . '/routes/routesCallController.php'),
include(__DIR__ . '/routes/routesCertificateController.php'),
include(__DIR__ . '/routes/routesChatController.php'),
include(__DIR__ . '/routes/routesCommandController.php'),
include(__DIR__ . '/routes/routesFederationController.php'),
include(__DIR__ . '/routes/routesFilesIntegrationController.php'),
include(__DIR__ . '/routes/routesGuestController.php'),
Expand Down
35 changes: 0 additions & 35 deletions appinfo/routes/routesCommandController.php

This file was deleted.

99 changes: 1 addition & 98 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,4 @@

!!! warning

**Deprecation:** Commands are deprecated in favor of [Bots](bots.md).

---

!!! 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.
**Deprecation:** Commands have been removed in favor of [Bots](bots.md).
11 changes: 0 additions & 11 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,6 @@ listen to the `OCA\Talk\Events\SystemMessagesMultipleSentEvent` event instead.
* Since: 18.0.0
* Since: 19.0.0 - Method `getParent()` was added

### Deprecated events

These events were not using the typed-event mechanism and are therefore deprecated and will be removed in a future version.

#### Command execution for apps

* Event class: `OCA\Talk\Events\CommandEvent`
* Event name: `OCA\Talk\Chat\Command\Executor::EVENT_APP_EXECUTE`
* Since: 8.0.0
* Deprecated: 17.0.0 - Commands are deprecated, please migrate to bots instead

## Other events

### Turn servers get
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* [Call experience](call-experience.md)
* [Occ commands](occ.md)
* [Bots](bot-list.md)
* [Commands (deprecated)](commands.md)
* [Matterbridge integration](matterbridge.md)

## Developer documentation
Expand Down
77 changes: 0 additions & 77 deletions docs/occ.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,83 +106,6 @@ Uninstall a bot from the server
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | `'plain'` |
| `--url` | The URL of the bot (required when no ID is given, ignored otherwise) | yes | yes | no | *Required* |

## talk:command:add

Add a new command

### Usage

* `talk:command:add [--output [OUTPUT]] [--] <cmd> <name> <script> <response> <enabled>`

| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
| `cmd` | The command as used in the chat "/help" => "help" | yes | no | *Required* |
| `name` | Name of the user posting the response | yes | no | *Required* |
| `script` | Script to execute (Must be using absolute paths only) | yes | no | *Required* |
| `response` | Who should see the response: 0 - No one, 1 - User, 2 - All | yes | no | *Required* |
| `enabled` | Who can use this command: 0 - Disabled, 1 - Moderators, 2 - Users, 3 - Guests | yes | no | *Required* |

| Options | Description | Accept value | Is value required | Is multiple | Default |
|---|---|---|---|---|---|
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | `'plain'` |

## talk:command:add-samples

Adds some sample commands: /wiki, …

### Usage

* `talk:command:add-samples`

## talk:command:delete

Remove an existing command

### Usage

* `talk:command:delete <command-id>`

| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
| `command-id` | | yes | no | *Required* |

## talk:command:list

List all available commands

### Usage

* `talk:command:list [--output [OUTPUT]] [--] [<app>]`

| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
| `app` | Only list the commands of a specific app, "custom" to list all custom commands | no | no | `NULL` |

| Options | Description | Accept value | Is value required | Is multiple | Default |
|---|---|---|---|---|---|
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | `'plain'` |

## talk:command:update

Add a new command

### Usage

* `talk:command:update [--output [OUTPUT]] [--] <command-id> <cmd> <name> <script> <response> <enabled>`

| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
| `command-id` | | yes | no | *Required* |
| `cmd` | The command as used in the chat "/help" => "help" | yes | no | *Required* |
| `name` | Name of the user posting the response | yes | no | *Required* |
| `script` | Script to execute (Must be using absolute paths only) | yes | no | *Required* |
| `response` | Who should see the response: 0 - No one, 1 - User, 2 - All | yes | no | *Required* |
| `enabled` | Who can use this command: 0 - Disabled, 1 - Moderators, 2 - Users, 3 - Guests | yes | no | *Required* |

| Options | Description | Accept value | Is value required | Is multiple | Default |
|---|---|---|---|---|---|
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | `'plain'` |

## talk:monitor:calls

Prints a list with conversations that have an active call as well as their participant count
Expand Down
7 changes: 0 additions & 7 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
use OCA\Talk\Activity\Listener as ActivityListener;
use OCA\Talk\Capabilities;
use OCA\Talk\Chat\Changelog\Listener as ChangelogListener;
use OCA\Talk\Chat\Command\Listener as CommandListener;
use OCA\Talk\Chat\Listener as ChatListener;
use OCA\Talk\Chat\Parser\Changelog;
use OCA\Talk\Chat\Parser\Command;
use OCA\Talk\Chat\Parser\ReactionParser;
use OCA\Talk\Chat\Parser\SystemMessage;
use OCA\Talk\Chat\Parser\UserMention;
Expand All @@ -57,7 +55,6 @@
use OCA\Talk\Events\BeforeAttendeeRemovedEvent;
use OCA\Talk\Events\BeforeAttendeesAddedEvent;
use OCA\Talk\Events\BeforeCallEndedForEveryoneEvent;
use OCA\Talk\Events\BeforeChatMessageSentEvent;
use OCA\Talk\Events\BeforeDuplicateShareSentEvent;
use OCA\Talk\Events\BeforeGuestJoinedRoomEvent;
use OCA\Talk\Events\BeforeParticipantModifiedEvent;
Expand Down Expand Up @@ -219,15 +216,11 @@ public function register(IRegistrationContext $context): void {

// Chat parser
$context->registerEventListener(MessageParseEvent::class, Changelog::class, -75);
$context->registerEventListener(MessageParseEvent::class, Command::class);
$context->registerEventListener(MessageParseEvent::class, ReactionParser::class);
$context->registerEventListener(MessageParseEvent::class, SystemMessage::class);
$context->registerEventListener(MessageParseEvent::class, SystemMessage::class, 9999);
$context->registerEventListener(MessageParseEvent::class, UserMention::class, -100);

// Command listener
$context->registerEventListener(BeforeChatMessageSentEvent::class, CommandListener::class);

// Files integration listeners
$context->registerEventListener(BeforeGuestJoinedRoomEvent::class, FilesListener::class);
$context->registerEventListener(BeforeUserJoinedRoomEvent::class, FilesListener::class);
Expand Down
4 changes: 1 addition & 3 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ public function sendMessage(
string $referenceId = '',
bool $silent = false,
bool $rateLimitGuestMentions = true,
bool $forceLastMessageUpdate = false, // Remove when dropping commands
): IComment {
if ($chat->isFederatedConversation()) {
$e = new MessagingNotAllowedException();
Expand Down Expand Up @@ -354,10 +353,9 @@ public function sendMessage(
$this->participantService->updateLastReadMessage($participant, (int) $comment->getId());
}

// Update last_message (not for commands)
// Update last_message
if ($comment->getActorType() !== Attendee::ACTOR_BOTS
|| $comment->getActorId() === Attendee::ACTOR_ID_CHANGELOG
|| $forceLastMessageUpdate
|| str_starts_with($comment->getActorId(), Attendee::ACTOR_BOT_PREFIX)) {
$this->roomService->setLastMessage($chat, $comment);
$this->unreadCountCache->clear($chat->getId() . '-');
Expand Down
Loading

0 comments on commit 0488b36

Please sign in to comment.