From d6ccb4dc01a4507c22ab096d334dc55125d01942 Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Thu, 11 May 2023 19:58:47 +0200 Subject: [PATCH 1/2] Added activities in GUILD_CREATE packet. --- .../packets/guild_create_packet.dart | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/src/internal/websockets/packets/guild_create_packet.dart b/lib/src/internal/websockets/packets/guild_create_packet.dart index 3d882f31e..213f7716c 100644 --- a/lib/src/internal/websockets/packets/guild_create_packet.dart +++ b/lib/src/internal/websockets/packets/guild_create_packet.dart @@ -6,6 +6,8 @@ import 'package:mineral/core/api.dart'; import 'package:mineral/core/events.dart'; import 'package:mineral/framework.dart'; import 'package:mineral/src/api/channels/partial_channel.dart'; +import 'package:mineral/src/api/guilds/activities/guild_member_activity.dart'; +import 'package:mineral/src/api/guilds/guild_member_presence.dart'; import 'package:mineral/src/api/managers/channel_manager.dart'; import 'package:mineral/src/api/managers/emoji_manager.dart'; import 'package:mineral/src/api/managers/guild_role_manager.dart'; @@ -21,6 +23,8 @@ import 'package:mineral/src/internal/services/event_service.dart'; import 'package:mineral/src/internal/websockets/websocket_packet.dart'; import 'package:mineral/src/internal/websockets/websocket_response.dart'; +import '../../../api/guilds/client_status_bucket.dart'; + class GuildCreatePacket with Container implements WebsocketPacket { @override Future handle(WebsocketResponse websocketResponse) async { @@ -49,9 +53,9 @@ class GuildCreatePacket with Container implements WebsocketPacket { EmojiManager emojiManager = EmojiManager(); for(dynamic payload in websocketResponse.payload['emojis']) { Emoji emoji = Emoji.from( - memberManager: memberManager, - emojiManager: emojiManager, - payload: payload + memberManager: memberManager, + emojiManager: emojiManager, + payload: payload ); emojiManager.cache.putIfAbsent(emoji.id, () => emoji); @@ -60,9 +64,9 @@ class GuildCreatePacket with Container implements WebsocketPacket { GuildScheduledEventService guildScheduledManager = GuildScheduledEventService(); for(dynamic payload in websocketResponse.payload['guild_scheduled_events']) { GuildScheduledEvent event = GuildScheduledEvent.from( - channelManager: channelManager, - memberManager: memberManager, - payload: payload + channelManager: channelManager, + memberManager: memberManager, + payload: payload ); guildScheduledManager.cache.putIfAbsent(event.id, () => event); @@ -93,13 +97,13 @@ class GuildCreatePacket with Container implements WebsocketPacket { for (dynamic member in websocketResponse.payload['members']) { User user = User.from(member['user']); GuildMember guildMember = GuildMember.from( - roles: roleManager, - user: user, - member: member, - guild: guild, - voice: voices.containsKey(user.id) - ? voices.get(user.id)! - : VoiceManager.empty(member['deaf'], member['mute'], user.id, websocketResponse.payload['guild_id']) + roles: roleManager, + user: user, + member: member, + guild: guild, + voice: voices.containsKey(user.id) + ? voices.get(user.id)! + : VoiceManager.empty(member['deaf'], member['mute'], user.id, websocketResponse.payload['guild_id']) ); memberManager.cache.putIfAbsent(guildMember.user.id, () => guildMember); @@ -115,6 +119,20 @@ class GuildCreatePacket with Container implements WebsocketPacket { } } + for (dynamic payload in websocketResponse.payload['presences']) { + payload['guild_id'] = websocketResponse.payload['id']; + GuildMember member = await guild.members.resolve(payload['user']['id']); + ClientStatusBucket clientStatusBucket = ClientStatusBucket(payload['client_status']['desktop'], payload['client_status']['mobile'], payload['client_status']['web']); + + List activities = []; + for(dynamic activity in payload['activities']) { + activities.add(GuildMemberActivity(ActivityType.values.firstWhere((element) => element.value == activity['type']), activity['name'])); + } + + GuildMemberPresence guildMemberPresence = GuildMemberPresence(payload['guild_id'], payload['status'], null, clientStatusBucket, activities); + member.presence = guildMemberPresence; + } + guild.afkChannel = guild.channels.cache.get(guild.afkChannelId); guild.systemChannel = guild.channels.cache.get(guild.systemChannelId); guild.rulesChannel = guild.channels.cache.get(guild.rulesChannelId); @@ -143,8 +161,8 @@ class GuildCreatePacket with Container implements WebsocketPacket { Future?> getAutoModerationRules (Guild guild) async { Response response = await container.use() - .get(url: "/guilds/${guild.id}/auto-moderation/rules") - .build(); + .get(url: "/guilds/${guild.id}/auto-moderation/rules") + .build(); if (response.statusCode == 200) { dynamic payload = jsonDecode(response.body); @@ -160,4 +178,4 @@ class GuildCreatePacket with Container implements WebsocketPacket { return null; } -} +} \ No newline at end of file From 42b3ea11d8294b7901c15b15dc19be02fb9353d1 Mon Sep 17 00:00:00 2001 From: PandaGuerrier <76222146+PandaGuerrier@users.noreply.github.com> Date: Sat, 13 May 2023 13:51:00 +0200 Subject: [PATCH 2/2] Added messages's threads --- lib/src/api/messages/message.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/src/api/messages/message.dart b/lib/src/api/messages/message.dart index fba9cc1f5..9622a3281 100644 --- a/lib/src/api/messages/message.dart +++ b/lib/src/api/messages/message.dart @@ -77,6 +77,17 @@ class Message extends PartialMessage { .build(); } + Future createThread ({ required String label, int archiveDuration = 60}) async { + Response respose = await ioc.use().post(url: '/channels/${super.channel.id}/messages/${super.id}/threads') + .payload({ + 'name': label, + 'auto_archive_duration': archiveDuration, + }) + .build(); + + return ThreadChannel.fromPayload(jsonDecode(respose.body)); + } + Future pin (Snowflake webhookId) async { if (isPinned) { ioc.use().warn('Message $id is already pinned');