Interactions constructor

Interactions(
  1. Nyxx _client
)

Create new instance of the interactions class.

Implementation

Interactions(this._client) {
  _events = _EventController(this);
  _client.options.dispatchRawShardEvent = true;
  this.interactionsEndpoints = _InteractionsEndpoints(_client);

  _logger.info("Interactions ready");

  _client.onReady.listen((event) async {
    _client.shardManager.rawEvent.listen((event) {
      if (event.rawData["op"] == OPCodes.dispatch && event.rawData["t"] == _interactionCreateCommand) {
        this._logger.fine("Received interaction event: [${event.rawData}]");

        final type = event.rawData["d"]["type"] as int;

        switch (type) {
          case 2:
            _events.onSlashCommand.add(SlashCommandInteractionEvent._new(this, event.rawData["d"] as RawApiMap));
            break;
          case 3:
            final componentType = event.rawData["d"]["data"]["component_type"] as int;

            switch (componentType) {
              case 2:
                _events.onButtonEvent
                    .add(ButtonInteractionEvent._new(this, event.rawData["d"] as Map<String, dynamic>));
                break;
              case 3:
                _events.onMultiselectEvent
                    .add(MultiselectInteractionEvent._new(this, event.rawData["d"] as Map<String, dynamic>));
                break;
              default:
                this
                    ._logger
                    .warning("Unknown componentType type: [$componentType]; Payload: ${jsonEncode(event.rawData)}");
            }
            break;
          case 4:
            _events.onAutocompleteEvent
                .add(AutocompleteInteractionEvent._new(this, event.rawData["d"] as Map<String, dynamic>));
            break;
          default:
            this._logger.warning("Unknown interaction type: [$type]; Payload: ${jsonEncode(event.rawData)}");
        }
      }
    });
  });
}