From bfcf00726a576edda5278205c3dfee699df881d9 Mon Sep 17 00:00:00 2001 From: "AsynchronousMatrix (Jack)" Date: Thu, 16 Jan 2025 22:45:04 +0000 Subject: [PATCH] feature: implement more typecasting to reduce type complexity --- .../classes/src/application/application.luau | 12 +- .../src/channels/behaviour/channel.luau | 8 +- .../classes/src/channels/behaviour/forum.luau | 2 +- .../src/channels/behaviour/groupDM.luau | 9 +- .../classes/src/channels/behaviour/guild.luau | 32 ++-- .../classes/src/channels/behaviour/media.luau | 2 +- .../classes/src/channels/behaviour/text.luau | 18 +- .../src/channels/behaviour/thread.luau | 16 +- packages/classes/src/guild/guild.luau | 164 +++++++++--------- packages/classes/src/guild/member.luau | 78 ++++----- packages/classes/src/guild/role.luau | 6 +- .../src/interaction/types/command.luau | 20 ++- .../src/interaction/types/component.luau | 20 ++- .../classes/src/interaction/types/ping.luau | 2 +- packages/classes/src/message/message.luau | 16 +- packages/websocket/src/shard.luau | 8 +- 16 files changed, 210 insertions(+), 203 deletions(-) diff --git a/packages/classes/src/application/application.luau b/packages/classes/src/application/application.luau index 2ceddeb..48c033d 100644 --- a/packages/classes/src/application/application.luau +++ b/packages/classes/src/application/application.luau @@ -37,7 +37,7 @@ function Application.Prototype.createSlashCommandAsync(self: Application, slashC assert(response:isOk(), response:unwrapErr()) return commandObject.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -50,7 +50,9 @@ function Application.Prototype.deleteSlashCommandAsync(self: Application, slashC local response = rest.commands.deleteGlobalApplicationCommandAsync(request, self.id, slashCommandId):await() assert(response:isOk(), response:unwrapErr()) - end) + + return nil + end) :: future.FutureLike end --[[ @@ -70,7 +72,7 @@ function Application.Prototype.editSlashCommandAsync( assert(response:isOk(), response:unwrapErr()) return commandObject.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -95,7 +97,7 @@ function Application.Prototype.getSlashCommandsAsync(self: Application, withLoca end return commands - end) + end) :: future.FutureLike end --[[ @@ -120,7 +122,7 @@ function Application.Prototype.overwriteSlashCommandsAsync( end return commands - end) + end) :: future.FutureLike end function Application.Prototype.sync(self: Application, applicationData: apiTypes.ApplicationObject) diff --git a/packages/classes/src/channels/behaviour/channel.luau b/packages/classes/src/channels/behaviour/channel.luau index 224b963..026d01c 100644 --- a/packages/classes/src/channels/behaviour/channel.luau +++ b/packages/classes/src/channels/behaviour/channel.luau @@ -31,8 +31,8 @@ function ChannelBehaviour.Prototype.deleteChannelAsync(self: Channel) self:sync(response:unwrapOk()) - return self :: T - end) + return self + end) :: future.FutureLike> end --[[ @@ -50,7 +50,7 @@ function ChannelBehaviour.Prototype.triggerTypingIndicatorAsync(self: Channel assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -67,7 +67,7 @@ function ChannelBehaviour.Prototype.modifyAsync(self: Channel, json: build self:sync(response:unwrapOk()) return self - end) + end) :: future.FutureLike> end function ChannelBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/forum.luau b/packages/classes/src/channels/behaviour/forum.luau index 2a6e24f..b3a0e4e 100644 --- a/packages/classes/src/channels/behaviour/forum.luau +++ b/packages/classes/src/channels/behaviour/forum.luau @@ -36,7 +36,7 @@ function ForumBehaviour.Prototype.createPostAsync(self: Channel, post: bui assert(response:isOk(), response:unwrapErr()) return response:unwrapOk().id - end) + end) :: future.FutureLike end function ForumBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/groupDM.luau b/packages/classes/src/channels/behaviour/groupDM.luau index ae5e93c..7899bff 100644 --- a/packages/classes/src/channels/behaviour/groupDM.luau +++ b/packages/classes/src/channels/behaviour/groupDM.luau @@ -6,7 +6,6 @@ local apiTypes = require("../../../lune_packages/api_types") local future = require("../../../luau_packages/future") local rest = require("../../../lune_packages/rest") local state = require("../../../lune_packages/state") -local builders = require("../../../lune_packages/builders") local user = require("../../user") @@ -37,7 +36,7 @@ function GroupDMBehaviour.Prototype.addRecipient( assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -52,7 +51,7 @@ function GroupDMBehaviour.Prototype.removeRecipient(self: Channel, userId: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -61,7 +60,7 @@ end function GroupDMBehaviour.Prototype.setNameAsync(self: Channel, groupName: string) return self:modifyAsync({ name = groupName, - }) + }) :: future.FutureLike> end --[[ @@ -71,7 +70,7 @@ function GroupDMBehaviour.Prototype.setIconAsync(self: Channel, iconData: return self:modifyAsync({ name = self.name, icon = iconData, - }) + }) :: future.FutureLike> end function GroupDMBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/guild.luau b/packages/classes/src/channels/behaviour/guild.luau index 2f6210e..d5b18a9 100644 --- a/packages/classes/src/channels/behaviour/guild.luau +++ b/packages/classes/src/channels/behaviour/guild.luau @@ -35,7 +35,7 @@ function GuildBehaviour.Prototype.setPositionAsync(self: Channel, position assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -56,7 +56,7 @@ function GuildBehaviour.Prototype.setParentAsync(self: Channel, parentId: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -84,7 +84,7 @@ function GuildBehaviour.Prototype.setPermissionsAsync( assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -104,7 +104,7 @@ function GuildBehaviour.Prototype.deletePermissionAsync( assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -125,7 +125,7 @@ function GuildBehaviour.Prototype.getInvitesAsync(self: Channel) end return invites - end) + end) :: future.FutureLike end --[[ @@ -140,7 +140,7 @@ function GuildBehaviour.Prototype.createInviteAsync(self: Channel, json: b assert(response:isOk(), response:unwrapErr()) return invite.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -181,7 +181,11 @@ function GuildBehaviour.Prototype.listPublicArchivedThreadsAsync( end return returnedValue - end) + end) :: future.FutureLike end --[[ @@ -222,7 +226,11 @@ function GuildBehaviour.Prototype.listPrivateArchivedThreadsAsync( end return returnedValue - end) + end) :: future.FutureLike end --[[ @@ -263,7 +271,11 @@ function GuildBehaviour.Prototype.listJoinedPrivateArchivedThreadsAsync( end return returnedValue - end) + end) :: future.FutureLike end --[[ @@ -272,7 +284,7 @@ end function GuildBehaviour.Prototype.setNameAsync(self: Channel, groupName: string) return self:modifyAsync({ name = groupName, - }) + }) :: future.FutureLike> end function GuildBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/media.luau b/packages/classes/src/channels/behaviour/media.luau index 872fb3e..6347fad 100644 --- a/packages/classes/src/channels/behaviour/media.luau +++ b/packages/classes/src/channels/behaviour/media.luau @@ -36,7 +36,7 @@ function MediaBehaviour.Prototype.createPostAsync(self: Channel, post: bui assert(response:isOk(), response:unwrapErr()) return response:unwrapOk().id - end) + end) :: future.FutureLike end function MediaBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/text.luau b/packages/classes/src/channels/behaviour/text.luau index 293ba27..8f0f3c5 100644 --- a/packages/classes/src/channels/behaviour/text.luau +++ b/packages/classes/src/channels/behaviour/text.luau @@ -33,7 +33,7 @@ function TextBehaviour.Prototype.bulkDeleteMessagesAsync(self: Channel, me assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -67,7 +67,7 @@ function TextBehaviour.Prototype.getMessagesAsync( end return messages - end) + end) :: future.FutureLike end --[[ @@ -82,7 +82,7 @@ function TextBehaviour.Prototype.getMessageAsync(self: Channel, messageId: assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -97,7 +97,7 @@ function TextBehaviour.Prototype.createMessageAsync(self: Channel, json: b assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -118,7 +118,7 @@ function TextBehaviour.Prototype.getPinnedMessagesAsync(self: Channel) end return messages - end) + end) :: future.FutureLike end --[[ @@ -133,7 +133,7 @@ function TextBehaviour.Prototype.pinMessageAsync(self: Channel, messageId: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -148,7 +148,7 @@ function TextBehaviour.Prototype.unpinMessageAsync(self: Channel, messageI assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -162,8 +162,8 @@ function TextBehaviour.Prototype.startThread(self: Channel, json: builders assert(response:isOk(), response:unwrapErr()) - return response.id - end) + return response:unwrapOk().id + end) :: future.FutureLike end function TextBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/channels/behaviour/thread.luau b/packages/classes/src/channels/behaviour/thread.luau index 4c9472f..5be7120 100644 --- a/packages/classes/src/channels/behaviour/thread.luau +++ b/packages/classes/src/channels/behaviour/thread.luau @@ -27,7 +27,7 @@ function ThreadBehaviour.Prototype.joinThreadAsync(self: Channel) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -42,7 +42,7 @@ function ThreadBehaviour.Prototype.addMemberToThreadAsync(self: Channel, u assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -57,7 +57,7 @@ function ThreadBehaviour.Prototype.leaveThreadAsync(self: Channel) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -72,7 +72,7 @@ function ThreadBehaviour.Prototype.removeMemberAsync(self: Channel, userId assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -87,7 +87,7 @@ function ThreadBehaviour.Prototype.removeMemberAsync(self: Channel, userId assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -106,7 +106,7 @@ function ThreadBehaviour.Prototype.getMemberAsync(self: Channel, userId: s assert(response:isOk(), response:unwrapErr()) return threadMember.new(self.state, self.guildId, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -133,12 +133,12 @@ function ThreadBehaviour.Prototype.listMembersAsync( local threadMembers = {} - for _, memberData in response do + for _, memberData in response:unwrapOk() do table.insert(threadMembers, threadMember.new(self.state, self.guildId, memberData)) end return threadMembers - end) + end) :: future.FutureLike end function ThreadBehaviour.Interface.inheritProperties(class: any, channelData: apiTypes.ChannelObject) diff --git a/packages/classes/src/guild/guild.luau b/packages/classes/src/guild/guild.luau index 5e6e569..5aa3ac0 100644 --- a/packages/classes/src/guild/guild.luau +++ b/packages/classes/src/guild/guild.luau @@ -60,7 +60,7 @@ function Guild.Prototype.createSlashCommandAsync(self: Guild, slashCommand: buil assert(response:isOk(), response:unwrapErr()) return commandObject.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -77,7 +77,7 @@ function Guild.Prototype.deleteSlashCommandAsync(self: Guild, slashCommandId: ap assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -98,7 +98,7 @@ function Guild.Prototype.editSlashCommandAsync( assert(response:isOk(), response:unwrapErr()) return commandObject.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -123,7 +123,7 @@ function Guild.Prototype.getSlashCommandsAsync(self: Guild, withLocalizations: b end return commands - end) + end) :: future.FutureLike end --[[ @@ -148,7 +148,7 @@ function Guild.Prototype.overwriteSlashCommandsAsync(self: Guild, slashCommands: end return commands - end) + end) :: future.FutureLike end --[[ @@ -165,7 +165,7 @@ function Guild.Prototype.fetchGuildPreviewAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return preview.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -184,7 +184,7 @@ function Guild.Prototype.modifyGuildAsync(self: Guild, json: builders.guildJSON, self:sync(response:unwrapOk()) return self - end) + end) :: future.FutureLike end --[[ @@ -200,7 +200,7 @@ function Guild.Prototype.deleteGuildAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -226,7 +226,7 @@ function Guild.Prototype.getChannelsAsync(self: Guild) end return channels - end) + end) :: future.FutureLike end --[[ @@ -244,14 +244,14 @@ function Guild.Prototype.getTextChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -269,14 +269,14 @@ function Guild.Prototype.getVoiceChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -294,14 +294,14 @@ function Guild.Prototype.getCategoryChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -319,14 +319,14 @@ function Guild.Prototype.getAnnouncementChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -344,14 +344,14 @@ function Guild.Prototype.getStageVoiceChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -369,14 +369,14 @@ function Guild.Prototype.getDirectoryChannelsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -398,7 +398,7 @@ function Guild.Prototype.createChannelAsync(self: Guild, json: builders.chann assert(response:isOk(), response:unwrapErr()) return constructChannelFromData(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -420,12 +420,12 @@ function Guild.Prototype.getThreadsAsync(self: Guild) local channels: { unknown } = {} - for _, channelData in next, response.threads do + for _, channelData in next, response:unwrapOk().threads do table.insert(channels, constructChannelFromData(self.state, channelData)) end return channels - end) + end) :: future.FutureLike end --[[ @@ -443,14 +443,14 @@ function Guild.Prototype.getAnnouncementThreadsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -468,14 +468,14 @@ function Guild.Prototype.getPublicThreadsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -493,14 +493,14 @@ function Guild.Prototype.getPrivateThreadsAsync(self: Guild) continue end - table.insert(resolvedChannels, channel :: guildText.GuildText) + table.insert(resolvedChannels, channel :: any) end return resolvedChannels else error(channels:unwrapErr()) end - end) + end) :: future.FutureLike end --[[ @@ -516,7 +516,7 @@ function Guild.Prototype.getGuildMemberAsync(self: Guild, userId: string) assert(response:isOk(), response:unwrapErr()) return member.new(self.state, self.id, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -542,7 +542,7 @@ function Guild.Prototype.listGuildMembersAsync(self: Guild, lastSnowflake: strin end return members - end) + end) :: future.FutureLike end --[[ @@ -568,7 +568,7 @@ function Guild.Prototype.searchGuildMembersAsync(self: Guild, query: string, lim end return members - end) + end) :: future.FutureLike end --[[ @@ -606,10 +606,10 @@ function Guild.Prototype.addGuildMemberAsync( if data then return member.new(self.state, self.id, data) + else + return nil :: any end - - return - end) + end) :: future.FutureLike end --[[ @@ -624,7 +624,7 @@ function Guild.Prototype.kickGuildMemberAsync(self: Guild, userId: apiTypes.Snow assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -660,7 +660,7 @@ function Guild.Prototype.banGuildMemberAsync( assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -675,31 +675,33 @@ function Guild.Prototype.bulkBanGuildMembersAsync( string, { failedUsers: { apiTypes.Snowflake }, bannedUsers: { apiTypes.Snowflake } } > - return future.Future.new(function() - local request = self.state.rest:newRequest() + return future.Future.new( + function() + local request = self.state.rest:newRequest() - if deleteMessageSeconds then - assert(deleteMessageSeconds < 604800, "deleteMessageSeconds must be less than 604800") - assert(deleteMessageSeconds > 0, "deleteMessageSeconds must be greater than 0") - end + if deleteMessageSeconds then + assert(deleteMessageSeconds < 604800, "deleteMessageSeconds must be less than 604800") + assert(deleteMessageSeconds > 0, "deleteMessageSeconds must be greater than 0") + end - local response = rest.guild - .bulkGuildBanAsync(request, self.id, { - user_ids = userIds, - delete_message_seconds = deleteMessageSeconds, - }, reason) - :await() + local response = rest.guild + .bulkGuildBanAsync(request, self.id, { + user_ids = userIds, + delete_message_seconds = deleteMessageSeconds, + }, reason) + :await() - assert(response:isOk(), response:unwrapErr()) + assert(response:isOk(), response:unwrapErr()) - local data = response:unwrapOk() - local returnedValue = {} + local data = response:unwrapOk() + local returnedValue = {} - returnedValue.bannedUsers = data.banned_users - returnedValue.failedUsers = data.failed_users + returnedValue.bannedUsers = data.banned_users + returnedValue.failedUsers = data.failed_users - return returnedValue - end) + return returnedValue + end + ) :: future.FutureLike end --[[ @@ -731,7 +733,7 @@ function Guild.Prototype.getGuildBansAsync( end return bans - end) + end) :: future.FutureLike end --[[ @@ -749,10 +751,10 @@ function Guild.Prototype.getGuildBanAsync(self: Guild, userId: apiTypes.Snowflak if data then return ban.new(data) + else + return nil :: any end - - return nil - end) + end) :: future.FutureLike end --[[ @@ -773,7 +775,7 @@ function Guild.Prototype.getGuildRolesAsync(self: Guild) end return roles - end) + end) :: future.FutureLike end --[[ @@ -788,7 +790,7 @@ function Guild.Prototype.getGuildRoleAsync(self: Guild, roleId: apiTypes.Snowfla assert(response:isOk(), response:unwrapErr()) return role.new(self.state, self.id, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -803,7 +805,7 @@ function Guild.Prototype.createGuildRoleAsync(self: Guild, roleJson: builders.ro assert(response:isOk(), response:unwrapErr()) return role.new(self.state, self.id, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -822,7 +824,7 @@ function Guild.Prototype.setGuildMFALevelAsync(self: Guild, mfaLevel: apiTypes.M assert(response:isOk(), response:unwrapErr()) return apiTypes.guild.MFALevel[response:unwrapOk()] - end) + end) :: future.FutureLike end --[[ @@ -847,7 +849,7 @@ function Guild.Prototype.getGuildPruneCountAsync(self: Guild, days: number?, inc assert(response:isOk(), response:unwrapErr()) return response:unwrapOk().pruned - end) + end) :: future.FutureLike end --[[ @@ -886,7 +888,7 @@ function Guild.Prototype.beginGuildPruneAsync( else return 0 end - end) + end) :: future.FutureLike end --[[ @@ -907,7 +909,7 @@ function Guild.Prototype.getGuildVoiceRegionsAsync(self: Guild) end return voiceRegions - end) + end) :: future.FutureLike end --[[ @@ -928,7 +930,7 @@ function Guild.Prototype.getGuildInvitesAsync(self: Guild) end return invites - end) + end) :: future.FutureLike end --[[ @@ -949,7 +951,7 @@ function Guild.Prototype.getGuildIntegrationsAsync(self: Guild) end return integrations - end) + end) :: future.FutureLike end --[[ @@ -967,7 +969,7 @@ function Guild.Prototype.deleteGuildIntegrationAsync(self: Guild, integrationId: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -982,7 +984,7 @@ function Guild.Prototype.getGuildWidgetSettingsAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return widgetSettings.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -997,8 +999,8 @@ function Guild.Prototype.modifyGuildWidgetAsync(self: Guild, json: builders.widg assert(response:isOk(), response:unwrapErr()) - return widgetSettings.new(response:unwarpOk()) - end) + return widgetSettings.new(response:unwrapOk()) + end) :: future.FutureLike end --[[ @@ -1014,7 +1016,7 @@ function Guild.Prototype.getGuildWidgetAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return widget.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -1030,7 +1032,7 @@ function Guild.Prototype.getGuildVanityUrlAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return vanityUrl.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -1052,7 +1054,7 @@ function Guild.Prototype.getGuildWidgetImageAsync( assert(response:isOk(), response:unwrapErr()) return response:unwrapOk() - end) + end) :: future.FutureLike end --[[ @@ -1069,7 +1071,7 @@ function Guild.Prototype.getGuildWelcomeScreenAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return welcomeScreen.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -1084,7 +1086,7 @@ function Guild.Prototype.modifyGuildWelcomeScreenAsync(self: Guild, json: builde assert(response:isOk(), response:unwrapErr()) return welcomeScreen.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -1099,7 +1101,7 @@ function Guild.Prototype.getGuildOnboardingAsync(self: Guild) assert(response:isOk(), response:unwrapErr()) return onboarding.new(response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -1115,7 +1117,7 @@ function Guild.Prototype.modifyGuildOnboardingAsync(self: Guild, json: builders. assert(response:isOk(), response:unwrapErr()) return onboarding.new(response:unwrapOk()) - end) + end) :: future.FutureLike end function Guild.Prototype.sync(self: Guild, guildData: apiTypes.GuildObject) diff --git a/packages/classes/src/guild/member.luau b/packages/classes/src/guild/member.luau index 313568d..3e451ed 100644 --- a/packages/classes/src/guild/member.luau +++ b/packages/classes/src/guild/member.luau @@ -53,7 +53,7 @@ function Member.Prototype.banAsync( assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -70,7 +70,7 @@ function Member.Prototype.kickAsync(self: Member, reason: string?) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -110,106 +110,88 @@ function Member.Prototype.modifyAsync( self:sync(response:unwrapOk()) return self - end) + end) :: future.FutureLike end --[[ will mute the user in voice channels the user is in. Returns the updated Member. ]] function Member.Prototype.muteAsync(self: Member, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - muted = true, - }, reason) - end) + return self:modifyAsync({ + muted = true, + }, reason) end --[[ will unmute the user in voice channels the user is in. Returns the updated Member. ]] function Member.Prototype.unmuteAsync(self: Member, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - muted = false, - }, reason) - end) + return self:modifyAsync({ + muted = false, + }, reason) end --[[ will deafen the user in voice channels the user is in. Returns the updated Member. ]] function Member.Prototype.deafenAsync(self: Member, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - deaf = true, - }, reason) - end) + return self:modifyAsync({ + deaf = true, + }, reason) end --[[ will undeafen the user in voice channels the user is in. Returns the updated Member. ]] function Member.Prototype.undeafenAsync(self: Member, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - deaf = false, - }, reason) - end) + return self:modifyAsync({ + deaf = false, + }, reason) end --[[ will set the nickname of the user. Returns the updated Member. ]] function Member.Prototype.setNicknameAsync(self: Member, nickname: string, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - nickname = nickname, - }, reason) - end) + return self:modifyAsync({ + nickname = nickname, + }, reason) end --[[ will set all roles that the user has in this guild. Returns the updated Member. ]] function Member.Prototype.setRolesAsync(self: Member, roles: { apiTypes.Snowflake }, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - roles = roles, - }, reason) - end) + return self:modifyAsync({ + roles = roles, + }, reason) end --[[ will move the user between different voice channels. Returns the updated Member. ]] function Member.Prototype.moveVoiceChannelAsync(self: Member, channelId: apiTypes.Snowflake, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - channelId = channelId, - }, reason) - end) + return self:modifyAsync({ + channelId = channelId, + }, reason) end --[[ will disconnect the user from voice channels the user is in. Returns the updated Member. ]] function Member.Prototype.disconnectFromVoiceChannelAsync(self: Member, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - channelId = false, - }, reason) - end) + return self:modifyAsync({ + channelId = false, + }, reason) end --[[ Disables the users communication up to a specific time. Returns the updated Member. ]] function Member.Prototype.disableAsync(self: Member, disabledUntil: stdPolyfills.DateTime, reason: string?) - return future.Future.new(function() - return self:modifyAsync({ - communicationDisabledUntil = disabledUntil:toIsoDate(), - }, reason) - end) + return self:modifyAsync({ + communicationDisabledUntil = disabledUntil:toIsoDate(), + }, reason) end --[[ diff --git a/packages/classes/src/guild/role.luau b/packages/classes/src/guild/role.luau index 9363a51..2f0599f 100644 --- a/packages/classes/src/guild/role.luau +++ b/packages/classes/src/guild/role.luau @@ -31,7 +31,7 @@ function Role.Prototype.deleteAsync(self: Role, reason: string?) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -48,7 +48,7 @@ function Role.Prototype.modifyAsync(self: Role, json: builders.roleJSON, reason: self:sync(response:unwrapOk()) return self - end) + end) :: future.FutureLike end --[[ @@ -74,7 +74,7 @@ function Role.Prototype.modifyPositionAsync(self: Role, position: number, reason end return guildRoles - end) + end) :: future.FutureLike end --[[ diff --git a/packages/classes/src/interaction/types/command.luau b/packages/classes/src/interaction/types/command.luau index 9e8e73d..b9765fa 100644 --- a/packages/classes/src/interaction/types/command.luau +++ b/packages/classes/src/interaction/types/command.luau @@ -44,7 +44,7 @@ function Command.Prototype.deferAsync(self: Command) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -69,8 +69,10 @@ function Command.Prototype.messageAsync(self: Command, messageJSON: builders.mes if responseMessage and data.resource.message then return message.new(self.state, data.resource.message) + else + return nil :: any end - end) + end) :: future.FutureLike end --[[ @@ -89,7 +91,7 @@ function Command.Prototype.getResponseAsync(self: Command, threadId: string?) assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -108,7 +110,7 @@ function Command.Prototype.editResponseAsync(self: Command, messageJSON: builder assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -123,7 +125,7 @@ function Command.Prototype.deleteResponseAsync(self: Command) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -148,7 +150,7 @@ function Command.Prototype.createFollowupResponseAsync( assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -167,7 +169,7 @@ function Command.Prototype.getFollowupResponseAsync(self: Command, messageId: st assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -191,7 +193,7 @@ function Command.Prototype.editFollowupResponseAsync( assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -206,7 +208,7 @@ function Command.Prototype.deleteFollowupResponseAsync(self: Command, messageId: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ diff --git a/packages/classes/src/interaction/types/component.luau b/packages/classes/src/interaction/types/component.luau index 3e49f04..28469b1 100644 --- a/packages/classes/src/interaction/types/component.luau +++ b/packages/classes/src/interaction/types/component.luau @@ -43,7 +43,7 @@ function Component.Prototype.deferAsync(self: Component) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -68,8 +68,10 @@ function Component.Prototype.messageAsync(self: Component, messageJSON: builders if responseMessage and data.resource.message then return message.new(self.state, data.resource.message) + else + return nil :: any end - end) + end) :: future.FutureLike end --[[ @@ -88,7 +90,7 @@ function Component.Prototype.getResponseAsync(self: Component, threadId: string? assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -107,7 +109,7 @@ function Component.Prototype.editResponseAsync(self: Component, messageJSON: bui assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -122,7 +124,7 @@ function Component.Prototype.deleteResponseAsync(self: Component) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -147,7 +149,7 @@ function Component.Prototype.createFollowupResponseAsync( assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -166,7 +168,7 @@ function Component.Prototype.getFollowupResponseAsync(self: Component, messageId assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -190,7 +192,7 @@ function Component.Prototype.editFollowupResponseAsync( assert(response:isOk(), response:unwrapErr()) return message.new(self.state, response:unwrapOk()) - end) + end) :: future.FutureLike end --[[ @@ -205,7 +207,7 @@ function Component.Prototype.deleteFollowupResponseAsync(self: Component, messag assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end function Component.Prototype.sync(self: Component, interactionData: apiTypes.InteractionObject) diff --git a/packages/classes/src/interaction/types/ping.luau b/packages/classes/src/interaction/types/ping.luau index aa6b45b..1a31d04 100644 --- a/packages/classes/src/interaction/types/ping.luau +++ b/packages/classes/src/interaction/types/ping.luau @@ -39,7 +39,7 @@ function Ping.Prototype.pongAsync(self: Ping) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end function Ping.Prototype.sync(self: Ping, interactionData: apiTypes.InteractionObject) diff --git a/packages/classes/src/message/message.luau b/packages/classes/src/message/message.luau index 1c4f7ed..eabd1c2 100644 --- a/packages/classes/src/message/message.luau +++ b/packages/classes/src/message/message.luau @@ -59,7 +59,7 @@ function Message.Prototype.addReactionAsync(self: Message, emoji: builders.emoji assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -78,7 +78,7 @@ function Message.Prototype.removeOwnReactionAsync(self: Message, emoji: builders assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -97,7 +97,7 @@ function Message.Prototype.deleteUserReactionAsync(self: Message, emoji: builder assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -133,7 +133,7 @@ function Message.Prototype.getReactionsAsync( end return users - end) + end) :: future.FutureLike end --[[ @@ -148,7 +148,7 @@ function Message.Prototype.deleteAllReactionsAsync(self: Message) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -167,7 +167,7 @@ function Message.Prototype.deleteAllReactionsForEmojiAsync(self: Message, emoji: assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end --[[ @@ -193,7 +193,7 @@ function Message.Prototype.editMessageAsync(self: Message, message: builders.mes self:sync(response:unwrapOk()) return self - end) + end) :: future.FutureLike end --[[ Delete a message. If operating on a guild channel and trying to delete a message that was not sent by the current user, @@ -208,7 +208,7 @@ function Message.Prototype.deleteMessageAsync(self: Message, reason: string) assert(response:isOk(), response:unwrapErr()) return nil - end) + end) :: future.FutureLike end function Message.Prototype.sync(self: Message, messageData: apiTypes.MessageObject) diff --git a/packages/websocket/src/shard.luau b/packages/websocket/src/shard.luau index c82e659..d857c5e 100644 --- a/packages/websocket/src/shard.luau +++ b/packages/websocket/src/shard.luau @@ -150,7 +150,13 @@ function Shard.Prototype.disconnectAsync(self: Shard, code: number?) self.onSocketDisconnected:invoke(code) if self.socketInstance then - self.socketInstance.close(code) + xpcall(function() + self.socketInstance.close(code) + end, function(errorMessage) + self.logger:debug( + `Error during socketInstance.close, assuming socket has been closed: {tostring(errorMessage)}` + ) + end) end if self.socketThread then