Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/implement components #189

Merged
merged 19 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
102dedc
refactor(interactions): move interaction to internals
LeadcodeDev Aug 5, 2024
af518fc
feat(interaction): implement server button interaction
LeadcodeDev Aug 6, 2024
bdb9551
feat(interaction): implement private button interaction
LeadcodeDev Aug 6, 2024
4201170
feat(interaction): add missing customId
LeadcodeDev Aug 6, 2024
76f12ef
feat(interaction): implement dialog interactions
LeadcodeDev Aug 6, 2024
520e64f
feat(interaction): implement dialog handler named parameters
LeadcodeDev Aug 8, 2024
6acc96e
feat(interaction): add event listening constraint
LeadcodeDev Aug 11, 2024
0667296
feat(interaction): add interaction dialog listening constraint
LeadcodeDev Aug 11, 2024
754eeef
feat(interaction): implement channel select component
LeadcodeDev Aug 11, 2024
1f4c41a
feat(interaction): implement server channel select handler
LeadcodeDev Aug 11, 2024
dda9434
feat(interaction): enhance packets interaction structures
LeadcodeDev Aug 11, 2024
7f737e6
feat(interaction): implement server role select handler
LeadcodeDev Aug 11, 2024
96ab20e
feat(interaction): implement server member/user select handler
LeadcodeDev Aug 11, 2024
b1bb637
feat(interaction): implement text select handler
LeadcodeDev Aug 11, 2024
0d5a6be
feat(component): remove customId and define dialog customId as null
LeadcodeDev Aug 12, 2024
5829365
feat(component): add customId in button events
LeadcodeDev Aug 13, 2024
0bbcac5
feat(component): write factories
LeadcodeDev Aug 13, 2024
ec14f5a
feat(component): write factories
LeadcodeDev Aug 13, 2024
759e810
feat(component): add customId with default value as null
LeadcodeDev Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/api/common/components/component_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ enum ComponentType implements EnhancedEnum<int> {
mentionableSelectMenu(7),
channelSelectMenu(8);

static const selectMenus = [
textSelectMenu,
userSelectMenu,
roleSelectMenu,
mentionableSelectMenu,
channelSelectMenu,
];

@override
final int value;

Expand Down
4 changes: 2 additions & 2 deletions lib/api/private/private_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ final class PrivateMessage implements Message<PrivateChannel> {

final String userId;

final User user;
final User author;

PrivateMessage(this._properties, {
required this.userId,
required this.user,
required this.author,
});
}
2 changes: 1 addition & 1 deletion lib/domains/commands/command_interaction_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:mineral/api/common/commands/command_type.dart';
import 'package:mineral/api/common/types/interaction_type.dart';
import 'package:mineral/domains/commands/command_interaction_manager.dart';
import 'package:mineral/domains/commands/contexts/guild_command_context.dart';
import 'package:mineral/domains/types/interaction_dispatcher_contract.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_dispatcher_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';

final class CommandInteractionDispatcher implements InteractionDispatcherContract {
Expand Down
2 changes: 1 addition & 1 deletion lib/domains/commands/command_interaction_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:mineral/api/common/commands/command_context_type.dart';
import 'package:mineral/api/server/server.dart';
import 'package:mineral/domains/commands/command_builder.dart';
import 'package:mineral/domains/commands/command_interaction_dispatcher.dart';
import 'package:mineral/domains/types/interaction_dispatcher_contract.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_dispatcher_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/io/exceptions/missing_property_exception.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/domains/commands/contexts/guild_command_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/private/user.dart';
import 'package:mineral/api/server/server.dart';
import 'package:mineral/domains/commands/command_context.dart';
import 'package:mineral/domains/interactions/interaction.dart';
import 'package:mineral/domains/types/interaction_contract.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';

final class ServerCommandContext implements CommandContext {
@override
Expand Down
9 changes: 9 additions & 0 deletions lib/domains/components/buttons/button_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:mineral/api/common/snowflake.dart';

abstract interface class ButtonContext {
Snowflake get id;
Snowflake get applicationId;
String get token;
int get version;
String get customId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/private/private_message.dart';
import 'package:mineral/api/private/user.dart';
import 'package:mineral/domains/components/buttons/button_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';

final class PrivateButtonContext implements ButtonContext {
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final User user;

final PrivateMessage message;

late final InteractionContract interaction;

PrivateButtonContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.message,
required this.user,
}) {
interaction = Interaction(token, id);
}
}
41 changes: 41 additions & 0 deletions lib/domains/components/buttons/contexts/server_button_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/server/member.dart';
import 'package:mineral/api/server/server_message.dart';
import 'package:mineral/domains/components/buttons/button_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';

final class ServerButtonContext implements ButtonContext {
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final Member member;

final ServerMessage message;

late final InteractionContract interaction;

ServerButtonContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.message,
required this.member,
}) {
interaction = Interaction(token, id);
}
}
49 changes: 49 additions & 0 deletions lib/domains/components/dialog/contexts/private_dialog_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/private/user.dart';
import 'package:mineral/domains/components/dialog/dialog_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';

