From 1749908fbff99372627198a7816e826561ef645d Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:23:27 +0200 Subject: [PATCH 1/5] fix: ask for partial message instead of message id and fix delete method --- .../api/interactions/button_interaction.dart | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/src/api/interactions/button_interaction.dart b/lib/src/api/interactions/button_interaction.dart index b2299237..66d9ff13 100644 --- a/lib/src/api/interactions/button_interaction.dart +++ b/lib/src/api/interactions/button_interaction.dart @@ -1,13 +1,16 @@ import 'dart:core'; +import 'package:http/http.dart'; 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 ButtonInteraction extends Interaction { Snowflake _customId; - Snowflake? _messageId; + PartialMessage? _message; Snowflake _channelId; ButtonInteraction( @@ -19,7 +22,7 @@ class ButtonInteraction extends Interaction { super.token, super._userId, super._guildId, - this._messageId, + this._message, this._customId, this._channelId, ); @@ -27,20 +30,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(GuildChannel channel, dynamic payload) { return ButtonInteraction( payload['id'], null, @@ -50,7 +57,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'], ); From 2c727ba84ae38719b803926779d48f5cd1dfec0c Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:23:49 +0200 Subject: [PATCH 2/5] fix: delete method --- .../interactions/menus/select_menu_interaction.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/src/api/interactions/menus/select_menu_interaction.dart b/lib/src/api/interactions/menus/select_menu_interaction.dart index bb85dacc..4cd3278e 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'], From d4e38efdd2741e2704acbbdb007a069f6866bccc Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Tue, 27 Jun 2023 17:24:28 +0200 Subject: [PATCH 3/5] fix: ask channel as GuildChannel --- .../internal/websockets/packets/interaction_create_packet.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/internal/websockets/packets/interaction_create_packet.dart b/lib/src/internal/websockets/packets/interaction_create_packet.dart index d0d39ecc..8f774141 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 as GuildChannel, payload); final event = ButtonCreateEvent(buttonInteraction); eventService.controller.add(event); From e91ef7bed5d9bac2ec39c3f642f477bfbf9a7fcc Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:42:04 +0200 Subject: [PATCH 4/5] fix: request PartialChannel instead of GuildChannel --- lib/src/api/interactions/button_interaction.dart | 9 ++++----- .../websockets/packets/interaction_create_packet.dart | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/src/api/interactions/button_interaction.dart b/lib/src/api/interactions/button_interaction.dart index 66d9ff13..cf9b6811 100644 --- a/lib/src/api/interactions/button_interaction.dart +++ b/lib/src/api/interactions/button_interaction.dart @@ -1,12 +1,11 @@ import 'dart:core'; -import 'package:http/http.dart'; 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'; +import 'package:mineral/core.dart'; class ButtonInteraction extends Interaction { Snowflake _customId; @@ -43,11 +42,11 @@ class ButtonInteraction extends Interaction { String mid = message?.id ?? "@original"; await ioc.use() - .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") - .build(); + .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") + .build(); } - factory ButtonInteraction.fromPayload(GuildChannel channel, dynamic payload) { + factory ButtonInteraction.fromPayload(PartialChannel channel, dynamic payload) { return ButtonInteraction( payload['id'], null, diff --git a/lib/src/internal/websockets/packets/interaction_create_packet.dart b/lib/src/internal/websockets/packets/interaction_create_packet.dart index 8f774141..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(channel as GuildChannel, payload); + final buttonInteraction = ButtonInteraction.fromPayload(channel!, payload); final event = ButtonCreateEvent(buttonInteraction); eventService.controller.add(event); From d2d9b782b0bda293c0edd962a9791373e17c2494 Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:42:35 +0200 Subject: [PATCH 5/5] refactor: improve code style --- lib/src/api/interactions/menus/select_menu_interaction.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/api/interactions/menus/select_menu_interaction.dart b/lib/src/api/interactions/menus/select_menu_interaction.dart index 4cd3278e..700cc7dc 100644 --- a/lib/src/api/interactions/menus/select_menu_interaction.dart +++ b/lib/src/api/interactions/menus/select_menu_interaction.dart @@ -36,8 +36,8 @@ class SelectMenuInteraction extends Interaction { String mid = message?.id ?? "@original"; await ioc.use() - .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") - .build(); + .destroy(url: "/webhooks/$applicationId/$token/messages/$mid") + .build(); } factory SelectMenuInteraction.from({ required dynamic payload, required PartialChannel channel }) {