Add subCommand property to event for easier subcommand recognition
This commit is contained in:
parent
bcd12ee369
commit
5714f9cdd0
|
@ -3,13 +3,29 @@ part of nyxx_interactions;
|
||||||
/// The event that you receive when a user types a slash command.
|
/// The event that you receive when a user types a slash command.
|
||||||
class InteractionEvent {
|
class InteractionEvent {
|
||||||
late final Nyxx _client;
|
late final Nyxx _client;
|
||||||
|
|
||||||
/// The interaction data, includes the args, name, guild, channel, etc.
|
/// The interaction data, includes the args, name, guild, channel, etc.
|
||||||
late final Interaction interaction;
|
late final Interaction interaction;
|
||||||
|
|
||||||
/// The DateTime the interaction was received by the Nyxx Client.
|
/// The DateTime the interaction was received by the Nyxx Client.
|
||||||
final DateTime receivedAt = DateTime.now();
|
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.
|
/// 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;
|
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) {
|
InteractionEvent._new(this._client, Map<String, dynamic> rawJson) {
|
||||||
this.interaction = Interaction._new(this._client, rawJson);
|
this.interaction = Interaction._new(this._client, rawJson);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class InteractionOption {
|
||||||
late final dynamic value;
|
late final dynamic value;
|
||||||
|
|
||||||
/// Type of interaction
|
/// Type of interaction
|
||||||
late final InteractionOption type;
|
late final CommandArgType type;
|
||||||
|
|
||||||
/// Name of option
|
/// Name of option
|
||||||
late final String name;
|
late final String name;
|
||||||
|
@ -20,6 +20,7 @@ class InteractionOption {
|
||||||
InteractionOption._new(Map<String, dynamic> raw) {
|
InteractionOption._new(Map<String, dynamic> raw) {
|
||||||
this.value = raw["value"] as dynamic;
|
this.value = raw["value"] as dynamic;
|
||||||
this.name = raw["name"] as String;
|
this.name = raw["name"] as String;
|
||||||
|
this.type = CommandArgType(raw["type"] as int);
|
||||||
|
|
||||||
if (raw["options"] != null) {
|
if (raw["options"] != null) {
|
||||||
this.args = (raw["options"] as List<Map<String, dynamic>>).map((e) => InteractionOption._new(e));
|
this.args = (raw["options"] as List<Map<String, dynamic>>).map((e) => InteractionOption._new(e));
|
||||||
|
|
Loading…
Reference in a new issue