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 #77 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Release 4.6.0
  • Loading branch information
l7ssha authored Mar 5, 2023
2 parents 1c237b1 + 63bb1ea commit 9ff551c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 10 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
## 4.6.0
__06.03.2023__

- feature: Add Indonesian locale (#75)
- feature: Add an exception for unknown commands (#76)
- update to nyxx 5.0.0

## 4.6.0-dev.0
__26.01.2023__

- feature: Add Indonesian locale (#75)

## 4.5.0
__12.12.022__
__12.12.2022__

- feature: Handle HTTP error response in acknowledge()
- feature: Update nyxx_interactions to work with the new logging system in nyxx (#69)
Expand All @@ -8,7 +20,7 @@ __12.12.022__
- bug: Fix nsfw field not present in payload (#73)

## 4.4.0
__14.11.022__
__14.11.2022__

- feature: Add support for new select menus components (#62)

Expand Down
1 change: 1 addition & 0 deletions lib/nyxx_interactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export 'src/events/interaction_event.dart'
IMentionableMultiSelectInteractionEvent,
IChannelMultiSelectInteractionEvent;
export 'src/exceptions/already_responded.dart' show AlreadyRespondedError;
export 'src/exceptions/command_not_found.dart' show CommandNotFoundException;
export 'src/exceptions/interaction_expired.dart' show InteractionExpiredError;
export 'src/exceptions/response_required.dart' show ResponseRequiredError;
export 'src/internal/sync/commands_sync.dart' show ICommandsSync;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/interaction_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ abstract class InteractionEventWithAcknowledge<T extends IInteraction> extends I
} on IHttpResponseError catch (response) {
// 40060 - Interaction has already been acknowledged
// Catch in case of a desync between server and _hasAcked
if (response.code == 40060) {
if (response.errorCode == 40060) {
throw AlreadyRespondedError();
}

Expand Down
16 changes: 16 additions & 0 deletions lib/src/exceptions/command_not_found.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:nyxx_interactions/nyxx_interactions.dart';

/// An error thrown when an interaction is received but nyxx_interactions cannot find a matching command model.
///
/// Normally this indicates that a desync between nyxx_interactions and Discord has occurred. Make sure you call [IInteractions.sync] and that there are no
/// guild commands left undeleted.
class CommandNotFoundException implements Exception {
/// The interaction containing the unknown command.
final ISlashCommandInteraction interaction;

/// Create a new [CommandNotFoundException].
CommandNotFoundException(this.interaction);

@override
String toString() => 'Command not found: ${interaction.commandId}';
}
2 changes: 1 addition & 1 deletion lib/src/internal/interaction_endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class InteractionsEndpoints implements IInteractionsEndpoints {
} on IHttpResponseError catch (response) {
// 10066 = Unknown application command permissions
// Means there are no overrides for this command... why is this an error, Discord?
if (response.code == 10066) {
if (response.errorCode == 10066) {
_logger.finest('Got error code 10066 on permissions for command $commandId in guild $guildId, returning empty permission overrides.');
return SlashCommandPermissionOverrides.empty(commandId, _client);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/src/internal/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:nyxx/nyxx.dart';

import 'package:nyxx_interactions/src/builders/slash_command_builder.dart';
import 'package:nyxx_interactions/src/exceptions/command_not_found.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';
Expand Down Expand Up @@ -30,7 +31,11 @@ Iterable<Iterable<T>> partition<T>(Iterable<T> list, bool Function(T) predicate)
String determineInteractionCommandHandler(ISlashCommandInteraction interaction, IInteractions interactions) {
String commandHash = interaction.name;

ISlashCommand triggered = interactions.commands.firstWhere((command) => command.id == interaction.commandId);
ISlashCommand triggered = interactions.commands.firstWhere(
(command) => command.id == interaction.commandId,
orElse: () => throw CommandNotFoundException(interaction),
);

if (triggered.guild != null) {
commandHash = '${triggered.guild!.id}/$commandHash';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ModalInteraction extends Interaction implements IModalInteraction {
if (raw['data']["components"] != null) {
components = [
for (final rawRow in raw['data']["components"])
[for (final componentRaw in rawRow["components"]) MessageComponent.deserialize(componentRaw as RawApiMap)]
[for (final componentRaw in rawRow["components"]) MessageComponent.deserialize(componentRaw as RawApiMap, client)]
];
} else {
components = [];
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/locale.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum Locale {
indonesian('id'),
danish('da'),
german('de'),
englishUk('en-GB'),
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: nyxx_interactions
version: 4.5.0
version: 4.6.0
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 All @@ -12,11 +12,11 @@ environment:
dependencies:
crypto: ^3.0.1
logging: ^1.0.1
nyxx: ^4.2.0
nyxx: ^5.0.0

dev_dependencies:
test: ^1.19.0
mockito: ^5.0.16
build_runner: ^2.1.4
lints: ^1.0.1
lints: ^2.0.1
coverage: ^1.0.3
4 changes: 3 additions & 1 deletion test/unit/component_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:nyxx/nyxx.dart';
import 'package:nyxx_interactions/nyxx_interactions.dart';
import 'package:test/test.dart';

import '../mocks/nyxx_rest.mocks.dart';

main() {
test("components", () {
final customButton = ButtonBuilder("label", "customId", ButtonStyle.secondary);
Expand Down Expand Up @@ -78,7 +80,7 @@ main() {
});

test("MultiselectOptionBuilder emoji unicode", () {
final builder = MultiselectOptionBuilder("test", 'test')..emoji = IBaseGuildEmoji.fromId(Snowflake.zero());
final builder = MultiselectOptionBuilder("test", 'test')..emoji = IBaseGuildEmoji.fromId(Snowflake.zero(), NyxxRestMock());

final expectedResult = {
'label': 'test',
Expand Down

0 comments on commit 9ff551c

Please sign in to comment.