Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #58 from nyxx-discord/hotfix/handler-not-found
Browse files Browse the repository at this point in the history
Correctly select handler for global commands
  • Loading branch information
abitofevrything authored Aug 2, 2022
2 parents 661982c + 94fc5c5 commit 4f3e873
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.3.1
__01.08.2022__

- bug: Fix global commands selecting guild command handlers

## 4.3.0
__29.07.2022__

Expand Down
4 changes: 2 additions & 2 deletions lib/src/interactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Interactions implements IInteractions {

if (_commandHandlers.isNotEmpty) {
events.onSlashCommand.listen((event) async {
final commandHash = determineInteractionCommandHandler(event.interaction);
final commandHash = determineInteractionCommandHandler(event.interaction, this);

_logger.info("Executing command with hash [$commandHash]");
if (_commandHandlers.containsKey(commandHash)) {
Expand Down Expand Up @@ -257,7 +257,7 @@ class Interactions implements IInteractions {
if (_autocompleteHandlers.isNotEmpty) {
events.onAutocompleteEvent.listen((event) {
final name = event.focusedOption.name;
final commandHash = determineInteractionCommandHandler(event.interaction);
final commandHash = determineInteractionCommandHandler(event.interaction, this);
final autocompleteHash = "$commandHash$name";

if (_autocompleteHandlers.containsKey(autocompleteHash)) {
Expand Down
10 changes: 7 additions & 3 deletions lib/src/internal/utils.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:nyxx/nyxx.dart';

import 'package:nyxx_interactions/src/builders/slash_command_builder.dart';
import 'package:nyxx_interactions/src/interactions.dart';
import 'package:nyxx_interactions/src/models/command_option.dart';
import 'package:nyxx_interactions/src/models/interaction_option.dart';
import 'package:nyxx_interactions/src/models/interaction.dart';
import 'package:nyxx_interactions/src/models/slash_command.dart';

/// Slash command names and subcommands names have to match this regex
final RegExp slashCommandNameRegex = RegExp(r"^[\w-]{1,32}$");
Expand All @@ -25,10 +27,12 @@ Iterable<Iterable<T>> partition<T>(Iterable<T> list, bool Function(T) predicate)
}

/// Determine what handler should be executed based on [interaction]
String determineInteractionCommandHandler(ISlashCommandInteraction interaction) {
String determineInteractionCommandHandler(ISlashCommandInteraction interaction, IInteractions interactions) {
String commandHash = interaction.name;
if (interaction.guild != null) {
commandHash = '${interaction.guild!.id}/$commandHash';

ISlashCommand triggered = interactions.commands.firstWhere((command) => command.id == interaction.commandId);
if (triggered.guild != null) {
commandHash = '${triggered.guild!.id}/$commandHash';
}

try {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nyxx_interactions
version: 4.3.0
version: 4.3.1
description: Nyxx Interactions Module. Discord library for Dart. Simple, robust framework for creating discord bots for Dart language.
homepage: https://github.com/nyxx-discord/nyxx_interactions
repository: https://github.com/nyxx-discord/nyxx_interactions
Expand Down

0 comments on commit 4f3e873

Please sign in to comment.