final class PrivateDialogContext implements DialogContext {
PandaGuerrier marked this conversation as resolved.
Show resolved Hide resolved
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final User user;

late final InteractionContract interaction;

PrivateDialogContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.user,
}) {
interaction = Interaction(token, id);
}

static Future<PrivateDialogContext> fromMap(MarshallerContract marshaller, Map<String, dynamic> payload) async{
return PrivateDialogContext(
customId: payload['data']['custom_id'],
id: Snowflake(payload['id']),
applicationId: Snowflake(payload['application_id']),
token: payload['token'],
version: payload['version'],
user: await marshaller.serializers.user.serializeRemote(payload['user']),
);
}
}
52 changes: 52 additions & 0 deletions lib/domains/components/dialog/contexts/server_dialog_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/server/member.dart';
import 'package:mineral/domains/components/dialog/dialog_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';

final class ServerDialogContext implements DialogContext {
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final Member member;

late final InteractionContract interaction;

ServerDialogContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.member,
}) {
interaction = Interaction(token, id);
}

static Future<ServerDialogContext> fromMap(MarshallerContract marshaller, Map<String, dynamic> payload) async{
return ServerDialogContext(
customId: payload['data']['custom_id'],
id: Snowflake(payload['id']),
applicationId: Snowflake(payload['application_id']),
token: payload['token'],
version: payload['version'],
member: await marshaller.dataStore.member.getMember(
guildId: Snowflake(payload['guild_id']),
memberId: Snowflake(payload['member']['user']['id']),
),
);
}
}
9 changes: 9 additions & 0 deletions lib/domains/components/dialog/dialog_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:mineral/api/common/snowflake.dart';

abstract interface class DialogContext {
Snowflake get id;
Snowflake get applicationId;
String get token;
int get version;
String get customId;
}
9 changes: 9 additions & 0 deletions lib/domains/components/selects/button_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:mineral/api/common/snowflake.dart';

abstract interface class SelectContext {
Snowflake get id;
Snowflake get applicationId;
String get token;
int get version;
String get customId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/private/private_message.dart';
import 'package:mineral/api/private/user.dart';
import 'package:mineral/domains/components/selects/button_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';

final class PrivateSelectContext implements SelectContext {
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final User user;

final PrivateMessage message;

late final InteractionContract interaction;

PrivateSelectContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.message,
required this.user,
}) {
interaction = Interaction(token, id);
}

static Future<PrivateSelectContext> fromMap(MarshallerContract marshaller, Map<String, dynamic> payload) async{
return PrivateSelectContext(
customId: payload['data']['custom_id'],
id: Snowflake(payload['id']),
applicationId: Snowflake(payload['application_id']),
token: payload['token'],
version: payload['version'],
message: await marshaller.dataStore.message.getPrivateMessage(
messageId: Snowflake(payload['message']['id']),
channelId: Snowflake(payload['channel_id']),
),
user: await marshaller.serializers.user.serializeRemote(payload['user']),
);
}
}
61 changes: 61 additions & 0 deletions lib/domains/components/selects/contexts/server_select_context.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/server/member.dart';
import 'package:mineral/api/server/server_message.dart';
import 'package:mineral/domains/components/buttons/button_context.dart';
import 'package:mineral/domains/components/selects/button_context.dart';
import 'package:mineral/infrastructure/internals/interactions/interaction.dart';
import 'package:mineral/infrastructure/internals/interactions/types/interaction_contract.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';

final class ServerSelectContext implements SelectContext {
@override
final Snowflake id;

@override
final Snowflake applicationId;

@override
final String token;

@override
final int version;

@override
final String customId;

final Member member;

final ServerMessage message;

late final InteractionContract interaction;

ServerSelectContext({
required this.id,
required this.applicationId,
required this.token,
required this.version,
required this.customId,
required this.message,
required this.member,
}) {
interaction = Interaction(token, id);
}

static Future<ServerSelectContext> fromMap(MarshallerContract marshaller, Map<String, dynamic> payload) async{
return ServerSelectContext(
customId: payload['data']['custom_id'],
id: Snowflake(payload['id']),
applicationId: Snowflake(payload['application_id']),
token: payload['token'],
version: payload['version'],
message: await marshaller.dataStore.message.getServerMessage(
messageId: Snowflake(payload['message']['id']),
channelId: Snowflake(payload['channel_id']),
),
member: await marshaller.dataStore.member.getMember(
guildId: Snowflake(payload['guild_id']),
memberId: Snowflake(payload['member']['user']['id']),
),
);
}
}
Loading