diff --git a/lib/src/api/interactions/button_interaction.dart b/lib/src/api/interactions/button_interaction.dart index b2299237..cf9b6811 100644 --- a/lib/src/api/interactions/button_interaction.dart +++ b/lib/src/api/interactions/button_interaction.dart @@ -5,9 +5,11 @@ import 'package:mineral/framework.dart'; import 'package:mineral/src/api/messages/partial_message.dart'; import 'package:mineral_ioc/ioc.dart'; +import 'package:mineral/core.dart'; + class ButtonInteraction extends Interaction { Snowflake _customId; - Snowflake? _messageId; + PartialMessage? _message; Snowflake _channelId; ButtonInteraction( @@ -19,7 +21,7 @@ class ButtonInteraction extends Interaction { super.token, super._userId, super._guildId, - this._messageId, + this._message, this._customId, this._channelId, ); @@ -27,20 +29,24 @@ class ButtonInteraction extends Interaction { /// Get custom id of this Snowflake get customId => _customId; - /// Get message id of this - Snowflake? get mid => _messageId; - /// Get message [PartialMessage] of this - PartialMessage? get message => guild != null - ? (guild?.channels.cache.get(_channelId) as dynamic)?.messages.cache[_messageId] - : ioc.use().dmChannels.cache.get(_channelId)?.messages.cache.getOrFail(_messageId); + PartialMessage? get message => _message; /// Get channel [PartialChannel] of this PartialChannel get channel => guild != null ? guild!.channels.cache.getOrFail(_channelId) : throw UnsupportedError('DM channel is not supported'); - factory ButtonInteraction.fromPayload(dynamic payload) { + @override + Future delete () async { + String mid = message?.id ?? "@original"; + + await ioc.use() + .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") + .build(); + } + + factory ButtonInteraction.fromPayload(PartialChannel channel, dynamic payload) { return ButtonInteraction( payload['id'], null, @@ -50,7 +56,7 @@ class ButtonInteraction extends Interaction { payload['token'], payload['member']?['user']?['id'] ?? payload['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?, payload['data']['custom_id'], payload['channel_id'], ); diff --git a/lib/src/api/interactions/menus/select_menu_interaction.dart b/lib/src/api/interactions/menus/select_menu_interaction.dart index bb85dacc..700cc7dc 100644 --- a/lib/src/api/interactions/menus/select_menu_interaction.dart +++ b/lib/src/api/interactions/menus/select_menu_interaction.dart @@ -1,10 +1,11 @@ import 'dart:core'; import 'package:mineral/core/api.dart'; -import 'package:mineral/framework.dart'; import 'package:mineral/src/api/messages/partial_message.dart'; import 'package:mineral_ioc/ioc.dart'; +import '../../../../core.dart'; + class SelectMenuInteraction extends Interaction { PartialMessage? _message; Snowflake _customId; @@ -30,6 +31,15 @@ class SelectMenuInteraction extends Interaction { PartialChannel get channel => _channel; + @override + Future delete () async { + String mid = message?.id ?? "@original"; + + await ioc.use() + .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") + .build(); + } + factory SelectMenuInteraction.from({ required dynamic payload, required PartialChannel channel }) { return SelectMenuInteraction( payload['id'], diff --git a/lib/src/internal/websockets/packets/interaction_create_packet.dart b/lib/src/internal/websockets/packets/interaction_create_packet.dart index d0d39ecc..79137d9f 100644 --- a/lib/src/internal/websockets/packets/interaction_create_packet.dart +++ b/lib/src/internal/websockets/packets/interaction_create_packet.dart @@ -107,7 +107,7 @@ class InteractionCreatePacket with Container implements WebsocketPacket { } catch(_) { } } - final buttonInteraction = ButtonInteraction.fromPayload(payload); + final buttonInteraction = ButtonInteraction.fromPayload(channel!, payload); final event = ButtonCreateEvent(buttonInteraction); eventService.controller.add(event);