registerCommand method
Registers the command name of ownerId on the instance (or scopeKind and
scopeId) and appends command.changed; returns its ID.
Implementation
String registerCommand(
String ownerId,
String name, {
String description = '',
List<JsonMap> options = const [],
bool control = false,
String scopeKind = 'instance',
String? scopeId,
FakeAutocomplete? autocomplete,
}) {
final id = world.nextId();
final command = <String, Object?>{
'id': id,
'owner_principal_id': ownerId,
'name': name,
'description': description,
'scope_kind': scopeKind,
'scope_id': ?scopeId,
'options': options,
'required_level': 'trigger',
'control': control,
'version': 1,
};
commands[id] = command;
if (autocomplete != null) suggestions[id] = autocomplete;
world.append(
'command.changed',
resource: {'kind': 'command', 'id': id, 'version': 1},
scope: {
if (scopeKind == 'channel') 'channel_id': scopeId,
if (scopeKind == 'space') 'space_id': scopeId,
},
payload: {'command': command, 'change': 'registered'},
actor: ownerId,
);
return id;
}