From 17115e7681ab674a27e0bb221106034f829118f0 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Thu, 21 Oct 2021 17:41:47 +0200 Subject: [PATCH] Gateway helpers --- src/handlers/channels/CHANNEL_CREATE.ts | 2 +- src/handlers/channels/CHANNEL_DELETE.ts | 2 +- src/handlers/channels/CHANNEL_PINS_UPDATE.ts | 2 +- src/handlers/channels/CHANNEL_UPDATE.ts | 2 +- .../channels/STAGE_INSTANCE_CREATE.ts | 2 +- .../channels/STAGE_INSTANCE_DELETE.ts | 2 +- .../channels/STAGE_INSTANCE_UPDATE.ts | 2 +- src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts | 2 +- src/handlers/guilds/GUILD_BAN_ADD.ts | 2 +- src/handlers/guilds/GUILD_BAN_REMOVE.ts | 2 +- src/handlers/guilds/GUILD_CREATE.ts | 2 +- src/handlers/guilds/GUILD_DELETE.ts | 2 +- .../guilds/GUILD_INTEGRATIONS_UPDATE.ts | 2 +- src/handlers/guilds/GUILD_LOADED_DD.ts | 2 +- src/handlers/guilds/GUILD_UPDATE.ts | 2 +- .../discovery/add_discovery_subcategory.ts | 2 +- src/helpers/discovery/edit_discovery.ts | 2 +- src/helpers/discovery/get_discovery.ts | 2 +- .../discovery/get_discovery_categories.ts | 2 +- .../discovery/remove_discovery_subcategory.ts | 2 +- src/helpers/discovery/valid_discovery_term.ts | 2 +- src/helpers/emojis/get_emoji.ts | 2 +- src/helpers/emojis/get_emojis.ts | 2 +- .../integrations/delete_integration.ts | 2 +- src/helpers/invites/create_invite.ts | 2 +- src/helpers/invites/delete_invite.ts | 2 +- src/helpers/invites/get_channel_invites.ts | 2 +- src/helpers/invites/get_invite.ts | 2 +- src/helpers/invites/get_invites.ts | 2 +- src/helpers/messages/get_message.ts | 2 +- src/helpers/messages/publish_message.ts | 2 +- src/helpers/messages/suppress_embeds.ts | 2 +- src/helpers/misc/edit_bot_profile.ts | 2 +- src/helpers/misc/edit_bot_status.ts | 2 +- src/helpers/misc/get_gateway_bot.ts | 2 +- src/helpers/misc/get_user.ts | 2 +- src/helpers/oauth/get_application.ts | 2 +- src/helpers/voice/connect_to_voice_channel.ts | 2 +- src/helpers/webhooks/create_webhook.ts | 5 +-- src/helpers/webhooks/delete_webhook.ts | 10 +++--- .../webhooks/delete_webhook_message.ts | 7 ++-- .../webhooks/delete_webhook_with_token.ts | 7 ++-- src/helpers/webhooks/edit_webhook.ts | 11 +++---- src/helpers/webhooks/edit_webhook_message.ts | 33 +++++++++++-------- .../webhooks/edit_webhook_with_token.ts | 11 ++++--- src/helpers/webhooks/get_webhook.ts | 8 ++--- src/helpers/webhooks/get_webhook_message.ts | 13 ++++---- .../webhooks/get_webhook_with_token.ts | 7 ++-- src/helpers/webhooks/get_webhooks.ts | 11 +++---- src/helpers/webhooks/send_webhook.ts | 32 +++++++++++------- 50 files changed, 121 insertions(+), 110 deletions(-) diff --git a/src/handlers/channels/CHANNEL_CREATE.ts b/src/handlers/channels/CHANNEL_CREATE.ts index eb1338979..c9a61eb7c 100644 --- a/src/handlers/channels/CHANNEL_CREATE.ts +++ b/src/handlers/channels/CHANNEL_CREATE.ts @@ -2,7 +2,7 @@ import type { Channel } from "../../types/channels/channel.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; export async function handleChannelCreate(bot: Bot, payload: SnakeCasedPropertiesDeep) { const channel = bot.transformers.channel(bot, { channel: payload.d as SnakeCasedPropertiesDeep }); diff --git a/src/handlers/channels/CHANNEL_DELETE.ts b/src/handlers/channels/CHANNEL_DELETE.ts index 627b989fd..5b289d45c 100644 --- a/src/handlers/channels/CHANNEL_DELETE.ts +++ b/src/handlers/channels/CHANNEL_DELETE.ts @@ -1,6 +1,6 @@ import type { Channel } from "../../types/channels/channel.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts index 261e1a4d5..121da7060 100644 --- a/src/handlers/channels/CHANNEL_PINS_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_PINS_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { ChannelPinsUpdate } from "../../types/channels/channel_pins_update.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/channels/CHANNEL_UPDATE.ts b/src/handlers/channels/CHANNEL_UPDATE.ts index 19fbb622f..f7e7af816 100644 --- a/src/handlers/channels/CHANNEL_UPDATE.ts +++ b/src/handlers/channels/CHANNEL_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { Channel } from "../../types/channels/channel.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/channels/STAGE_INSTANCE_CREATE.ts b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts index d65635df2..25e812560 100644 --- a/src/handlers/channels/STAGE_INSTANCE_CREATE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/channels/STAGE_INSTANCE_DELETE.ts b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts index fced34649..e40668923 100644 --- a/src/handlers/channels/STAGE_INSTANCE_DELETE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts index e65cfb498..5b497edea 100644 --- a/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts +++ b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { StageInstance } from "../../types/channels/stage_instance.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index 2ea8ef84e..fbc82f69c 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { GuildEmojisUpdate } from "../../types/emojis/guild_emojis_update.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_BAN_ADD.ts b/src/handlers/guilds/GUILD_BAN_ADD.ts index 6a171f5e9..5e0cda90c 100644 --- a/src/handlers/guilds/GUILD_BAN_ADD.ts +++ b/src/handlers/guilds/GUILD_BAN_ADD.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_BAN_REMOVE.ts b/src/handlers/guilds/GUILD_BAN_REMOVE.ts index cd2b41961..a3f9a9057 100644 --- a/src/handlers/guilds/GUILD_BAN_REMOVE.ts +++ b/src/handlers/guilds/GUILD_BAN_REMOVE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { GuildBanAddRemove } from "../../types/guilds/guild_ban_add_remove.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_CREATE.ts b/src/handlers/guilds/GUILD_CREATE.ts index b7e7b7c0d..de7deb3f4 100644 --- a/src/handlers/guilds/GUILD_CREATE.ts +++ b/src/handlers/guilds/GUILD_CREATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { Guild } from "../../types/guilds/guild.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_DELETE.ts b/src/handlers/guilds/GUILD_DELETE.ts index 2ded20125..d7c276360 100644 --- a/src/handlers/guilds/GUILD_DELETE.ts +++ b/src/handlers/guilds/GUILD_DELETE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { UnavailableGuild } from "../../types/guilds/unavailable_guild.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 827c629ed..e6a2610d7 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_LOADED_DD.ts b/src/handlers/guilds/GUILD_LOADED_DD.ts index d8a8c4562..a2c99dc73 100644 --- a/src/handlers/guilds/GUILD_LOADED_DD.ts +++ b/src/handlers/guilds/GUILD_LOADED_DD.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { Guild } from "../../types/guilds/guild.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/handlers/guilds/GUILD_UPDATE.ts b/src/handlers/guilds/GUILD_UPDATE.ts index 7d145ecab..028867c50 100644 --- a/src/handlers/guilds/GUILD_UPDATE.ts +++ b/src/handlers/guilds/GUILD_UPDATE.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { Guild } from "../../types/guilds/guild.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; diff --git a/src/helpers/discovery/add_discovery_subcategory.ts b/src/helpers/discovery/add_discovery_subcategory.ts index b442ac23d..f960f91c6 100644 --- a/src/helpers/discovery/add_discovery_subcategory.ts +++ b/src/helpers/discovery/add_discovery_subcategory.ts @@ -1,5 +1,5 @@ import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index c3cbdd477..f71e07df0 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -1,7 +1,7 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.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(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) { diff --git a/src/helpers/discovery/get_discovery.ts b/src/helpers/discovery/get_discovery.ts index 985d28882..746e815ee 100644 --- a/src/helpers/discovery/get_discovery.ts +++ b/src/helpers/discovery/get_discovery.ts @@ -1,6 +1,6 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */ export async function getDiscovery(bot: Bot, guildId: bigint) { diff --git a/src/helpers/discovery/get_discovery_categories.ts b/src/helpers/discovery/get_discovery_categories.ts index b6a991c96..d8af16d77 100644 --- a/src/helpers/discovery/get_discovery_categories.ts +++ b/src/helpers/discovery/get_discovery_categories.ts @@ -1,6 +1,6 @@ import type { DiscoveryCategory } from "../../types/discovery/discovery_category.ts"; import { Collection } from "../../util/collection.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Returns a Collection (mapped by Id of the discovery category object) of discovery category objects that can be used when editing guilds */ diff --git a/src/helpers/discovery/remove_discovery_subcategory.ts b/src/helpers/discovery/remove_discovery_subcategory.ts index 5abafb24d..38fee53f0 100644 --- a/src/helpers/discovery/remove_discovery_subcategory.ts +++ b/src/helpers/discovery/remove_discovery_subcategory.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */ export async function removeDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { diff --git a/src/helpers/discovery/valid_discovery_term.ts b/src/helpers/discovery/valid_discovery_term.ts index 7c8a278b4..883d274ac 100644 --- a/src/helpers/discovery/valid_discovery_term.ts +++ b/src/helpers/discovery/valid_discovery_term.ts @@ -1,5 +1,5 @@ import type { ValidateDiscoverySearchTerm } from "../../types/discovery/validate_discovery_search_term.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; export async function validDiscoveryTerm(bot: Bot, term: string) { diff --git a/src/helpers/emojis/get_emoji.ts b/src/helpers/emojis/get_emoji.ts index a99ec6baf..22f4b78b4 100644 --- a/src/helpers/emojis/get_emoji.ts +++ b/src/helpers/emojis/get_emoji.ts @@ -1,6 +1,6 @@ import type { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/discordeno/errors.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** * Returns an emoji for the given guild and emoji Id. diff --git a/src/helpers/emojis/get_emojis.ts b/src/helpers/emojis/get_emojis.ts index be3141caa..e0f2fe6cb 100644 --- a/src/helpers/emojis/get_emojis.ts +++ b/src/helpers/emojis/get_emojis.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { Emoji } from "../../types/emojis/emoji.ts"; import { Errors } from "../../types/discordeno/errors.ts"; import { Collection } from "../../util/collection.ts"; diff --git a/src/helpers/integrations/delete_integration.ts b/src/helpers/integrations/delete_integration.ts index 75c00cc1a..4cee41844 100644 --- a/src/helpers/integrations/delete_integration.ts +++ b/src/helpers/integrations/delete_integration.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */ export async function deleteIntegration(bot: Bot, guildId: bigint, id: bigint) { diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index a18b66f45..8523cf00c 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -1,7 +1,7 @@ import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { Errors } from "../../types/discordeno/errors.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */ diff --git a/src/helpers/invites/delete_invite.ts b/src/helpers/invites/delete_invite.ts index ced9fd715..48af20d99 100644 --- a/src/helpers/invites/delete_invite.ts +++ b/src/helpers/invites/delete_invite.ts @@ -1,5 +1,5 @@ import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */ diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index b889f78fb..6c56df480 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -1,6 +1,6 @@ import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { Collection } from "../../util/collection.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Gets the invites for this channel. Requires MANAGE_CHANNEL */ diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 51037c241..aead6734c 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,7 +1,7 @@ import { GetInvite } from "../../types/invites/get_invite.ts"; import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ export async function getInvite(bot: Bot, inviteCode: string, options?: GetInvite) { diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index e254bee54..71926a2c1 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -1,7 +1,7 @@ import type { InviteMetadata } from "../../types/invites/invite_metadata.ts"; import { Collection } from "../../util/collection.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ export async function getInvites(bot: Bot, guildId: bigint) { diff --git a/src/helpers/messages/get_message.ts b/src/helpers/messages/get_message.ts index b48833799..2267ef9f4 100644 --- a/src/helpers/messages/get_message.ts +++ b/src/helpers/messages/get_message.ts @@ -15,5 +15,5 @@ export async function getMessage(bot: Bot, channelId: bigint, id: bigint) { bot.constants.endpoints.CHANNEL_MESSAGE(channelId, id) ); - return await bot.transformers.message(bot, result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/messages/publish_message.ts b/src/helpers/messages/publish_message.ts index 903643a3e..6cbc735ed 100644 --- a/src/helpers/messages/publish_message.ts +++ b/src/helpers/messages/publish_message.ts @@ -10,5 +10,5 @@ export async function publishMessage(bot: Bot, channelId: bigint, messageId: big bot.constants.endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId) ); - return await bot.transformers.message(bot, data); + return bot.transformers.message(bot, data); } diff --git a/src/helpers/messages/suppress_embeds.ts b/src/helpers/messages/suppress_embeds.ts index e28ba0eb6..a89457222 100644 --- a/src/helpers/messages/suppress_embeds.ts +++ b/src/helpers/messages/suppress_embeds.ts @@ -16,5 +16,5 @@ export async function suppressEmbeds(bot: Bot, channelId: bigint, messageId: big { flags: 4 } ); - return await bot.transformers.message(bot, result); + return bot.transformers.message(bot, result); } diff --git a/src/helpers/misc/edit_bot_profile.ts b/src/helpers/misc/edit_bot_profile.ts index 66dac6510..297566354 100644 --- a/src/helpers/misc/edit_bot_profile.ts +++ b/src/helpers/misc/edit_bot_profile.ts @@ -1,6 +1,6 @@ import { Errors } from "../../types/discordeno/errors.ts"; import type { User } from "../../types/users/user.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Modifies the bot's username or avatar. diff --git a/src/helpers/misc/edit_bot_status.ts b/src/helpers/misc/edit_bot_status.ts index 7bba6658c..3908fefc1 100644 --- a/src/helpers/misc/edit_bot_status.ts +++ b/src/helpers/misc/edit_bot_status.ts @@ -1,4 +1,4 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts"; import type { StatusUpdate } from "../../types/gateway/status_update.ts"; diff --git a/src/helpers/misc/get_gateway_bot.ts b/src/helpers/misc/get_gateway_bot.ts index 6a798c8d1..1281d08e5 100644 --- a/src/helpers/misc/get_gateway_bot.ts +++ b/src/helpers/misc/get_gateway_bot.ts @@ -1,5 +1,5 @@ import type { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ diff --git a/src/helpers/misc/get_user.ts b/src/helpers/misc/get_user.ts index eb3de22f7..2208b7da6 100644 --- a/src/helpers/misc/get_user.ts +++ b/src/helpers/misc/get_user.ts @@ -1,5 +1,5 @@ import type { User } from "../../types/users/user.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */ diff --git a/src/helpers/oauth/get_application.ts b/src/helpers/oauth/get_application.ts index 38e48af6b..5a011d43f 100644 --- a/src/helpers/oauth/get_application.ts +++ b/src/helpers/oauth/get_application.ts @@ -1,5 +1,5 @@ import { Application } from "../../types/applications/application.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Get the applications info */ diff --git a/src/helpers/voice/connect_to_voice_channel.ts b/src/helpers/voice/connect_to_voice_channel.ts index 5d986ed94..079927e54 100644 --- a/src/helpers/voice/connect_to_voice_channel.ts +++ b/src/helpers/voice/connect_to_voice_channel.ts @@ -1,6 +1,6 @@ import type { UpdateVoiceState } from "../../types/voice/update_voice_state.ts"; import type { AtLeastOne } from "../../types/util.ts"; -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; /** Connect or join a voice channel inside a guild. By default, the "selfDeaf" option is true. Requires `CONNECT` and `VIEW_CHANNEL` permissions. */ export async function connectToVoiceChannel( diff --git a/src/helpers/webhooks/create_webhook.ts b/src/helpers/webhooks/create_webhook.ts index db413d602..e0daa22f1 100644 --- a/src/helpers/webhooks/create_webhook.ts +++ b/src/helpers/webhooks/create_webhook.ts @@ -1,6 +1,7 @@ -import { Bot } from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { CreateWebhook } from "../../types/webhooks/create_webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; +import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** * Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations: @@ -18,7 +19,7 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create throw new Error(bot.constants.Errors.INVALID_WEBHOOK_NAME); } - return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), { + return await bot.rest.runMethod>(bot.rest, "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), { ...options, avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, }); diff --git a/src/helpers/webhooks/delete_webhook.ts b/src/helpers/webhooks/delete_webhook.ts index 464f90504..274f66d63 100644 --- a/src/helpers/webhooks/delete_webhook.ts +++ b/src/helpers/webhooks/delete_webhook.ts @@ -1,10 +1,8 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../util/permissions.ts"; +import type {Bot} from "../../bot.ts"; /** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */ -export async function deleteWebhook(channelId: bigint, webhookId: bigint) { - await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); +export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint) { + await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]); - return await rest.runMethod("delete", endpoints.WEBHOOK_ID(webhookId)); + return await bot.rest.runMethod(bot.rset,"delete", bot.constants.endpoints.WEBHOOK_ID(webhookId)); } diff --git a/src/helpers/webhooks/delete_webhook_message.ts b/src/helpers/webhooks/delete_webhook_message.ts index e9bff59b7..99d0762cc 100644 --- a/src/helpers/webhooks/delete_webhook_message.ts +++ b/src/helpers/webhooks/delete_webhook_message.ts @@ -1,6 +1,5 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import type {Bot} from "../../bot.ts"; -export async function deleteWebhookMessage(webhookId: bigint, webhookToken: string, messageId: bigint) { - return await rest.runMethod("delete", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); +export async function deleteWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) { + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); } diff --git a/src/helpers/webhooks/delete_webhook_with_token.ts b/src/helpers/webhooks/delete_webhook_with_token.ts index 8a76eb41a..9806e3846 100644 --- a/src/helpers/webhooks/delete_webhook_with_token.ts +++ b/src/helpers/webhooks/delete_webhook_with_token.ts @@ -1,7 +1,6 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import type {Bot} from "../../bot.ts"; /** Delete a webhook permanently. Returns a undefined on success */ -export async function deleteWebhookWithToken(webhookId: bigint, webhookToken: string) { - return await rest.runMethod("delete", endpoints.WEBHOOK(webhookId, webhookToken)); +export async function deleteWebhookWithToken(bot: Bot, webhookId: bigint, webhookToken: string) { + return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)); } diff --git a/src/helpers/webhooks/edit_webhook.ts b/src/helpers/webhooks/edit_webhook.ts index 9c5b469fc..2e27c219a 100644 --- a/src/helpers/webhooks/edit_webhook.ts +++ b/src/helpers/webhooks/edit_webhook.ts @@ -1,14 +1,13 @@ -import { rest } from "../../rest/rest.ts"; import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../util/permissions.ts"; +import type {Bot} from "../../bot.ts"; +import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */ -export async function editWebhook(channelId: bigint, webhookId: bigint, options: ModifyWebhook) { - await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); +export async function editWebhook(bot: Bot, channelId: bigint, webhookId: bigint, options: ModifyWebhook) { + await bot.utils.requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]); - return await rest.runMethod("patch", endpoints.WEBHOOK_ID(webhookId), { + return await bot.rest.runMethod>(bot.rest,"patch", bot.constants.endpoints.WEBHOOK_ID(webhookId), { ...options, channel_id: options.channelId, }); diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index 7fed5041d..3dadb8ab4 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -1,19 +1,17 @@ -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import type { Message } from "../../types/messages/message.ts"; import type { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize, validateComponents } from "../../util/utils.ts"; +import type {Bot} from "../../bot.ts"; +import {DiscordAllowedMentionsTypes} from "../../types/messages/allowed_mentions_types.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; export async function editWebhookMessage( + bot: Bot, webhookId: bigint, webhookToken: string, options: EditWebhookMessage & { messageId?: bigint } ) { if (options.content && options.content.length > 2000) { - throw Error(Errors.MESSAGE_MAX_LENGTH); + throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); } if (options.embeds && options.embeds.length > 10) { @@ -43,16 +41,25 @@ export async function editWebhookMessage( } if (options.components?.length) { - validateComponents(options.components); + bot.utils.validateComponents(options.components); } - const result = await rest.runMethod( + const result = await bot.rest.runMethod>( + bot.rest, "patch", options.messageId - ? endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) - : endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken), - snakelize(options) + ? bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) + : bot.constants.endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken), + { + content: options.content, + embeds: options.embeds, + file: options.file, + allowedMentions: options.allowed_mentions, + attachments: options.attachments, + components: options.components, + message_id: options.messageId + } ); - return await structures.createDiscordenoMessage(result); + return bot.transformers.message(result); } diff --git a/src/helpers/webhooks/edit_webhook_with_token.ts b/src/helpers/webhooks/edit_webhook_with_token.ts index e7ef38f6a..8fb09bb3b 100644 --- a/src/helpers/webhooks/edit_webhook_with_token.ts +++ b/src/helpers/webhooks/edit_webhook_with_token.ts @@ -1,14 +1,17 @@ -import { rest } from "../../rest/rest.ts"; import type { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; +import type {Bot} from "../../bot.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Edit a webhook. Returns the updated webhook object on success. */ export async function editWebhookWithToken( + bot: Bot, webhookId: bigint, webhookToken: string, options: Omit ) { - return await rest.runMethod("patch", endpoints.WEBHOOK(webhookId, webhookToken), snakelize(options)); + return await bot.rest.runMethod>(bot.rest,"patch", bot.constants.endpoints.WEBHOOK(webhookId, webhookToken), { + name: options.name, + avatar: options.avatar + }); } diff --git a/src/helpers/webhooks/get_webhook.ts b/src/helpers/webhooks/get_webhook.ts index 86f40ab5e..b4dcce0f9 100644 --- a/src/helpers/webhooks/get_webhook.ts +++ b/src/helpers/webhooks/get_webhook.ts @@ -1,8 +1,8 @@ -import { rest } from "../../rest/rest.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; -import { endpoints } from "../../util/constants.ts"; +import type {Bot} from "../../bot.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Returns the new webhook object for the given id. */ -export async function getWebhook(webhookId: bigint) { - return await rest.runMethod("get", endpoints.WEBHOOK_ID(webhookId)); +export async function getWebhook(bot: Bot, webhookId: bigint) { + return await bot.rest.runMethod>(bot.rest, "get", bot.constants.endpoints.WEBHOOK_ID(webhookId)); } diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts index bbe5d8fab..750d46efa 100644 --- a/src/helpers/webhooks/get_webhook_message.ts +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -1,11 +1,10 @@ -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; import type { Message } from "../../types/messages/message.ts"; -import { endpoints } from "../../util/constants.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; +import type {Bot} from "../../bot.ts"; -/** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ -export async function getWebhookMessage(webhookId: bigint, webhookToken: string, messageId: bigint) { - const result = await rest.runMethod("get", endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); +/** Returns a previously-sent webhook message from the same token. Returns a message object on success. */ +export async function getWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) { + const result = await bot.rest.runMethod>(bot.rest,"get", bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)); - return await structures.createDiscordenoMessage(result); + return bot.transformers.message(result); } diff --git a/src/helpers/webhooks/get_webhook_with_token.ts b/src/helpers/webhooks/get_webhook_with_token.ts index 40db27786..5042ce2ae 100644 --- a/src/helpers/webhooks/get_webhook_with_token.ts +++ b/src/helpers/webhooks/get_webhook_with_token.ts @@ -1,8 +1,7 @@ -import { rest } from "../../rest/rest.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; -import { endpoints } from "../../util/constants.ts"; +import type {Bot} from "../../bot.ts"; /** Returns the new webhook object for the given id, this call does not require authentication and returns no user in the webhook object. */ -export async function getWebhookWithToken(webhookId: bigint, token: string) { - return await rest.runMethod("get", endpoints.WEBHOOK(webhookId, token)); +export async function getWebhookWithToken(bot: Bot, webhookId: bigint, token: string) { + return await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.WEBHOOK(webhookId, token)); } diff --git a/src/helpers/webhooks/get_webhooks.ts b/src/helpers/webhooks/get_webhooks.ts index 245905f88..e9594ec3a 100644 --- a/src/helpers/webhooks/get_webhooks.ts +++ b/src/helpers/webhooks/get_webhooks.ts @@ -1,14 +1,13 @@ -import { rest } from "../../rest/rest.ts"; +import type {Bot} from "../../bot.ts"; import type { Webhook } from "../../types/webhooks/webhook.ts"; import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotGuildPermissions } from "../../util/permissions.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */ -export async function getWebhooks(guildId: bigint) { - await requireBotGuildPermissions(guildId, ["MANAGE_WEBHOOKS"]); +export async function getWebhooks(bot: Bot, guildId: bigint) { + await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_WEBHOOKS"]); - const result = await rest.runMethod("get", endpoints.GUILD_WEBHOOKS(guildId)); + const result = await bot.rest.runMethod[]>(bot.rest,"get", bot.constants.endpoints.GUILD_WEBHOOKS(guildId)); return new Collection(result.map((webhook) => [webhook.id, webhook])); } diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index 6d208d725..2a3230f30 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -1,20 +1,17 @@ -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; +import type {Bot} from "../../bot.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; import type { ExecuteWebhook } from "../../types/webhooks/execute_webhook.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; +import {SnakeCasedPropertiesDeep} from "../../types/util.ts"; /** Send a webhook with webhook Id and webhook token */ -export async function sendWebhook(webhookId: bigint, webhookToken: string, options: ExecuteWebhook) { +export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: string, options: ExecuteWebhook) { if (!options.content && !options.file && !options.embeds) { - throw new Error(Errors.INVALID_WEBHOOK_OPTIONS); + throw new Error(bot.constants.Errors.INVALID_WEBHOOK_OPTIONS); } if (options.content && options.content.length > 2000) { - throw Error(Errors.MESSAGE_MAX_LENGTH); + throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); } options.embeds?.splice(10); @@ -41,14 +38,25 @@ export async function sendWebhook(webhookId: bigint, webhookToken: string, optio } } - const result = await rest.runMethod( + const result = await bot.rest.runMethod>( + bot.rest, "post", - `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${ + `${bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${ options.threadId ? `&thread_id=${options.threadId}` : "" }`, - snakelize(options) + { + wait: options.wait, + thread_id: options.threadId, + content: options.content, + username: options.username, + avatar_url: options.avatarUrl, + tts: options.tts, + file: options.file, + embeds: options.embeds, + allowed_mentions: options.allowedMentions, + } ); if (!options.wait) return; - return structures.createDiscordenoMessage(result); + return bot.transformers.message(result); }