Skip to content

Commit

Permalink
Merge pull request #119 from mineral-dart/feat/before-release
Browse files Browse the repository at this point in the history
Before release
  • Loading branch information
PandaGuerrier authored Jun 20, 2023
2 parents 62c278c + f9d0b71 commit 50e6308
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 43 deletions.
12 changes: 7 additions & 5 deletions lib/src/api/interactions/menus/channel_menu_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:mineral/framework.dart';
import 'package:mineral/src/api/interactions/menus/select_menu_interaction.dart';
import 'package:mineral_ioc/ioc.dart';

import '../../messages/partial_message.dart';

class ChannelMenuInteraction extends SelectMenuInteraction {
final MenuBucket _menu;

Expand All @@ -15,15 +17,15 @@ class ChannelMenuInteraction extends SelectMenuInteraction {
super.token,
super.user,
super.guild,
super.messageId,
super.message,
super.customId,
super.channelId,
super.channel,
this._menu,
);

MenuBucket get menu => _menu;

factory ChannelMenuInteraction.from(dynamic payload) => ChannelMenuInteraction(
factory ChannelMenuInteraction.from(dynamic payload, PartialChannel channel) => ChannelMenuInteraction(
payload['id'],
null,
payload['application_id'],
Expand All @@ -32,9 +34,9 @@ class ChannelMenuInteraction extends SelectMenuInteraction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
MenuBucket(payload['guild_id'], List<Snowflake>.from(payload['data']['values'])),
);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/src/api/interactions/menus/dynamic_menu_interaction.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:mineral/core/api.dart';
import 'package:mineral/src/api/interactions/menus/select_menu_interaction.dart';
import 'package:mineral/src/api/messages/partial_message.dart';

class DynamicMenuInteraction extends SelectMenuInteraction {
final MenuBucket _menu;
Expand All @@ -14,13 +16,13 @@ class DynamicMenuInteraction extends SelectMenuInteraction {
super.guild,
super.messageId,
super.customId,
super.channelId,
super.channel,
this._menu,
);

MenuBucket get menu => _menu;

factory DynamicMenuInteraction.from(dynamic payload) => DynamicMenuInteraction(
factory DynamicMenuInteraction.from(dynamic payload, PartialChannel channel) => DynamicMenuInteraction(
payload['id'],
null,
payload['application_id'],
Expand All @@ -29,9 +31,9 @@ class DynamicMenuInteraction extends SelectMenuInteraction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
MenuBucket(payload['data']['values']),
);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/src/api/interactions/menus/mentionable_menu_interaction.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:mineral/src/api/interactions/menus/select_menu_interaction.dart';

import '../../../../core/api.dart';
import '../../messages/partial_message.dart';

class MentionableMenuInteraction extends SelectMenuInteraction {
final MenuBucket _menu;

Expand All @@ -12,15 +15,15 @@ class MentionableMenuInteraction extends SelectMenuInteraction {
super.token,
super.user,
super.guild,
super.messageId,
super.message,
super.customId,
super.channelId,
super.channel,
this._menu,
);

MenuBucket get menu => _menu;

factory MentionableMenuInteraction.from(dynamic payload) => MentionableMenuInteraction(
factory MentionableMenuInteraction.from(dynamic payload, PartialChannel channel) => MentionableMenuInteraction(
payload['id'],
null,
payload['application_id'],
Expand All @@ -29,9 +32,9 @@ class MentionableMenuInteraction extends SelectMenuInteraction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
MenuBucket(payload['data']['values']),
);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/src/api/interactions/menus/role_menu_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:mineral/framework.dart';
import 'package:mineral/src/api/interactions/menus/select_menu_interaction.dart';
import 'package:mineral_ioc/ioc.dart';

import '../../messages/partial_message.dart';

class RoleMenuInteraction extends SelectMenuInteraction {
final MenuBucket _menu;

Expand All @@ -15,15 +17,15 @@ class RoleMenuInteraction extends SelectMenuInteraction {
super.token,
super.user,
super.guild,
super.messageId,
super.message,
super.customId,
super.channelId,
super.channel,
this._menu,
);

MenuBucket get menu => _menu;

factory RoleMenuInteraction.from(dynamic payload) => RoleMenuInteraction(
factory RoleMenuInteraction.from(dynamic payload, PartialChannel channel) => RoleMenuInteraction(
payload['id'],
null,
payload['application_id'],
Expand All @@ -32,9 +34,9 @@ class RoleMenuInteraction extends SelectMenuInteraction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
MenuBucket(payload['guild_id'], List<String>.from(payload['data']['values'])),
);
}
Expand Down
22 changes: 9 additions & 13 deletions lib/src/api/interactions/menus/select_menu_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:mineral/src/api/messages/partial_message.dart';
import 'package:mineral_ioc/ioc.dart';

class SelectMenuInteraction extends Interaction {
Snowflake? _messageId;
PartialMessage? _message;
Snowflake _customId;
Snowflake _channelId;
PartialChannel _channel;

SelectMenuInteraction(
super._id,
Expand All @@ -19,22 +19,18 @@ class SelectMenuInteraction extends Interaction {
super._token,
super._user,
super._guild,
this._messageId,
this._message,
this._customId,
this._channelId,
this._channel,
);

PartialMessage get message => guild != null
? guild!.channels.cache.getOrFail(_channelId).cast<dynamic>().messages.cache[_messageId]
: ioc.use<MineralClient>().dmChannels.cache.getOrFail(_channelId).messages.cache.getOrFail(_messageId);
PartialMessage? get message => _message;

Snowflake get customId => _customId;

PartialChannel get channel => guild != null
? guild!.channels.cache.getOrFail(_channelId)
: ioc.use<MineralClient>().dmChannels.cache.getOrFail(_channelId);
PartialChannel get channel => _channel;

factory SelectMenuInteraction.from({ required dynamic payload }) {
factory SelectMenuInteraction.from({ required dynamic payload, required PartialChannel channel }) {
return SelectMenuInteraction(
payload['id'],
null,
Expand All @@ -44,9 +40,9 @@ class SelectMenuInteraction extends Interaction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
);
}
}
12 changes: 7 additions & 5 deletions lib/src/api/interactions/menus/user_menu_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:mineral/framework.dart';
import 'package:mineral/src/api/interactions/menus/select_menu_interaction.dart';
import 'package:mineral_ioc/ioc.dart';

import '../../messages/partial_message.dart';

class UserMenuInteraction extends SelectMenuInteraction {
final MenuBucket _menu;

Expand All @@ -15,15 +17,15 @@ class UserMenuInteraction extends SelectMenuInteraction {
super.token,
super.user,
super.guild,
super.messageId,
super.message,
super.customId,
super.channelId,
super.channel,
this._menu,
);

MenuBucket get menu => _menu;

factory UserMenuInteraction.from(dynamic payload) => UserMenuInteraction(
factory UserMenuInteraction.from(dynamic payload, PartialChannel channel) => UserMenuInteraction(
payload['id'],
null,
payload['application_id'],
Expand All @@ -32,9 +34,9 @@ class UserMenuInteraction extends SelectMenuInteraction {
payload['token'],
payload['member']?['user']?['id'],
payload['guild_id'],
payload['message']?['id'],
(payload['guild_id'] != null ? Message.from(channel: channel as GuildChannel, payload: payload['message']) : DmMessage.from(channel: channel as DmChannel, payload: payload['message'])) as PartialMessage<PartialChannel>?,
payload['data']['custom_id'],
payload['channel_id'],
channel,
MenuBucket(payload['guild_id'], List<String>.from(payload['data']['values'])),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/entities/commands/command_option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CommandOption {
);
}

factory CommandOption.number(Display label, Display description, { bool? required = false }) {
factory CommandOption.double(Display label, Display description, { bool? required = false }) {
return CommandOption(
label: label,
description: description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,39 @@ class InteractionCreatePacket with Container implements WebsocketPacket {
}

if (payload['data']['component_type'] == ComponentType.dynamicSelect.value) {
final event = DynamicMenuCreateEvent(DynamicMenuInteraction.from(payload));
final event = DynamicMenuCreateEvent(DynamicMenuInteraction.from(payload, channel));

eventService.controller.add(event);
container.use<CollectorService>().emit(DynamicMenuCreateEvent, event);
container.use<ComponentService>().emit(event.interaction.customId, event);
}

if (payload['data']['component_type'] == ComponentType.userSelect.value) {
final event = UserMenuCreateEvent(UserMenuInteraction.from(payload));
final event = UserMenuCreateEvent(UserMenuInteraction.from(payload, channel));

eventService.controller.add(event);
container.use<CollectorService>().emit(UserMenuInteraction, event);
container.use<ComponentService>().emit(event.interaction.customId, event);
}

if (payload['data']['component_type'] == ComponentType.channelSelect.value) {
final event = ChannelMenuCreateEvent(ChannelMenuInteraction.from(payload));
final event = ChannelMenuCreateEvent(ChannelMenuInteraction.from(payload, channel));

eventService.controller.add(event);
container.use<CollectorService>().emit(ChannelMenuInteraction, event);
container.use<ComponentService>().emit(event.interaction.customId, event);
}

if (payload['data']['component_type'] == ComponentType.roleSelect.value) {
final event = RoleMenuCreateEvent(RoleMenuInteraction.from(payload));
final event = RoleMenuCreateEvent(RoleMenuInteraction.from(payload, channel));

eventService.controller.add(event);
container.use<CollectorService>().emit(RoleMenuCreateEvent, event);
container.use<ComponentService>().emit(event.interaction.customId, event);
}

if (payload['data']['component_type'] == ComponentType.mentionableSelect.value) {
final event = MentionableMenuCreateEvent(MentionableMenuInteraction.from(payload));
final event = MentionableMenuCreateEvent(MentionableMenuInteraction.from(payload, channel));

eventService.controller.add(event);
container.use<CollectorService>().emit(MentionableMenuCreateEvent, event);
Expand Down

0 comments on commit 50e6308

Please sign in to comment.