Add subCommand property to event for easier subcommand recognition

This commit is contained in:
Szymon Uglis 2021-03-03 00:43:03 +01:00
parent bcd12ee369
commit 5714f9cdd0
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
2 changed files with 18 additions and 1 deletions

View file

@ -3,13 +3,29 @@ part of nyxx_interactions;
/// The event that you receive when a user types a slash command.
class InteractionEvent {
late final Nyxx _client;
/// The interaction data, includes the args, name, guild, channel, etc.
late final Interaction interaction;
/// The DateTime the interaction was received by the Nyxx Client.
final DateTime receivedAt = DateTime.now();
/// If the Client has sent a response to the Discord API. Once the API was received a response you cannot send another.
bool hasResponded = false;
/// Returns subcommand or null if not subcommand
InteractionOption? get subCommand {
if (this.interaction.args.isEmpty) {
return null;
}
try {
return this.interaction.args.firstWhere((element) => element.type == CommandArgType.subCommand);
} on Error {
return null;
}
}
InteractionEvent._new(this._client, Map<String, dynamic> rawJson) {
this.interaction = Interaction._new(this._client, rawJson);

View file

@ -6,7 +6,7 @@ class InteractionOption {
late final dynamic value;
/// Type of interaction
late final InteractionOption type;
late final CommandArgType type;
/// Name of option
late final String name;
@ -20,6 +20,7 @@ class InteractionOption {
InteractionOption._new(Map<String, dynamic> raw) {
this.value = raw["value"] as dynamic;
this.name = raw["name"] as String;
this.type = CommandArgType(raw["type"] as int);
if (raw["options"] != null) {
this.args = (raw["options"] as List<Map<String, dynamic>>).map((e) => InteractionOption._new(e));