diff --git a/src/handlers/channels/CHANNEL_CREATE.ts b/src/handlers/channels/CHANNEL_CREATE.ts index 3c04e9288..135dbc0d9 100644 --- a/src/handlers/channels/CHANNEL_CREATE.ts +++ b/src/handlers/channels/CHANNEL_CREATE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelCreate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordChannel; + const payload = data.d as Channel; const discordenoChannel = await structures.createDiscordenoChannel(payload); await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 4e41719c6..f4c07229f 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -1,19 +1,19 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelDelete(data: DiscordGatewayPayload) { - const payload = data.d as DiscordChannel; + const payload = data.d as Channel; const cachedChannel = await cacheHandlers.get("channels", payload.id); if (!cachedChannel) return; if ( - cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guild_id + cachedChannel.type === DiscordChannelTypes.GUILD_VOICE && payload.guildId ) { - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const guild = await cacheHandlers.get("guilds", payload.guildId); if (guild) { return Promise.all(guild.voiceStates.map(async (vs, key) => { diff --git a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index 85234d64c..371274096 100644 --- a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,17 +1,17 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { DiscordChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; +import { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordChannelPinsUpdate; + const payload = data.d as ChannelPinsUpdate; - const channel = await cacheHandlers.get("channels", payload.channel_id); + const channel = await cacheHandlers.get("channels", payload.channelId); if (!channel) return; - const guild = payload.guild_id - ? await cacheHandlers.get("guilds", payload.guild_id) + const guild = payload.guildId + ? await cacheHandlers.get("guilds", payload.guildId) : undefined; - eventHandlers.channelPinsUpdate?.(channel, guild, payload.last_pin_timestamp); + eventHandlers.channelPinsUpdate?.(channel, guild, payload.lastPinTimestamp); } diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index 27f0d5d80..1045545c5 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; export async function handleChannelUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordChannel; + const payload = data.d as Channel; const cachedChannel = await cacheHandlers.get("channels", payload.id); const discordenoChannel = await structures.createDiscordenoChannel(payload); diff --git a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts index 59ef82873..2ceae936b 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts @@ -2,16 +2,12 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { ApplicationCommandCreateUpdateDelete, - DiscordApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleApplicationCommandCreate( data: DiscordGatewayPayload, ) { eventHandlers.applicationCommandCreate?.( - snakeKeysToCamelCase( - data.d as DiscordApplicationCommandCreateUpdateDelete, - ), + data.d as ApplicationCommandCreateUpdateDelete, ); } diff --git a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts index 0845aa0a9..63d96b23e 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts @@ -2,14 +2,10 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { ApplicationCommandCreateUpdateDelete, - DiscordApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleApplicationCommandDelete(data: DiscordGatewayPayload) { eventHandlers.applicationCommandDelete?.( - snakeKeysToCamelCase( - data.d as DiscordApplicationCommandCreateUpdateDelete, - ), + data.d as ApplicationCommandCreateUpdateDelete, ); } diff --git a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts index 4d55a574b..ad9ffde28 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts @@ -2,14 +2,10 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { ApplicationCommandCreateUpdateDelete, - DiscordApplicationCommandCreateUpdateDelete, } from "../../types/interactions/application_command_create_update_delete.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) { eventHandlers.applicationCommandUpdate?.( - snakeKeysToCamelCase( - data.d as DiscordApplicationCommandCreateUpdateDelete, - ), + data.d as ApplicationCommandCreateUpdateDelete, ); } diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index 31bf720e7..40ae9f496 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,12 +1,12 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; -import { DiscordGuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; +import { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { Collection } from "../../util/collection.ts"; export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildEmojisUpdate; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildEmojisUpdate; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const cachedEmojis = guild.emojis; @@ -14,7 +14,7 @@ export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) { payload.emojis.map((emoji) => [emoji.id!, emoji]), ); - await cacheHandlers.set("guilds", payload.guild_id, guild); + await cacheHandlers.set("guilds", payload.guildId, guild); eventHandlers.guildEmojisUpdate?.( guild, diff --git a/src/handlers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts index 26df8e004..56df5c0e1 100644 --- a/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; +import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; export async function handleGuildBanAdd(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildBanAddRemove; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildBanAddRemove; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const member = await cacheHandlers.get("members", payload.user.id); diff --git a/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts index 61301ce4c..5c220588d 100644 --- a/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; +import { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; export async function handleGuildBanRemove(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildBanAddRemove; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildBanAddRemove; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const member = await cacheHandlers.get("members", payload.user.id); diff --git a/src/handlers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts index 3d391e9f3..d3fff22d1 100644 --- a/src/handlers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -2,14 +2,14 @@ import { eventHandlers } from "../../bot.ts"; import { cache, cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuild } from "../../types/guilds/guild.ts"; +import { Guild } from "../../types/guilds/guild.ts"; import { ws } from "../../ws/ws.ts"; export async function handleGuildCreate( data: DiscordGatewayPayload, shardId: number, ) { - const payload = data.d as DiscordGuild; + const payload = data.d as Guild; // When shards resume they emit GUILD_CREATE again. if (await cacheHandlers.has("guilds", payload.id)) return; diff --git a/src/handlers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts index 54c8b0b3b..bf1672a0d 100644 --- a/src/handlers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -1,14 +1,14 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordUnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; +import { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; import { ws } from "../../ws/ws.ts"; export async function handleGuildDelete( data: DiscordGatewayPayload, shardId: number, ) { - const payload = data.d as DiscordUnavailableGuild; + const payload = data.d as UnavailableGuild; const guild = await cacheHandlers.get("guilds", payload.id); if (!guild) return; diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index c576e6acf..7c28c6520 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,14 +1,14 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; +import { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; export async function handleGuildIntegrationsUpdate( data: DiscordGatewayPayload, ) { - const payload = data.d as DiscordGuildIntegrationsUpdate; + const payload = data.d as GuildIntegrationsUpdate; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; eventHandlers.guildIntegrationsUpdate?.(guild); diff --git a/src/handlers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts index a565ce2bd..186b40c25 100644 --- a/src/handlers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -2,10 +2,10 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { GuildUpdateChange } from "../../types/discordeno/guild_update_change.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuild } from "../../types/guilds/guild.ts"; +import { Guild } from "../../types/guilds/guild.ts"; export async function handleGuildUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuild; + const payload = data.d as Guild; const newGuild = await cacheHandlers.get("guilds", payload.id); if (!newGuild) return; diff --git a/src/handlers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts index 5d7f9dd38..1f6aede60 100644 --- a/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,17 +1,13 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { - DiscordIntegrationCreateUpdate, IntegrationCreateUpdate, } from "../../types/integration/integration_create_update.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleIntegrationCreate( data: DiscordGatewayPayload, ) { eventHandlers.integrationCreate?.( - snakeKeysToCamelCase( - data.d as DiscordIntegrationCreateUpdate, - ), + data.d as IntegrationCreateUpdate, ); } diff --git a/src/handlers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts index 6422cf9ba..1718d2a3c 100644 --- a/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,15 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { IntegrationCreateUpdate } from "../../types/integration/integration_create_update.ts"; -import { - DiscordIntegrationDelete, -} from "../../types/integration/integration_delete.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { IntegrationDelete } from "../../types/integration/integration_delete.ts"; export function handleIntegrationDelete(data: DiscordGatewayPayload) { eventHandlers.integrationDelete?.( - snakeKeysToCamelCase( - data.d as DiscordIntegrationDelete, - ), + data.d as IntegrationDelete, ); } diff --git a/src/handlers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts index 564f73cf7..c756ee2b3 100644 --- a/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,15 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { - DiscordIntegrationCreateUpdate, IntegrationCreateUpdate, } from "../../types/integration/integration_create_update.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleIntegrationUpdate(data: DiscordGatewayPayload) { eventHandlers.integrationUpdate?.( - snakeKeysToCamelCase( - data.d as DiscordIntegrationCreateUpdate, - ), + data.d as IntegrationCreateUpdate, ); } diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 78c292cd4..618cc1bdb 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -2,15 +2,15 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import { DiscordInteraction } from "../../types/interactions/interaction.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import { Interaction } from "../../types/interactions/interaction.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordInteraction; - const discordenoMember = payload.guild_id + const payload = data.d as Interaction; + const discordenoMember = payload.guildId ? await structures.createDiscordenoMember( - payload.member as DiscordGuildMemberWithUser, - payload.guild_id, + payload.member as GuildMemberWithUser, + payload.guildId, ) : undefined; if (discordenoMember) { diff --git a/src/handlers/invites/INVITE_CREATE.ts b/src/handlers/invites/INVITE_CREATE.ts index a222c46a0..bb5a4d8c7 100644 --- a/src/handlers/invites/INVITE_CREATE.ts +++ b/src/handlers/invites/INVITE_CREATE.ts @@ -1,13 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { - DiscordInviteCreate, - InviteCreate, -} from "../../types/invites/invite_create.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { InviteCreate } from "../../types/invites/invite_create.ts"; export function handleInviteCreate(data: DiscordGatewayPayload) { eventHandlers.inviteCreate?.( - snakeKeysToCamelCase(data.d as DiscordInviteCreate), + data.d as InviteCreate, ); } diff --git a/src/handlers/invites/INVITE_DELETE.ts b/src/handlers/invites/INVITE_DELETE.ts index a633cd500..6c7b137a8 100644 --- a/src/handlers/invites/INVITE_DELETE.ts +++ b/src/handlers/invites/INVITE_DELETE.ts @@ -1,13 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { - DiscordInviteDelete, - InviteDelete, -} from "../../types/invites/invite_delete.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { InviteDelete } from "../../types/invites/invite_delete.ts"; export function handleInviteDelete(data: DiscordGatewayPayload) { eventHandlers.inviteDelete?.( - snakeKeysToCamelCase(data.d as DiscordInviteDelete), + data.d as InviteDelete, ); } diff --git a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts index c65cf50c3..1057b666e 100644 --- a/src/handlers/members/GUILD_MEMBERS_CHUNK.ts +++ b/src/handlers/members/GUILD_MEMBERS_CHUNK.ts @@ -1,17 +1,17 @@ import { cache, cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; -import { Collection } from "../../util/collection.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMembersChunk } from "../../types/members/guild_members_chunk.ts"; +import { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts"; +import { Collection } from "../../util/collection.ts"; export async function handleGuildMembersChunk(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildMembersChunk; + const payload = data.d as GuildMembersChunk; const members = await Promise.all( payload.members.map(async (member) => { const discordenoMember = await structures.createDiscordenoMember( member, - payload.guild_id, + payload.guildId, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); @@ -26,17 +26,17 @@ export async function handleGuildMembersChunk(data: DiscordGatewayPayload) { const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce); if (!resolve) return; - if (payload.chunk_index + 1 === payload.chunk_count) { + if (payload.chunkIndex + 1 === payload.chunkCount) { cache.fetchAllMembersProcessingRequests.delete(payload.nonce); // Only 1 chunk most likely is all members or users only request a small amount of users - if (payload.chunk_count === 1) { + if (payload.chunkCount === 1) { return resolve(new Collection(members.map((m) => [m.id, m]))); } return resolve( await cacheHandlers.filter( "members", - (m) => m.guilds.has(payload.guild_id), + (m) => m.guilds.has(payload.guildId), ), ); } diff --git a/src/handlers/members/GUILD_MEMBER_ADD.ts b/src/handlers/members/GUILD_MEMBER_ADD.ts index af60fc83a..722bce40e 100644 --- a/src/handlers/members/GUILD_MEMBER_ADD.ts +++ b/src/handlers/members/GUILD_MEMBER_ADD.ts @@ -2,17 +2,17 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberAdd } from "../../types/members/guild_member_add.ts"; +import { GuildMemberAdd } from "../../types/members/guild_member_add.ts"; export async function handleGuildMemberAdd(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildMemberAdd; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildMemberAdd; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; guild.memberCount++; const discordenoMember = await structures.createDiscordenoMember( payload, - payload.guild_id, + payload.guildId, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); diff --git a/src/handlers/members/GUILD_MEMBER_REMOVE.ts b/src/handlers/members/GUILD_MEMBER_REMOVE.ts index 0b4e66495..cbf075a41 100644 --- a/src/handlers/members/GUILD_MEMBER_REMOVE.ts +++ b/src/handlers/members/GUILD_MEMBER_REMOVE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberRemove } from "../../types/members/guild_member_remove.ts"; +import { GuildMemberRemove } from "../../types/members/guild_member_remove.ts"; export async function handleGuildMemberRemove(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildMemberRemove; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildMemberRemove; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; guild.memberCount--; diff --git a/src/handlers/members/GUILD_MEMBER_UPDATE.ts b/src/handlers/members/GUILD_MEMBER_UPDATE.ts index e29988efb..6bcde3886 100644 --- a/src/handlers/members/GUILD_MEMBER_UPDATE.ts +++ b/src/handlers/members/GUILD_MEMBER_UPDATE.ts @@ -2,22 +2,20 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberUpdate } from "../../types/members/guild_member_update.ts"; +import { GuildMemberUpdate } from "../../types/members/guild_member_update.ts"; export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildMemberUpdate; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildMemberUpdate; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const cachedMember = await cacheHandlers.get("members", payload.user.id); - const guildMember = cachedMember?.guilds.get(payload.guild_id); + const guildMember = cachedMember?.guilds.get(payload.guildId); const newMemberData = { ...payload, - // deno-lint-ignore camelcase - premium_since: payload.premium_since || undefined, - // deno-lint-ignore camelcase - joined_at: new Date(guildMember?.joinedAt || Date.now()) + premiumSince: payload.premiumSince || undefined, + joinedAt: new Date(guildMember?.joinedAt || Date.now()) .toISOString(), deaf: guildMember?.deaf || false, mute: guildMember?.mute || false, @@ -25,7 +23,7 @@ export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) { }; const discordenoMember = await structures.createDiscordenoMember( newMemberData, - payload.guild_id, + payload.guildId, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); diff --git a/src/handlers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts index 1ef67dbcc..3a3c9080d 100644 --- a/src/handlers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -2,12 +2,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import { DiscordMessage, Message } from "../../types/messages/message.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import { Message } from "../../types/messages/message.ts"; export async function handleMessageCreate(data: DiscordGatewayPayload) { - const payload = snakeKeysToCamelCase(data.d as DiscordMessage) as Message; + const payload = data.d as Message; const channel = await cacheHandlers.get("channels", payload.channelId); if (channel) channel.lastMessageId = payload.id; @@ -18,7 +17,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) { if (payload.member && guild) { // If in a guild cache the author as a member const discordenoMember = await structures.createDiscordenoMember( - { ...payload.member, user: payload.author } as DiscordGuildMemberWithUser, + { ...payload.member, user: payload.author } as GuildMemberWithUser, guild.id, ); await cacheHandlers.set("members", discordenoMember.id, discordenoMember); @@ -29,7 +28,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) { // Cache the member if its a valid member if (mention.member && guild) { const discordenoMember = await structures.createDiscordenoMember( - { ...mention.member, user: mention } as DiscordGuildMemberWithUser, + { ...mention.member, user: mention } as GuildMemberWithUser, guild.id, ); @@ -43,7 +42,7 @@ export async function handleMessageCreate(data: DiscordGatewayPayload) { } const message = await structures.createDiscordenoMessage( - data.d as DiscordMessage, + data.d as Message, ); // Cache the message await cacheHandlers.set("messages", payload.id, message); diff --git a/src/handlers/messages/MESSAGE_DELETE.ts b/src/handlers/messages/MESSAGE_DELETE.ts index 48f25006f..f8bdc5e40 100644 --- a/src/handlers/messages/MESSAGE_DELETE.ts +++ b/src/handlers/messages/MESSAGE_DELETE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordMessageDelete } from "../../types/messages/message_delete.ts"; +import { MessageDelete } from "../../types/messages/message_delete.ts"; export async function handleMessageDelete(data: DiscordGatewayPayload) { - const payload = data.d as DiscordMessageDelete; - const channel = await cacheHandlers.get("channels", payload.channel_id); + const payload = data.d as MessageDelete; + const channel = await cacheHandlers.get("channels", payload.channelId); if (!channel) return; eventHandlers.messageDelete?.( diff --git a/src/handlers/messages/MESSAGE_DELETE_BULK.ts b/src/handlers/messages/MESSAGE_DELETE_BULK.ts index 050717f1a..058932208 100644 --- a/src/handlers/messages/MESSAGE_DELETE_BULK.ts +++ b/src/handlers/messages/MESSAGE_DELETE_BULK.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordMessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts"; +import { MessageDeleteBulk } from "../../types/messages/message_delete_bulk.ts"; export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) { - const payload = data.d as DiscordMessageDeleteBulk; - const channel = await cacheHandlers.get("channels", payload.channel_id); + const payload = data.d as MessageDeleteBulk; + const channel = await cacheHandlers.get("channels", payload.channelId); if (!channel) return; return Promise.all(payload.ids.map(async (id) => { diff --git a/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts index 8af308a15..9ba917f7c 100644 --- a/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -3,14 +3,13 @@ import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { - DiscordMessageReactionAdd, MessageReactionAdd, } from "../../types/messages/message_reaction_add.ts"; import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { - const payload = data.d as DiscordMessageReactionAdd; - const message = await cacheHandlers.get("messages", payload.message_id); + const payload = data.d as MessageReactionAdd; + const message = await cacheHandlers.get("messages", payload.messageId); if (message) { const reactionExisted = message.reactions?.find( @@ -23,7 +22,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { else { const newReaction = { count: 1, - me: payload.user_id === botId, + me: payload.userId === botId, emoji: { ...payload.emoji, id: payload.emoji.id || undefined }, }; message.reactions = message.reactions @@ -31,11 +30,11 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { : [newReaction]; } - await cacheHandlers.set("messages", payload.message_id, message); + await cacheHandlers.set("messages", payload.messageId, message); } - if (payload.member && payload.guild_id) { - const guild = await cacheHandlers.get("guilds", payload.guild_id); + if (payload.member && payload.guildId) { + const guild = await cacheHandlers.get("guilds", payload.guildId); if (guild) { const discordenoMember = await structures.createDiscordenoMember( payload.member, diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts index 7c8fbe21a..9d947f8e3 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE.ts @@ -2,16 +2,14 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { - DiscordMessageReactionRemove, MessageReactionRemove, } from "../../types/messages/message_reaction_remove.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleMessageReactionRemove( data: DiscordGatewayPayload, ) { - const payload = data.d as DiscordMessageReactionRemove; - const message = await cacheHandlers.get("messages", payload.message_id); + const payload = data.d as MessageReactionRemove; + const message = await cacheHandlers.get("messages", payload.messageId); if (message) { const reaction = message.reactions?.find((reaction) => @@ -27,12 +25,12 @@ export async function handleMessageReactionRemove( } if (!message.reactions?.length) message.reactions = undefined; - await cacheHandlers.set("messages", payload.message_id, message); + await cacheHandlers.set("messages", payload.messageId, message); } } eventHandlers.reactionRemove?.( - snakeKeysToCamelCase(payload), + payload, message, ); } diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts index c4d48dccb..328f7c369 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_ALL.ts @@ -2,25 +2,23 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { - DiscordMessageReactionRemoveAll, MessageReactionRemoveAll, } from "../../types/messages/message_reaction_remove_all.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleMessageReactionRemoveAll( data: DiscordGatewayPayload, ) { - const payload = data.d as DiscordMessageReactionRemoveAll; - const message = await cacheHandlers.get("messages", payload.message_id); + const payload = data.d as MessageReactionRemoveAll; + const message = await cacheHandlers.get("messages", payload.messageId); if (message?.reactions) { message.reactions = undefined; - await cacheHandlers.set("messages", payload.message_id, message); + await cacheHandlers.set("messages", payload.messageId, message); } eventHandlers.reactionRemoveAll?.( - snakeKeysToCamelCase(payload), + payload, message, ); } diff --git a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts index e7e8aa90e..34e42b0ca 100644 --- a/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts +++ b/src/handlers/messages/MESSAGE_REACTION_REMOVE_EMOJI.ts @@ -1,13 +1,13 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordMessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts"; +import { MessageReactionRemoveEmoji } from "../../types/messages/message_reaction_remove_emoji.ts"; export async function handleMessageReactionRemoveEmoji( data: DiscordGatewayPayload, ) { - const payload = data.d as DiscordMessageReactionRemoveEmoji; - const message = await cacheHandlers.get("messages", payload.message_id); + const payload = data.d as MessageReactionRemoveEmoji; + const message = await cacheHandlers.get("messages", payload.messageId); if (message?.reactions) { message.reactions = message.reactions.filter( @@ -21,13 +21,13 @@ export async function handleMessageReactionRemoveEmoji( if (!message.reactions.length) message.reactions = undefined; - await cacheHandlers.set("messages", payload.message_id, message); + await cacheHandlers.set("messages", payload.messageId, message); } eventHandlers.reactionRemoveEmoji?.( payload.emoji, - payload.message_id, - payload.channel_id, - payload.guild_id, + payload.messageId, + payload.channelId, + payload.guildId, ); } diff --git a/src/handlers/messages/MESSAGE_UPDATE.ts b/src/handlers/messages/MESSAGE_UPDATE.ts index 9494cc7c5..390746e04 100644 --- a/src/handlers/messages/MESSAGE_UPDATE.ts +++ b/src/handlers/messages/MESSAGE_UPDATE.ts @@ -2,11 +2,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; export async function handleMessageUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordMessage; - const channel = await cacheHandlers.get("channels", payload.channel_id); + const payload = data.d as Message; + const channel = await cacheHandlers.get("channels", payload.channelId); if (!channel) return; const oldMessage = await cacheHandlers.get("messages", payload.id); @@ -14,7 +14,7 @@ export async function handleMessageUpdate(data: DiscordGatewayPayload) { // Messages with embeds can trigger update but they wont have edited_timestamp if ( - !payload.edited_timestamp || + !payload.editedTimestamp || (oldMessage.content === payload.content) ) { return; diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index 38601b858..1e8d94657 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -1,16 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { - DiscordPresenceUpdate, - PresenceUpdate, -} from "../../types/misc/presence_update.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { PresenceUpdate } from "../../types/misc/presence_update.ts"; export async function handlePresenceUpdate(data: DiscordGatewayPayload) { - const payload = snakeKeysToCamelCase( - data.d as DiscordPresenceUpdate, - ); + const payload = data.d as PresenceUpdate; + const oldPresence = await cacheHandlers.get("presences", payload.user.id); await cacheHandlers.set("presences", payload.user.id, payload); diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index 85bc3dbe9..204ed07f2 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -3,9 +3,8 @@ import { cache, cacheHandlers } from "../../cache.ts"; import { initialMemberLoadQueue } from "../../structures/guild.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordReady } from "../../types/gateway/ready.ts"; -import { DiscordGuildMemberWithUser } from "../../types/mod.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { Ready } from "../../types/gateway/ready.ts"; +import { GuildMemberWithUser } from "../../types/mod.ts"; import { ws } from "../../ws/ws.ts"; export function handleReady( @@ -15,7 +14,7 @@ export function handleReady( // The bot has already started, the last shard is resumed, however. if (cache.isReady) return; - const payload = data.d as DiscordReady; + const payload = data.d as Ready; setBotId(payload.user.id); setApplicationId(payload.application.id); @@ -44,7 +43,7 @@ export function handleReady( // Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event /** This function checks if the shard is fully loaded */ -async function checkReady(payload: DiscordReady, shardId: number, now: number) { +async function checkReady(payload: Ready, shardId: number, now: number) { const shard = ws.shards.get(shardId); if (!shard) return; @@ -100,7 +99,7 @@ async function loaded(shardId: number) { await Promise.allSettled( members.map(async (member) => { const discordenoMember = await structures.createDiscordenoMember( - camelKeysToSnakeCase(member), + member as GuildMemberWithUser, guildId, ); diff --git a/src/handlers/misc/TYPING_START.ts b/src/handlers/misc/TYPING_START.ts index 61a369d23..1cfde4296 100644 --- a/src/handlers/misc/TYPING_START.ts +++ b/src/handlers/misc/TYPING_START.ts @@ -1,13 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { - DiscordTypingStart, - TypingStart, -} from "../../types/misc/typing_start.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { TypingStart } from "../../types/misc/typing_start.ts"; export function handleTypingStart(data: DiscordGatewayPayload) { eventHandlers.typingStart?.( - snakeKeysToCamelCase(data.d as DiscordTypingStart), + data.d as TypingStart, ); } diff --git a/src/handlers/misc/USER_UPDATE.ts b/src/handlers/misc/USER_UPDATE.ts index 76d2eade2..5ed05a74b 100644 --- a/src/handlers/misc/USER_UPDATE.ts +++ b/src/handlers/misc/USER_UPDATE.ts @@ -1,11 +1,10 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordUser, User } from "../../types/users/user.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { User } from "../../types/users/user.ts"; export async function handleUserUpdate(data: DiscordGatewayPayload) { - const userData = camelKeysToSnakeCase(data.d as DiscordUser) as User; + const userData = data.d as User; const member = await cacheHandlers.get("members", userData.id); if (!member) return; diff --git a/src/handlers/roles/GUILD_ROLE_CREATE.ts b/src/handlers/roles/GUILD_ROLE_CREATE.ts index e0c57eada..8798e530f 100644 --- a/src/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/src/handlers/roles/GUILD_ROLE_CREATE.ts @@ -2,16 +2,16 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildRoleCreate } from "../../types/mod.ts"; +import { GuildRoleCreate } from "../../types/mod.ts"; export async function handleGuildRoleCreate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildRoleCreate; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildRoleCreate; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const role = await structures.createDiscordenoRole(payload); guild.roles = guild.roles.set(payload.role.id, role); - await cacheHandlers.set("guilds", payload.guild_id, guild); + await cacheHandlers.set("guilds", payload.guildId, guild); eventHandlers.roleCreate?.(guild, role); } diff --git a/src/handlers/roles/GUILD_ROLE_DELETE.ts b/src/handlers/roles/GUILD_ROLE_DELETE.ts index ca22ac66f..ade6eff2a 100644 --- a/src/handlers/roles/GUILD_ROLE_DELETE.ts +++ b/src/handlers/roles/GUILD_ROLE_DELETE.ts @@ -1,15 +1,15 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildRoleDelete } from "../../types/guilds/guild_role_delete.ts"; +import { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts"; export async function handleGuildRoleDelete(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildRoleDelete; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildRoleDelete; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; - const cachedRole = guild.roles.get(payload.role_id)!; - guild.roles.delete(payload.role_id); + const cachedRole = guild.roles.get(payload.roleId)!; + guild.roles.delete(payload.roleId); if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole); @@ -28,9 +28,9 @@ export async function handleGuildRoleDelete(data: DiscordGatewayPayload) { `2. Running forEach loop in CHANNEL_DELTE file.`, ); // Member does not have this role - if (!g.roles.includes(payload.role_id)) return; + if (!g.roles.includes(payload.roleId)) return; // Remove this role from the members cache - g.roles = g.roles.filter((id) => id !== payload.role_id); + g.roles = g.roles.filter((id) => id !== payload.roleId); cacheHandlers.set("members", member.id, member); }); }); diff --git a/src/handlers/roles/GUILD_ROLE_UPDATE.ts b/src/handlers/roles/GUILD_ROLE_UPDATE.ts index 263ee3520..2ad390925 100644 --- a/src/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/src/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -2,11 +2,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildRoleUpdate } from "../../types/mod.ts"; +import { GuildRoleUpdate } from "../../types/mod.ts"; export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) { - const payload = data.d as DiscordGuildRoleUpdate; - const guild = await cacheHandlers.get("guilds", payload.guild_id); + const payload = data.d as GuildRoleUpdate; + const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; const cachedRole = guild.roles.get(payload.role.id); diff --git a/src/handlers/voice/VOICE_SERVER_UPDATE.ts b/src/handlers/voice/VOICE_SERVER_UPDATE.ts index ed6955c9f..9edb0052d 100644 --- a/src/handlers/voice/VOICE_SERVER_UPDATE.ts +++ b/src/handlers/voice/VOICE_SERVER_UPDATE.ts @@ -1,16 +1,10 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { - DiscordVoiceServerUpdate, - VoiceServerUpdate, -} from "../../types/voice/voice_server_update.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { VoiceServerUpdate } from "../../types/voice/voice_server_update.ts"; export async function handleVoiceServerUpdate(data: DiscordGatewayPayload) { - const payload = snakeKeysToCamelCase( - data.d as DiscordVoiceServerUpdate, - ); + const payload = data.d as VoiceServerUpdate; const guild = await cacheHandlers.get("guilds", payload.guildId); if (!guild) return; diff --git a/src/handlers/voice/VOICE_STATE_UPDATE.ts b/src/handlers/voice/VOICE_STATE_UPDATE.ts index c84f9c65f..e5915d28e 100644 --- a/src/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -2,15 +2,11 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordGuildMemberWithUser } from "../../types/mod.ts"; import { DiscordVoiceState, VoiceState, } from "../../types/voice/voice_state.ts"; -import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, -} from "../../util/utils.ts"; +import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { const payload = snakeKeysToCamelCase( @@ -23,7 +19,7 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { const member = payload.member ? await structures.createDiscordenoMember( - camelKeysToSnakeCase(payload), + payload.member, guild.id, ) : await cacheHandlers.get("members", payload.userId); diff --git a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts index 1f53d23cf..fef9ac28c 100644 --- a/src/handlers/webhooks/WEBHOOKS_UPDATE.ts +++ b/src/handlers/webhooks/WEBHOOKS_UPDATE.ts @@ -1,11 +1,11 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { DiscordWebhookUpdate } from "../../types/webhooks/webhooks_update.ts"; +import { WebhookUpdate } from "../../types/webhooks/webhooks_update.ts"; export function handleWebhooksUpdate(data: DiscordGatewayPayload) { - const options = data.d as DiscordWebhookUpdate; + const options = data.d as WebhookUpdate; eventHandlers.webhooksUpdate?.( - options.channel_id, - options.guild_id, + options.channelId, + options.guildId, ); } diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index da902252f..9d675ed60 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { CreateGuildChannel, @@ -38,7 +38,7 @@ export async function createChannel( // BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000 if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000; - const result = (await rest.runMethod( + const result = await rest.runMethod( "post", endpoints.GUILD_CHANNELS(guildId), { @@ -51,7 +51,7 @@ export async function createChannel( type: options?.type || DiscordChannelTypes.GUILD_TEXT, reason, }, - )) as DiscordChannel; + ); const discordenoChannel = await structures.createDiscordenoChannel(result); await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel); diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index cd384bbfa..d934c8944 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -23,11 +23,9 @@ export async function deleteChannel( throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED); } - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_BASE(channelId), { reason }, ); - - return result; } diff --git a/src/helpers/channels/delete_channel_overwrite.ts b/src/helpers/channels/delete_channel_overwrite.ts index da9f04a4f..ea92593cb 100644 --- a/src/helpers/channels/delete_channel_overwrite.ts +++ b/src/helpers/channels/delete_channel_overwrite.ts @@ -10,10 +10,8 @@ export async function deleteChannelOverwrite( ): Promise { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), ); - - return result; } diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index d6e06fda2..dfb064c7d 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -1,6 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; import { ModifyChannel } from "../../types/channels/modify_channel.ts"; +import { Channel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -58,7 +59,7 @@ export async function editChannel( }), }; - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.CHANNEL_BASE(channelId), { @@ -66,8 +67,6 @@ export async function editChannel( reason, }, ); - - return result; } interface EditChannelRequest { diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index e6caad9b0..17f271528 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -15,7 +15,7 @@ export async function editChannelOverwrite( ): Promise { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.CHANNEL_OVERWRITE(channelId, overwriteId), { @@ -24,6 +24,4 @@ export async function editChannelOverwrite( type: options.type, }, ); - - return result; } diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index b8c9e7e27..550bf9d0f 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordFollowedChannel } from "../../types/channels/followed_channel.ts"; +import { FollowedChannel } from "../../types/channels/followed_channel.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -10,10 +10,13 @@ export async function followChannel( ) { await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]); - const data = - (await rest.runMethod("post", endpoints.CHANNEL_FOLLOW(sourceChannelId), { + const data = await rest.runMethod( + "post", + endpoints.CHANNEL_FOLLOW(sourceChannelId), + { webhook_channel_id: targetChannelId, - })) as DiscordFollowedChannel; + }, + ); - return data.webhook_id; + return data.webhookId; } diff --git a/src/helpers/channels/get_channel.ts b/src/helpers/channels/get_channel.ts index e0023133a..9c27334aa 100644 --- a/src/helpers/channels/get_channel.ts +++ b/src/helpers/channels/get_channel.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetches a single channel object from the api. @@ -9,14 +9,14 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ export async function getChannel(channelId: string, addToCache = true) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_BASE(channelId), - )) as DiscordChannel; + ); const discordenoChannel = await structures.createDiscordenoChannel( result, - result.guild_id, + result.guildId, ); if (addToCache) { await cacheHandlers.set( diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index bdea2baf5..69fcc7825 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -1,23 +1,19 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordWebhook, Webhook } from "../../types/webhooks/webhook.ts"; +import { Webhook } from "../../types/webhooks/webhook.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */ export async function getChannelWebhooks(channelId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_WEBHOOKS(channelId), - )) as DiscordWebhook[]; + ); return new Collection( - result.map((webhook) => [ - webhook.id, - snakeKeysToCamelCase(webhook), - ]), + result.map((webhook) => [webhook.id, webhook]), ); } diff --git a/src/helpers/channels/get_channels.ts b/src/helpers/channels/get_channels.ts index df7543b7e..c0271fb41 100644 --- a/src/helpers/channels/get_channels.ts +++ b/src/helpers/channels/get_channels.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; @@ -10,10 +10,10 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** */ export async function getChannels(guildId: string, addToCache = true) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_CHANNELS(guildId), - )) as DiscordChannel[]; + ); return new Collection( ( diff --git a/src/helpers/channels/get_pins.ts b/src/helpers/channels/get_pins.ts index c09237216..18b878b03 100644 --- a/src/helpers/channels/get_pins.ts +++ b/src/helpers/channels/get_pins.ts @@ -1,14 +1,14 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Get pinned messages in this channel. */ export async function getPins(channelId: string) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_PINS(channelId), - )) as DiscordMessage[]; + ); return Promise.all( result.map((res) => structures.createDiscordenoMessage(res)), diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index c5cf0144b..013ad46e2 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -10,7 +10,7 @@ import { botHasChannelPermissions } from "../../util/permissions.ts"; * However, if a bot is responding to a command and expects the computation to take a few seconds, * this endpoint may be called to let the user know that the bot is processing their message. */ -export async function startTyping(channelId: string): Promise { +export async function startTyping(channelId: string) { const channel = await cacheHandlers.get("channels", channelId); // If the channel is cached, we can do extra checks/safety if (channel) { @@ -35,10 +35,8 @@ export async function startTyping(channelId: string): Promise { } } - const result = await rest.runMethod( + return await rest.runMethod( "post", endpoints.CHANNEL_TYPING(channelId), ); - - return result; } diff --git a/src/helpers/channels/swap_channels.ts b/src/helpers/channels/swap_channels.ts index 9c6801c36..c55b903d3 100644 --- a/src/helpers/channels/swap_channels.ts +++ b/src/helpers/channels/swap_channels.ts @@ -6,16 +6,14 @@ import { endpoints } from "../../util/constants.ts"; export async function swapChannels( guildId: string, channelPositions: ModifyGuildChannelPositions[], -): Promise { +) { if (channelPositions.length < 2) { throw "You must provide at least two channels to be swapped."; } - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.GUILD_CHANNELS(guildId), channelPositions, ); - - return result; } diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/commands/create_slash_command.ts index 8baa84490..2da719f56 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/commands/create_slash_command.ts @@ -1,6 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; import { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts"; +import { ApplicationCommand } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase, @@ -24,13 +25,11 @@ export async function createSlashCommand( ) { validateSlashCommands([options], true); - const result = await rest.runMethod( + return await rest.runMethod( "post", guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), camelKeysToSnakeCase(options), ); - - return result; } diff --git a/src/helpers/commands/delete_slash_command.ts b/src/helpers/commands/delete_slash_command.ts index 0b9580e15..9f4c889d7 100644 --- a/src/helpers/commands/delete_slash_command.ts +++ b/src/helpers/commands/delete_slash_command.ts @@ -6,13 +6,11 @@ import { endpoints } from "../../util/constants.ts"; export async function deleteSlashCommand( id: string, guildId?: string, -): Promise { - const result = await rest.runMethod( +) { + return await rest.runMethod( "delete", guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id) : endpoints.COMMANDS_ID(applicationId, id), ); - - return result; } diff --git a/src/helpers/commands/delete_slash_response.ts b/src/helpers/commands/delete_slash_response.ts index 14523c3a5..c0972f1cf 100644 --- a/src/helpers/commands/delete_slash_response.ts +++ b/src/helpers/commands/delete_slash_response.ts @@ -6,8 +6,8 @@ import { endpoints } from "../../util/constants.ts"; export async function deleteSlashResponse( token: string, messageId?: string, -): Promise { - const result = await rest.runMethod( +) { + return await rest.runMethod( "delete", messageId ? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID( @@ -17,6 +17,4 @@ export async function deleteSlashResponse( ) : endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token), ); - - return result; } diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/commands/edit_slash_response.ts index 099b61b30..2c458f047 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/commands/edit_slash_response.ts @@ -3,7 +3,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; @@ -69,10 +68,10 @@ export async function editSlashResponse( ); // If the original message was edited, this will not return a message - if (!options.messageId) return result; + if (!options.messageId) return result as undefined; const message = await structures.createDiscordenoMessage( - result as DiscordMessage, + result, ); return message; } diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/commands/get_slash_command.ts index 72c61b3f6..d207c577b 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/commands/get_slash_command.ts @@ -5,12 +5,10 @@ import { endpoints } from "../../util/constants.ts"; /** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ export async function getSlashCommand(commandId: string, guildId?: string) { - const result = await rest.runMethod( + return await rest.runMethod( "get", guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId) : endpoints.COMMANDS_ID(applicationId, commandId), ); - - return result as ApplicationCommand; } diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/commands/get_slash_commands.ts index 3337baf49..4b4de42d1 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/commands/get_slash_commands.ts @@ -6,12 +6,12 @@ import { endpoints } from "../../util/constants.ts"; /** Fetch all of the global commands for your application. */ export async function getSlashCommands(guildId?: string) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), - )) as ApplicationCommand[]; + ); return new Collection(result.map((command) => [command.name, command])); } diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/commands/send_interaction_response.ts index 775036da8..3bb2132cb 100644 --- a/src/helpers/commands/send_interaction_response.ts +++ b/src/helpers/commands/send_interaction_response.ts @@ -17,9 +17,13 @@ export async function sendInteractionResponse( ) { // If its already been executed, we need to send a followup response if (cache.executedSlashCommands.has(token)) { - return rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), { - ...options, - }); + return await rest.runMethod( + "post", + endpoints.WEBHOOK(applicationId, token), + { + ...options, + }, + ); } // Expire in 15 minutes @@ -45,11 +49,9 @@ export async function sendInteractionResponse( options.data = { ...options.data, allowedMentions: { parse: [] } }; } - const result = await rest.runMethod( + return await rest.runMethod( "post", endpoints.INTERACTION_ID_TOKEN(id, token), options, ); - - return result; } diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/commands/upsert_slash_command.ts index 66c064780..2fb71ae7c 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/commands/upsert_slash_command.ts @@ -1,6 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; +import { ApplicationCommand } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; @@ -14,13 +15,11 @@ export async function upsertSlashCommand( ) { validateSlashCommands([options]); - const result = await rest.runMethod( + return await rest.runMethod( "patch", guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId) : endpoints.COMMANDS_ID(applicationId, commandId), options, ); - - return result; } diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/commands/upsert_slash_commands.ts index ce0bdeee2..bf2b78343 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/commands/upsert_slash_commands.ts @@ -1,6 +1,7 @@ import { applicationId } from "../../bot.ts"; import { rest } from "../../rest/rest.ts"; import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; +import { ApplicationCommand } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { validateSlashCommands } from "../../util/utils.ts"; @@ -15,13 +16,11 @@ export async function upsertSlashCommands( ) { validateSlashCommands(options); - const result = await rest.runMethod( + return await rest.runMethod( "put", guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), options, ); - - return result; } diff --git a/src/helpers/discovery/add_discovery_subcategory.ts b/src/helpers/discovery/add_discovery_subcategory.ts index f57296503..93a124c91 100644 --- a/src/helpers/discovery/add_discovery_subcategory.ts +++ b/src/helpers/discovery/add_discovery_subcategory.ts @@ -1,11 +1,9 @@ import { rest } from "../../rest/rest.ts"; import { AddGuildDiscoverySubcategory, - DiscordAddGuildDiscoverySubcategory, } from "../../types/discovery/add_guild_discovery_subcategory.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ export async function addDiscoverySubcategory( @@ -14,10 +12,8 @@ export async function addDiscoverySubcategory( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod( + return await rest.runMethod( "post", endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index 8c8c16d1b..9976e04cd 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -1,15 +1,9 @@ import { rest } from "../../rest/rest.ts"; -import { - DiscordDiscoveryMetadata, - DiscoveryMetadata, -} from "../../types/discovery/discovery_metadata.ts"; +import { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, -} from "../../util/utils.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ export async function editDiscovery( @@ -18,11 +12,9 @@ export async function editDiscovery( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.DISCOVERY_MODIFY(guildId), camelKeysToSnakeCase(data), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/discovery/get_discovery_categories.ts b/src/helpers/discovery/get_discovery_categories.ts index 4c390a616..8ec9858f5 100644 --- a/src/helpers/discovery/get_discovery_categories.ts +++ b/src/helpers/discovery/get_discovery_categories.ts @@ -1,25 +1,18 @@ import { rest } from "../../rest/rest.ts"; -import { - DiscordDiscoveryCategory, - DiscoveryCategory, -} from "../../types/discovery/discovery_category.ts"; +import { DiscoveryCategory } from "../../types/discovery/discovery_category.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns an array of discovery category objects that can be used when editing guilds */ export async function getDiscoveryCategories() { - const result = await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.DISCOVERY_CATEGORIES, ); return new Collection( result.map( - (category) => [ - category.id, - snakeKeysToCamelCase(category), - ], + (category) => [category.id, category], ), ); } diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index 5e4554ab8..2b55f7ec4 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -3,7 +3,7 @@ import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts"; import { Emoji } from "../../types/emojis/emoji.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts"; +import { urlToBase64 } from "../../util/utils.ts"; /** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ export async function createEmoji( @@ -18,11 +18,9 @@ export async function createEmoji( image = await urlToBase64(image); } - const result = await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), { + return await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), { ...options, name, image, }); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/emojis/delete_emoji.ts b/src/helpers/emojis/delete_emoji.ts index 97783b41c..40b43eaa3 100644 --- a/src/helpers/emojis/delete_emoji.ts +++ b/src/helpers/emojis/delete_emoji.ts @@ -7,14 +7,12 @@ export async function deleteEmoji( guildId: string, id: string, reason?: string, -): Promise { +) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_EMOJI(guildId, id), { reason }, ); - - return result; } diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index 803dc8ea5..28ee8e15a 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts"; +import { Emoji } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -11,7 +12,7 @@ export async function editEmoji( ) { await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]); - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.GUILD_EMOJI(guildId, id), { @@ -19,6 +20,4 @@ export async function editEmoji( roles: options.roles, }, ); - - return result; } diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index c99baa1d0..09f2a3cdd 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -14,16 +14,16 @@ export async function getEmoji( emojiId: string, addToCache = true, ) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_EMOJI(guildId, emojiId), - )) as Emoji; + ); if (addToCache) { const guild = await cacheHandlers.get("guilds", guildId); if (!guild) throw new Error(Errors.GUILD_NOT_FOUND); guild.emojis.set(emojiId, result); - cacheHandlers.set( + await cacheHandlers.set( "guilds", guildId, guild, diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index 140244d0c..da1d8cfa1 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -12,8 +12,10 @@ import { endpoints } from "../../util/constants.ts"; * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis */ export async function getEmojis(guildId: string, addToCache = true) { - const result = - (await rest.runMethod("get", endpoints.GUILD_EMOJIS(guildId))) as Emoji[]; + const result = await rest.runMethod( + "get", + endpoints.GUILD_EMOJIS(guildId), + ); if (addToCache) { const guild = await cacheHandlers.get("guilds", guildId); @@ -27,7 +29,7 @@ export async function getEmojis(guildId: string, addToCache = true) { guild.emojis.set(emoji.id!, emoji); }); - cacheHandlers.set("guilds", guildId, guild); + await cacheHandlers.set("guilds", guildId, guild); } return new Collection(result.map((e) => [e.id!, e])); diff --git a/src/helpers/guilds/create_guild.ts b/src/helpers/guilds/create_guild.ts index f4a5678cd..40c28f3fa 100644 --- a/src/helpers/guilds/create_guild.ts +++ b/src/helpers/guilds/create_guild.ts @@ -3,17 +3,17 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuild } from "../../types/guilds/create_guild.ts"; -import { DiscordGuild } from "../../types/guilds/guild.ts"; +import { Guild } from "../../types/guilds/guild.ts"; import { endpoints } from "../../util/constants.ts"; import { getMember } from "../members/get_member.ts"; /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ export async function createGuild(options: CreateGuild) { - const result = (await rest.runMethod( + const result = await rest.runMethod( "post", endpoints.GUILDS, options, - )) as DiscordGuild; + ); const guild = await structures.createDiscordenoGuild(result, 0); // MANUALLY CACHE THE GUILD diff --git a/src/helpers/guilds/delete_server.ts b/src/helpers/guilds/delete_server.ts index 43a1085eb..8dcf42eaf 100644 --- a/src/helpers/guilds/delete_server.ts +++ b/src/helpers/guilds/delete_server.ts @@ -3,8 +3,9 @@ import { endpoints } from "../../util/constants.ts"; /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ -export async function deleteServer(guildId: string): Promise { - const result = await rest.runMethod("delete", endpoints.GUILDS_BASE(guildId)); - - return result; +export async function deleteServer(guildId: string) { + return await rest.runMethod( + "delete", + endpoints.GUILDS_BASE(guildId), + ); } diff --git a/src/helpers/guilds/edit_guild.ts b/src/helpers/guilds/edit_guild.ts index 77e9367ce..20df19c47 100644 --- a/src/helpers/guilds/edit_guild.ts +++ b/src/helpers/guilds/edit_guild.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGuild } from "../../types/guilds/guild.ts"; +import { Guild } from "../../types/guilds/guild.ts"; import { ModifyGuild } from "../../types/guilds/modify_guild.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -22,11 +22,12 @@ export async function editGuild(guildId: string, options: ModifyGuild) { options.splash = await urlToBase64(options.splash); } - const result = await rest.runMethod( + const result = await rest.runMethod( "patch", endpoints.GUILDS_BASE(guildId), options, - ) as DiscordGuild; + ); + // TODO: use ws.botGatewayData to calculate the shard ID return structures.createDiscordenoGuild(result, -1); } diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index 5ad2a95b6..ae2dae039 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -2,20 +2,15 @@ import { rest } from "../../rest/rest.ts"; import { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; import { WelcomeScreen } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; -import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, -} from "../../util/utils.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; export async function editWelcomeScreen( guildId: string, options: ModifyGuildWelcomeScreen, ) { - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.GUILD_WELCOME_SCREEN(guildId), camelKeysToSnakeCase(options), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 8d0e0cf93..9259cf32d 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -2,7 +2,6 @@ import { rest } from "../../rest/rest.ts"; import { GuildWidget } from "../../types/guilds/guild_widget.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */ export async function editWidget( @@ -12,7 +11,7 @@ export async function editWidget( ) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod( + return await rest.runMethod( "patch", endpoints.GUILD_WIDGET(guildId), { @@ -20,6 +19,4 @@ export async function editWidget( channel_id: channelId, }, ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index 795e4bd7c..95b5b3aae 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -3,10 +3,7 @@ import { AuditLog } from "../../types/audit_log/audit_log.ts"; import { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, -} from "../../util/utils.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs( @@ -15,7 +12,7 @@ export async function getAuditLogs( ) { await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]); - const result = await rest.runMethod( + return await rest.runMethod( "get", endpoints.GUILD_AUDIT_LOGS(guildId), camelKeysToSnakeCase({ @@ -25,6 +22,4 @@ export async function getAuditLogs( : 50, }), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/guilds/get_available_voice_regions.ts b/src/helpers/guilds/get_available_voice_regions.ts index 944973477..5570e4916 100644 --- a/src/helpers/guilds/get_available_voice_regions.ts +++ b/src/helpers/guilds/get_available_voice_regions.ts @@ -4,7 +4,5 @@ import { endpoints } from "../../util/constants.ts"; /** Returns an array of voice regions that can be used when creating servers. */ export async function getAvailableVoiceRegions() { - const result = await rest.runMethod("get", endpoints.VOICE_REGIONS); - - return result as VoiceRegion; + return await rest.runMethod("get", endpoints.VOICE_REGIONS); } diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index 7abe6d3b0..3fddcd1a8 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -2,16 +2,13 @@ import { rest } from "../../rest/rest.ts"; import { Ban } from "../../types/guilds/ban.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */ export async function getBan(guildId: string, memberId: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await rest.runMethod( + return await rest.runMethod( "get", endpoints.GUILD_BAN(guildId, memberId), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index 1fdef4fcd..c9497f8b4 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -1,20 +1,19 @@ import { rest } from "../../rest/rest.ts"; -import { Ban, DiscordBan } from "../../types/guilds/ban.ts"; +import { Ban } from "../../types/guilds/ban.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ export async function getBans(guildId: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const results = (await rest.runMethod( + const results = await rest.runMethod( "get", endpoints.GUILD_BANS(guildId), - )) as DiscordBan[]; + ); return new Collection( - results.map((res) => [res.user.id, snakeKeysToCamelCase(res)]), + results.map((res) => [res.user.id, res]), ); } diff --git a/src/helpers/guilds/get_guild.ts b/src/helpers/guilds/get_guild.ts index 5652b979b..6e9dd06d3 100644 --- a/src/helpers/guilds/get_guild.ts +++ b/src/helpers/guilds/get_guild.ts @@ -1,7 +1,9 @@ +import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; import { Guild } from "../../types/guilds/guild.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; +import { ws } from "../../ws/ws.ts"; /** * ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get() @@ -10,10 +12,29 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts"; * This function fetches a guild's data. This is not the same data as a GUILD_CREATE. * So it does not cache the guild, you must do it manually. * */ -export async function getGuild(guildId: string, counts = true) { - const result = await rest.runMethod("get", endpoints.GUILDS_BASE(guildId), { - with_counts: counts, - }); +export async function getGuild( + guildId: string, + options: { counts?: boolean; addToCache?: boolean } = { + counts: true, + addToCache: true, + }, +) { + const result = await rest.runMethod( + "get", + endpoints.GUILDS_BASE(guildId), + { + with_counts: options.counts, + }, + ); - return snakeKeysToCamelCase(result); + const structure = await structures.createDiscordenoGuild( + result, + Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)), + ); + + if (options.addToCache) { + await cacheHandlers.set("guilds", guildId, structure); + } + + return structure; } diff --git a/src/helpers/guilds/get_guild_preview.ts b/src/helpers/guilds/get_guild_preview.ts index 274f20a28..40873cf0f 100644 --- a/src/helpers/guilds/get_guild_preview.ts +++ b/src/helpers/guilds/get_guild_preview.ts @@ -1,11 +1,11 @@ import { rest } from "../../rest/rest.ts"; import { GuildPreview } from "../../types/guilds/guild_preview.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ export async function getGuildPreview(guildId: string) { - const result = await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId)); - - return snakeKeysToCamelCase(result); + return await rest.runMethod( + "get", + endpoints.GUILD_PREVIEW(guildId), + ); } diff --git a/src/helpers/guilds/get_vainty_url.ts b/src/helpers/guilds/get_vainty_url.ts index 999c34884..0dee86af7 100644 --- a/src/helpers/guilds/get_vainty_url.ts +++ b/src/helpers/guilds/get_vainty_url.ts @@ -1,18 +1,15 @@ import { rest } from "../../rest/rest.ts"; import { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */ export async function getVanityURL(guildId: string) { - const result = await rest.runMethod( - "get", - endpoints.GUILD_VANITY_URL(guildId), - ); - - return snakeKeysToCamelCase< + return await rest.runMethod< (Partial & Pick) | { code: null; } - >(result); + >( + "get", + endpoints.GUILD_VANITY_URL(guildId), + ); } diff --git a/src/helpers/guilds/get_voice_regions.ts b/src/helpers/guilds/get_voice_regions.ts index 166c7fa2a..6ed926e52 100644 --- a/src/helpers/guilds/get_voice_regions.ts +++ b/src/helpers/guilds/get_voice_regions.ts @@ -1,22 +1,16 @@ import { rest } from "../../rest/rest.ts"; -import { - DiscordVoiceRegion, - VoiceRegion, -} from "../../types/voice/voice_region.ts"; +import { VoiceRegion } from "../../types/voice/voice_region.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ export async function getVoiceRegions(guildId: string) { - const result = await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_REGIONS(guildId), - ) as DiscordVoiceRegion[]; - - const convertedRegions = snakeKeysToCamelCase(result); + ); return new Collection( - convertedRegions.map((region) => [region.id, region]), + result.map((region) => [region.id, region]), ); } diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts index 4163c4f71..36950e3eb 100644 --- a/src/helpers/guilds/get_welcome_screen.ts +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -1,13 +1,10 @@ import { rest } from "../../rest/rest.ts"; import { WelcomeScreen } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function getWelcomeScreen(guildId: string) { - const result = await rest.runMethod( + return await rest.runMethod( "get", endpoints.GUILD_WELCOME_SCREEN(guildId), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index f44197d37..c685b8088 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -11,5 +11,6 @@ export async function getWidget(guildId: string, options?: { force: boolean }) { if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); } - return rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); + // TODO: add return type + return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); } diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index 8d28e8c9c..960fb83ec 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -7,7 +7,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getWidgetSettings(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod("get", endpoints.GUILD_WIDGET(guildId)); - - return result as GuildWidget; + return await rest.runMethod( + "get", + endpoints.GUILD_WIDGET(guildId), + ); } diff --git a/src/helpers/guilds/leave_guild.ts b/src/helpers/guilds/leave_guild.ts index 805b56885..9552ffe1a 100644 --- a/src/helpers/guilds/leave_guild.ts +++ b/src/helpers/guilds/leave_guild.ts @@ -2,8 +2,9 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; /** Leave a guild */ -export async function leaveGuild(guildId: string): Promise { - const result = await rest.runMethod("delete", endpoints.GUILD_LEAVE(guildId)); - - return result; +export async function leaveGuild(guildId: string) { + return await rest.runMethod( + "delete", + endpoints.GUILD_LEAVE(guildId), + ); } diff --git a/src/helpers/integrations/delete_integration.ts b/src/helpers/integrations/delete_integration.ts index 375672b9e..cd92ab5e1 100644 --- a/src/helpers/integrations/delete_integration.ts +++ b/src/helpers/integrations/delete_integration.ts @@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function deleteIntegration(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_INTEGRATION(guildId, id), ); - - return result; } diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 888dd8f96..f8c54d80d 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -1,4 +1,5 @@ import { rest } from "../../rest/rest.ts"; +import { Integration } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; @@ -6,10 +7,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function getIntegrations(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = await rest.runMethod( + return await rest.runMethod( "get", endpoints.GUILD_INTEGRATIONS(guildId), ); - - return result; } diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 09e13633d..0c7af679f 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; +import { Invite } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -12,11 +13,9 @@ export async function createInvite( // TODO: add proper options validation - const result = await rest.runMethod( + return await rest.runMethod( "post", endpoints.CHANNEL_INVITES(channelId), options, ); - - return result; } diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index a0e9cead8..0891c89ed 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -1,13 +1,12 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; -import { DiscordInvite, Invite } from "../../types/invites/invite.ts"; +import { Invite } from "../../types/invites/invite.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions, requireBotGuildPermissions, } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ export async function deleteInvite(channelId: string, inviteCode: string) { @@ -23,10 +22,8 @@ export async function deleteInvite(channelId: string, inviteCode: string) { await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]); } - const result: DiscordInvite = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.INVITE(inviteCode), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index f1a489693..4c9ce95c6 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -1,20 +1,19 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordInvite, Invite } from "../../types/invites/invite.ts"; +import { Invite } from "../../types/invites/invite.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Gets the invites for this channel. Requires MANAGE_CHANNEL */ export async function getChannelInvites(channelId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]); - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_INVITES(channelId), - )) as DiscordInvite[]; + ); return new Collection( - result.map((invite) => [invite.code, snakeKeysToCamelCase(invite)]), + result.map((invite) => [invite.code, invite]), ); } diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 43f2cb35e..de91249fe 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,14 +1,11 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordInvite, Invite } from "../../types/invites/invite.ts"; +import { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ export async function getInvite(inviteCode: string) { - const result: DiscordInvite = await rest.runMethod( + return await rest.runMethod( "get", endpoints.INVITE(inviteCode), ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index 778a243d6..c4a72e7d6 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -1,20 +1,19 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordInvite, Invite } from "../../types/invites/invite.ts"; +import { Invite } from "../../types/invites/invite.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ export async function getInvites(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_INVITES(guildId), - )) as DiscordInvite[]; + ); return new Collection( - result.map((invite) => [invite.code, snakeKeysToCamelCase(invite)]), + result.map((invite) => [invite.code, invite]), ); } diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index cb01fa8c9..c1257cf08 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -1,5 +1,5 @@ -import { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts"; import { rest } from "../../rest/rest.ts"; +import { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; @@ -12,13 +12,11 @@ export async function ban( ) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.GUILD_BAN(guildId, id), camelKeysToSnakeCase(options), ); - - return result; } // aliases diff --git a/src/helpers/members/edit_bot_nickname.ts b/src/helpers/members/edit_bot_nickname.ts index 5b182cfcd..f9b41bb3c 100644 --- a/src/helpers/members/edit_bot_nickname.ts +++ b/src/helpers/members/edit_bot_nickname.ts @@ -9,9 +9,13 @@ export async function editBotNickname( ) { await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]); - const response = await rest.runMethod("patch", endpoints.USER_NICK(guildId), { - nick: nickname, - }) as { nick: string }; + const response = await rest.runMethod<{ nick: string }>( + "patch", + endpoints.USER_NICK(guildId), + { + nick: nickname, + }, + ); return response.nick; } diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/members/edit_bot_profile.ts index 062d0433f..2e4fd6c7c 100644 --- a/src/helpers/members/edit_bot_profile.ts +++ b/src/helpers/members/edit_bot_profile.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/misc/errors.ts"; +import { User } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { urlToBase64 } from "../../util/utils.ts"; @@ -26,10 +27,9 @@ export async function editBotProfile(username?: string, botAvatarURL?: string) { } const avatar = botAvatarURL ? await urlToBase64(botAvatarURL) : undefined; - const result = await rest.runMethod("patch", endpoints.USER_BOT, { + + return await rest.runMethod("patch", endpoints.USER_BOT, { username: username?.trim(), avatar, }); - - return result; } diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index 562bc47ed..73b3e6b6c 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGuildMember } from "../../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { Errors } from "../../types/misc/errors.ts"; import { ModifyGuildMember } from "../../types/mod.ts"; import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; @@ -10,10 +10,7 @@ import { requireBotChannelPermissions, requireBotGuildPermissions, } from "../../util/permissions.ts"; -import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, -} from "../../util/utils.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Edit the member */ export async function editMember( @@ -72,13 +69,14 @@ export async function editMember( await requireBotGuildPermissions(guildId, [...requiredPerms]); - const result = await rest.runMethod( + const result = await rest.runMethod( "patch", endpoints.GUILD_MEMBER(guildId, memberId), camelKeysToSnakeCase(options), - ) as DiscordGuildMember; + ); + const member = await structures.createDiscordenoMember( - snakeKeysToCamelCase(result), + result, guildId, ); diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index c59716433..8605fbe4c 100644 --- a/src/helpers/members/get_member.ts +++ b/src/helpers/members/get_member.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a guild member object for the specified user. @@ -16,7 +16,7 @@ export async function getMember( const guild = await cacheHandlers.get("guilds", guildId); if (!guild && !options?.force) return; - const data: DiscordGuildMemberWithUser = (await rest.runMethod( + const data = (await rest.runMethod( "get", endpoints.GUILD_MEMBER(guildId, id), )); diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 396eb844f..e54173b7c 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -4,10 +4,7 @@ import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; -import { - DiscordGuildMember, - DiscordGuildMemberWithUser, -} from "../../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; import { Collection } from "../../util/collection.ts"; @@ -49,7 +46,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) { ); } - const result: DiscordGuildMember[] = (await rest.runMethod( + const result = (await rest.runMethod( "get", `${endpoints.GUILD_MEMBERS(guildId)}?limit=${ membersLeft > 1000 ? 1000 : membersLeft @@ -59,7 +56,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) { const discordenoMembers = await Promise.all( result.map(async (member) => { const discordenoMember = await structures.createDiscordenoMember( - member as DiscordGuildMemberWithUser, + member, guildId, ); @@ -71,7 +68,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) { return discordenoMember; }), - ) as DiscordenoMember[]; + ); if (!discordenoMembers.length) break; diff --git a/src/helpers/members/kick_member.ts b/src/helpers/members/kick_member.ts index 3adee00f6..8dbefc72e 100644 --- a/src/helpers/members/kick_member.ts +++ b/src/helpers/members/kick_member.ts @@ -20,13 +20,11 @@ export async function kick(guildId: string, memberId: string, reason?: string) { await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_MEMBER(guildId, memberId), { reason }, ); - - return result; } // aliases diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 3527136d5..ae8fc190c 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -19,11 +19,11 @@ export async function pruneMembers( await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]); - const result = await rest.runMethod( + const result = await rest.runMethod<{ pruned: number }>( "post", endpoints.GUILD_PRUNE(guildId), camelKeysToSnakeCase(options), ); - return result; + return result.pruned; } diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index f9fb1b76b..12202aba2 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Errors } from "../../types/misc/errors.ts"; import { Collection } from "../../util/collection.ts"; @@ -24,7 +24,7 @@ export async function searchMembers( } } - const result = await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_MEMBERS_SEARCH(guildId), { diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index 841e81856..ce01eaeda 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordChannel } from "../../types/channels/channel.ts"; +import { Channel } from "../../types/channels/channel.ts"; import { CreateMessage } from "../../types/messages/create_message.ts"; import { endpoints } from "../../util/constants.ts"; import { sendMessage } from "../messages/send_message.ts"; @@ -14,11 +14,15 @@ export async function sendDirectMessage( let dmChannel = await cacheHandlers.get("channels", memberId); if (!dmChannel) { // If not available in cache create a new one. - const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, { - recipient_id: memberId, - }); + const dmChannelData = await rest.runMethod( + "post", + endpoints.USER_DM, + { + recipient_id: memberId, + }, + ); const discordenoChannel = await structures.createDiscordenoChannel( - dmChannelData as DiscordChannel, + dmChannelData, ); // Recreate the channel and add it undert he users id await cacheHandlers.set("channels", memberId, discordenoChannel); @@ -26,5 +30,5 @@ export async function sendDirectMessage( } // If it does exist try sending a message to this user - return sendMessage(dmChannel.id, content); + return await sendMessage(dmChannel.id, content); } diff --git a/src/helpers/members/unban_member.ts b/src/helpers/members/unban_member.ts index db79fe2fd..a6c429fb8 100644 --- a/src/helpers/members/unban_member.ts +++ b/src/helpers/members/unban_member.ts @@ -6,12 +6,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function unban(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_BAN(guildId, id), ); - - return result; } // aliases diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index 1a5861abb..6c2fe402b 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -19,10 +19,8 @@ export async function addReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); - - return result; } diff --git a/src/helpers/messages/delete_message.ts b/src/helpers/messages/delete_message.ts index c053a1787..9b84ae248 100644 --- a/src/helpers/messages/delete_message.ts +++ b/src/helpers/messages/delete_message.ts @@ -20,11 +20,9 @@ export async function deleteMessage( if (delayMilliseconds) await delay(delayMilliseconds); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_MESSAGE(channelId, messageId), { reason }, ); - - return result; } diff --git a/src/helpers/messages/delete_messages.ts b/src/helpers/messages/delete_messages.ts index ce7055d1a..5ff274215 100644 --- a/src/helpers/messages/delete_messages.ts +++ b/src/helpers/messages/delete_messages.ts @@ -21,7 +21,7 @@ export async function deleteMessages( ); } - const result = await rest.runMethod( + return await rest.runMethod( "post", endpoints.CHANNEL_BULK_DELETE(channelId), { @@ -29,6 +29,4 @@ export async function deleteMessages( reason, }, ); - - return result; } diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index 220f605b8..860aa7616 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts"; import { DiscordenoMessage } from "../../structures/message.ts"; import { structures } from "../../structures/mod.ts"; import { EditMessage } from "../../types/messages/edit_message.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; @@ -28,11 +28,11 @@ export async function editMessage( throw new Error(Errors.MESSAGE_MAX_LENGTH); } - const result: DiscordMessage = await rest.runMethod( + const result = await rest.runMethod( "patch", endpoints.CHANNEL_MESSAGE(message.channelId, message.id), content, ); - return structures.createDiscordenoMessage(result); + return await structures.createDiscordenoMessage(result); } diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index 9c6c11a57..fc3f00cf6 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -14,10 +14,10 @@ export async function getMessage(channelId: string, id: string) { ]); } - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_MESSAGE(channelId, id), - )) as DiscordMessage; + ); - return structures.createDiscordenoMessage(result); + return await structures.createDiscordenoMessage(result); } diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index 959504e9a..1429b495b 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -6,7 +6,7 @@ import { GetMessagesBefore, GetMessagesLimit, } from "../../types/messages/get_messages.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -26,13 +26,13 @@ export async function getMessages( if (options?.limit && options.limit > 100) return; - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.CHANNEL_MESSAGES(channelId), options, - )) as DiscordMessage[]; + ); - return Promise.all( + return await Promise.all( result.map((res) => structures.createDiscordenoMessage(res)), ); } diff --git a/src/helpers/messages/get_reactions.ts b/src/helpers/messages/get_reactions.ts index 0506f5b48..bf10d2d6d 100644 --- a/src/helpers/messages/get_reactions.ts +++ b/src/helpers/messages/get_reactions.ts @@ -1,8 +1,8 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordUser } from "../../types/users/user.ts"; +import { GetReactions } from "../../types/messages/message_get_reactions.ts"; +import { User } from "../../types/users/user.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; -import { GetReactions } from "../../types/messages/message_get_reactions.ts"; /** Get a list of users that reacted with this emoji. */ export async function getReactions( @@ -11,11 +11,11 @@ export async function getReactions( reaction: string, options?: GetReactions, ) { - const users = (await rest.runMethod( + const users = await rest.runMethod( "get", endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), options, - )) as DiscordUser[]; + ); return new Collection(users.map((user) => [user.id, user])); } diff --git a/src/helpers/messages/pin_message.ts b/src/helpers/messages/pin_message.ts index 3e3001142..f96cac8f0 100644 --- a/src/helpers/messages/pin_message.ts +++ b/src/helpers/messages/pin_message.ts @@ -6,12 +6,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function pin(channelId: string, messageId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.CHANNEL_PIN(channelId, messageId), ); - - return result; } // aliases diff --git a/src/helpers/messages/publish_message.ts b/src/helpers/messages/publish_message.ts index 277f06a22..7d9d2ca17 100644 --- a/src/helpers/messages/publish_message.ts +++ b/src/helpers/messages/publish_message.ts @@ -1,14 +1,14 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Crosspost a message in a News Channel to following channels. */ export async function publishMessage(channelId: string, messageId: string) { - const data = (await rest.runMethod( + const data = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), - )) as DiscordMessage; + ); - return structures.createDiscordenoMessage(data); + return await structures.createDiscordenoMessage(data); } diff --git a/src/helpers/messages/remove_all_reactions.ts b/src/helpers/messages/remove_all_reactions.ts index c228ddfde..a97b81d9e 100644 --- a/src/helpers/messages/remove_all_reactions.ts +++ b/src/helpers/messages/remove_all_reactions.ts @@ -6,10 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts"; export async function removeAllReactions(channelId: string, messageId: string) { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId), ); - - return result; } diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index 087cf6659..b8bd2f707 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -13,10 +13,8 @@ export async function removeReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); - - return result; } diff --git a/src/helpers/messages/remove_reaction_emoji.ts b/src/helpers/messages/remove_reaction_emoji.ts index 0ed789a82..85a68a0be 100644 --- a/src/helpers/messages/remove_reaction_emoji.ts +++ b/src/helpers/messages/remove_reaction_emoji.ts @@ -16,10 +16,8 @@ export async function removeReactionEmoji( reaction = reaction.substring(3, reaction.length - 1); } - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), ); - - return result; } diff --git a/src/helpers/messages/remove_user_reaction.ts b/src/helpers/messages/remove_user_reaction.ts index 4ae4ffb2b..7f5b67dfd 100644 --- a/src/helpers/messages/remove_user_reaction.ts +++ b/src/helpers/messages/remove_user_reaction.ts @@ -17,7 +17,7 @@ export async function removeUserReaction( reaction = reaction.substring(3, reaction.length - 1); } - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_MESSAGE_REACTION_USER( channelId, @@ -26,6 +26,4 @@ export async function removeUserReaction( userId, ), ); - - return result; } diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 802e876c4..73d00246f 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -4,7 +4,7 @@ import { structures } from "../../structures/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { CreateMessage } from "../../types/messages/create_message.ts"; -import { DiscordMessage } from "../../types/messages/message.ts"; +import { DiscordMessage, Message } from "../../types/messages/message.ts"; import { Errors } from "../../types/misc/errors.ts"; import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; @@ -93,7 +93,7 @@ export async function sendMessage( } } - const result = (await rest.runMethod( + const result = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGES(channelId), camelKeysToSnakeCase({ @@ -107,7 +107,7 @@ export async function sendMessage( } : {}), }), - )) as DiscordMessage; + ); return structures.createDiscordenoMessage(result); } diff --git a/src/helpers/messages/unpin_message.ts b/src/helpers/messages/unpin_message.ts index c2a5630bf..1af948620 100644 --- a/src/helpers/messages/unpin_message.ts +++ b/src/helpers/messages/unpin_message.ts @@ -9,12 +9,10 @@ export async function unpin( ): Promise { await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.CHANNEL_PIN(channelId, messageId), ); - - return result; } // aliases diff --git a/src/helpers/misc/get_gateway_bot.ts b/src/helpers/misc/get_gateway_bot.ts index 10aa515c2..d765780be 100644 --- a/src/helpers/misc/get_gateway_bot.ts +++ b/src/helpers/misc/get_gateway_bot.ts @@ -1,14 +1,8 @@ import { rest } from "../../rest/rest.ts"; -import { - DiscordGetGatewayBot, - GetGatewayBot, -} from "../../types/gateway/get_gateway_bot.ts"; +import { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ export async function getGatewayBot() { - const result = await rest.runMethod("get", endpoints.GATEWAY_BOT); - - return snakeKeysToCamelCase(result as DiscordGetGatewayBot) as GetGatewayBot; + return await rest.runMethod("get", endpoints.GATEWAY_BOT); } diff --git a/src/helpers/misc/get_user.ts b/src/helpers/misc/get_user.ts index 254779a7f..9913acddc 100644 --- a/src/helpers/misc/get_user.ts +++ b/src/helpers/misc/get_user.ts @@ -1,12 +1,8 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordUser } from "../../types/users/user.ts"; import { User } from "../../types/users/user.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ export async function getUser(userId: string) { - const result: User = await rest.runMethod("get", endpoints.USER(userId)); - - return snakeKeysToCamelCase(result); + return await rest.runMethod("get", endpoints.USER(userId)); } diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index 6213823c3..6bf738ede 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -25,11 +25,9 @@ export async function addRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "put", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); - - return result; } diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index b8cdf1079..9f81b3911 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts"; -import { DiscordRole } from "../../types/permissions/role.ts"; +import { Role } from "../../types/permissions/role.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -17,7 +17,7 @@ export async function createRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result: DiscordRole = await rest.runMethod( + const result = await rest.runMethod( "post", endpoints.GUILD_ROLES(guildId), { @@ -29,10 +29,11 @@ export async function createRole( const role = await structures.createDiscordenoRole({ role: result, - guild_id: guildId, + guildId, }); const guild = await cacheHandlers.get("guilds", guildId); guild?.roles.set(role.id, role); + // TODO: ADD TO CACHE? return role; } diff --git a/src/helpers/roles/delete_role.ts b/src/helpers/roles/delete_role.ts index dd8c9300b..f9d134545 100644 --- a/src/helpers/roles/delete_role.ts +++ b/src/helpers/roles/delete_role.ts @@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts"; export async function deleteRole(guildId: string, id: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_ROLE(guildId, id), ); - - return result; } diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index 351b6314a..b3c6e8784 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; -import { CreateGuildRole } from "../../types/mod.ts"; +import { structures } from "../../structures/mod.ts"; +import { CreateGuildRole, Role } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -14,7 +15,7 @@ export async function editRole( ) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + const result = await rest.runMethod( "patch", endpoints.GUILD_ROLE(guildId, id), { @@ -25,5 +26,5 @@ export async function editRole( }, ); - return result; + return await structures.createDiscordenoRole({ role: result, guildId }); } diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index 29b08998b..ace6fe351 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -1,9 +1,8 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordRole, Role } from "../../types/permissions/role.ts"; +import { Role } from "../../types/permissions/role.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** Returns a list of role objects for the guild. * @@ -12,12 +11,14 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function getRoles(guildId: string) { await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = (await rest.runMethod( + const result = await rest.runMethod( "get", endpoints.GUILD_ROLES(guildId), - )) as DiscordRole[]; + ); + + // TODO: addToCache return new Collection( - result.map((role) => [role.id, snakeKeysToCamelCase(role)]), + result.map((role) => [role.id, role]), ); } diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index 786b0136e..5a98501ef 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -27,11 +27,9 @@ export async function removeRole( await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]); - const result = await rest.runMethod( + return await rest.runMethod( "delete", endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId), { reason }, ); - - return result; } diff --git a/src/helpers/templates/create_guild_from_template.ts b/src/helpers/templates/create_guild_from_template.ts index 92399604c..770f71299 100644 --- a/src/helpers/templates/create_guild_from_template.ts +++ b/src/helpers/templates/create_guild_from_template.ts @@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts"; import { Guild } from "../../types/guilds/guild.ts"; import { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts"; import { endpoints } from "../../util/constants.ts"; -import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts"; +import { urlToBase64 } from "../../util/utils.ts"; /** * Create a new guild based on a template @@ -23,11 +23,11 @@ export async function createGuildFromTemplate( data.icon = await urlToBase64(data.icon); } - const result = await rest.runMethod( + // TODO: discordeno guild? + + return await rest.runMethod( "post", endpoints.GUILD_TEMPLATE(templateCode), data, ); - - return snakeKeysToCamelCase(result); } diff --git a/src/helpers/templates/create_guild_template.ts b/src/helpers/templates/create_guild_template.ts index 6bc726bbe..a66d8f069 100644 --- a/src/helpers/templates/create_guild_template.ts +++ b/src/helpers/templates/create_guild_template.ts @@ -1,8 +1,7 @@ import { rest } from "../../rest/rest.ts"; -import { DiscordTemplate, Template } from "../../types/templates/template.ts"; +import { Template } from "../../types/templates/template.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; /** * Creates a template for the guild. @@ -24,11 +23,9 @@ export async function createGuildTemplate( throw new Error("The description can only be in between 0-120 characters."); } - const template = await rest.runMethod( + return await rest.runMethod