From 7ff0d242ffe1f31c1e1402b20d923e192123a7c4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:06:32 +0200 Subject: [PATCH 1/4] hopefully the last dir change --- src/cache.ts | 2 +- .../commands/APPLICATION_COMMAND_CREATE.ts | 2 +- .../commands/APPLICATION_COMMAND_DELETE.ts | 2 +- .../commands/APPLICATION_COMMAND_UPDATE.ts | 2 +- .../guilds/GUILD_INTEGRATIONS_UPDATE.ts | 2 +- .../integrations/INTEGRATION_CREATE.ts | 2 +- .../integrations/INTEGRATION_DELETE.ts | 2 +- .../integrations/INTEGRATION_UPDATE.ts | 2 +- .../interactions/INTERACTION_CREATE.ts | 2 +- src/handlers/messages/MESSAGE_CREATE.ts | 2 +- src/handlers/messages/MESSAGE_REACTION_ADD.ts | 3 +- src/handlers/misc/PRESENCE_UPDATE.ts | 2 +- src/helpers/channels/create_channel.ts | 4 +- src/helpers/channels/edit_channel.ts | 4 +- .../channels/threads/get_archived_threads.ts | 4 +- src/helpers/channels/threads/start_thread.ts | 4 +- .../edit_slash_command_permissions.ts | 18 --- src/helpers/discovery/edit_discovery.ts | 4 +- src/helpers/guilds/edit_welcome_screen.ts | 4 +- src/helpers/guilds/get_audit_logs.ts | 4 +- src/helpers/guilds/get_prune_count.ts | 6 +- src/helpers/guilds/update_bot_voice_state.ts | 4 +- src/helpers/guilds/update_user_voice_state.ts | 4 +- src/helpers/integrations/get_integrations.ts | 2 +- .../batch_edit_slash_command_permissions.ts | 12 +- .../commands/create_slash_command.ts | 17 ++- .../commands/delete_slash_command.ts | 6 +- .../commands/delete_slash_response.ts | 6 +- .../edit_slash_command_permissions.ts | 18 +++ .../commands/edit_slash_response.ts | 14 +-- .../commands/get_slash_command.ts | 8 +- .../commands/get_slash_command_permission.ts | 8 +- .../commands/get_slash_command_permissions.ts | 8 +- .../commands/get_slash_commands.ts | 10 +- .../commands/upsert_slash_command.ts | 12 +- .../commands/upsert_slash_commands.ts | 12 +- .../get_original_interaction_response.ts | 0 .../send_interaction_response.ts | 0 src/helpers/invites/get_invite.ts | 4 +- src/helpers/members/ban_member.ts | 4 +- src/helpers/members/edit_member.ts | 8 +- src/helpers/members/fetch_members.ts | 4 +- src/helpers/members/get_member.ts | 2 +- src/helpers/members/get_members.ts | 6 +- src/helpers/members/prune_members.ts | 6 +- src/helpers/members/search_members.ts | 4 +- src/helpers/messages/send_message.ts | 6 +- .../{members => misc}/edit_bot_profile.ts | 0 src/helpers/mod.ts | 30 ++--- src/rest/run_method.ts | 4 +- src/structures/guild.ts | 6 +- src/structures/member.ts | 4 +- src/structures/message.ts | 2 +- src/structures/voice_state.ts | 2 +- src/types/{misc => activity}/activity.ts | 0 .../{misc => activity}/activity_assets.ts | 0 .../{misc => activity}/activity_button.ts | 0 .../{misc => activity}/activity_emoji.ts | 0 .../{misc => activity}/activity_flags.ts | 0 .../{misc => activity}/activity_party.ts | 0 .../{misc => activity}/activity_secrets.ts | 0 .../{misc => activity}/activity_timestamps.ts | 0 .../{misc => activity}/activity_types.ts | 0 src/types/{misc => activity}/client_status.ts | 0 .../{misc => activity}/presence_update.ts | 0 src/types/audit_log/audit_log.ts | 2 +- src/types/discordeno/create_slash_command.ts | 2 +- src/types/discordeno/eventHandlers.ts | 4 +- src/types/gateway/status_update.ts | 2 +- src/types/guilds/guild.ts | 4 +- .../guild_integrations_update.ts | 0 .../integration.ts | 0 .../integration_account.ts | 0 .../integration_application.ts | 0 .../integration_create_update.ts | 0 .../integration_delete.ts | 0 .../integration_expire_behaviors.ts | 0 .../{ => commands}/application_command.ts | 0 .../application_command_callback_data.ts | 4 +- ...pplication_command_create_update_delete.ts | 0 .../application_command_interaction_data.ts | 0 ...ication_command_interaction_data_option.ts | 0 ...ation_command_interaction_data_resolved.ts | 8 +- .../application_command_option.ts | 0 .../application_command_option_choice.ts | 0 .../application_command_option_types.ts | 0 .../application_command_permission_types.ts | 0 .../application_command_permissions.ts | 0 .../create_global_application_command.ts | 0 .../create_guild_application_command.ts | 0 .../edit_global_application_command.ts | 0 .../edit_guild_application_command.ts | 0 .../guild_application_command_permissions.ts | 0 src/types/interactions/interaction.ts | 4 +- .../interactions/interaction_guild_member.ts | 2 +- .../interactions/interaction_response.ts | 2 +- src/types/{guilds => members}/guild_member.ts | 0 src/types/members/guild_member_add.ts | 2 +- src/types/members/guild_members_chunk.ts | 4 +- .../{guilds => members}/list_guild_members.ts | 0 .../modify_current_user_nick.ts | 0 .../request_guild_members.ts | 0 src/types/messages/message.ts | 2 +- src/types/messages/message_reaction_add.ts | 2 +- src/types/misc/typing_start.ts | 2 +- src/types/mod.ts | 105 +++++++++++------- src/types/users/connection.ts | 2 +- src/types/voice/voice_state.ts | 2 +- src/util/cache_members.ts | 2 +- src/util/utils.ts | 26 ++--- src/ws/handle_on_message.ts | 4 +- src/ws/start_gateway.ts | 4 +- tests/util/utils.ts | 16 +-- 113 files changed, 267 insertions(+), 250 deletions(-) delete mode 100644 src/helpers/commands/edit_slash_command_permissions.ts rename src/helpers/{ => interactions}/commands/batch_edit_slash_command_permissions.ts (54%) rename src/helpers/{ => interactions}/commands/create_slash_command.ts (72%) rename src/helpers/{ => interactions}/commands/delete_slash_command.ts (66%) rename src/helpers/{ => interactions}/commands/delete_slash_response.ts (76%) create mode 100644 src/helpers/interactions/commands/edit_slash_command_permissions.ts rename src/helpers/{ => interactions}/commands/edit_slash_response.ts (80%) rename src/helpers/{ => interactions}/commands/get_slash_command.ts (61%) rename src/helpers/{ => interactions}/commands/get_slash_command_permission.ts (57%) rename src/helpers/{ => interactions}/commands/get_slash_command_permissions.ts (55%) rename src/helpers/{ => interactions}/commands/get_slash_commands.ts (55%) rename src/helpers/{ => interactions}/commands/upsert_slash_command.ts (52%) rename src/helpers/{ => interactions}/commands/upsert_slash_commands.ts (58%) rename src/helpers/{commands => interactions}/get_original_interaction_response.ts (100%) rename src/helpers/{commands => interactions}/send_interaction_response.ts (100%) rename src/helpers/{members => misc}/edit_bot_profile.ts (100%) rename src/types/{misc => activity}/activity.ts (100%) rename src/types/{misc => activity}/activity_assets.ts (100%) rename src/types/{misc => activity}/activity_button.ts (100%) rename src/types/{misc => activity}/activity_emoji.ts (100%) rename src/types/{misc => activity}/activity_flags.ts (100%) rename src/types/{misc => activity}/activity_party.ts (100%) rename src/types/{misc => activity}/activity_secrets.ts (100%) rename src/types/{misc => activity}/activity_timestamps.ts (100%) rename src/types/{misc => activity}/activity_types.ts (100%) rename src/types/{misc => activity}/client_status.ts (100%) rename src/types/{misc => activity}/presence_update.ts (100%) rename src/types/{integration => integrations}/guild_integrations_update.ts (100%) rename src/types/{integration => integrations}/integration.ts (100%) rename src/types/{integration => integrations}/integration_account.ts (100%) rename src/types/{integration => integrations}/integration_application.ts (100%) rename src/types/{integration => integrations}/integration_create_update.ts (100%) rename src/types/{integration => integrations}/integration_delete.ts (100%) rename src/types/{integration => integrations}/integration_expire_behaviors.ts (100%) rename src/types/interactions/{ => commands}/application_command.ts (100%) rename src/types/interactions/{ => commands}/application_command_callback_data.ts (80%) rename src/types/interactions/{ => commands}/application_command_create_update_delete.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data_option.ts (100%) rename src/types/interactions/{ => commands}/application_command_interaction_data_resolved.ts (68%) rename src/types/interactions/{ => commands}/application_command_option.ts (100%) rename src/types/interactions/{ => commands}/application_command_option_choice.ts (100%) rename src/types/interactions/{ => commands}/application_command_option_types.ts (100%) rename src/types/interactions/{ => commands}/application_command_permission_types.ts (100%) rename src/types/interactions/{ => commands}/application_command_permissions.ts (100%) rename src/types/interactions/{ => commands}/create_global_application_command.ts (100%) rename src/types/interactions/{ => commands}/create_guild_application_command.ts (100%) rename src/types/interactions/{ => commands}/edit_global_application_command.ts (100%) rename src/types/interactions/{ => commands}/edit_guild_application_command.ts (100%) rename src/types/interactions/{ => commands}/guild_application_command_permissions.ts (100%) rename src/types/{guilds => members}/guild_member.ts (100%) rename src/types/{guilds => members}/list_guild_members.ts (100%) rename src/types/{guilds => members}/modify_current_user_nick.ts (100%) rename src/types/{guilds => members}/request_guild_members.ts (100%) diff --git a/src/cache.ts b/src/cache.ts index 6da6e43ed..3abdab3c9 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -3,8 +3,8 @@ import type { DiscordenoChannel } from "./structures/channel.ts"; import type { DiscordenoGuild } from "./structures/guild.ts"; import type { DiscordenoMember } from "./structures/member.ts"; import type { DiscordenoMessage } from "./structures/message.ts"; +import type { PresenceUpdate } from "./types/activity/presence_update.ts"; import type { Emoji } from "./types/emojis/emoji.ts"; -import type { PresenceUpdate } from "./types/misc/presence_update.ts"; import { Collection } from "./util/collection.ts"; export const cache = { diff --git a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts index c52eddfa1..bcfa4270e 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandCreate( data: DiscordGatewayPayload, diff --git a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts index 674b23330..5a9fe3e23 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_DELETE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandDelete(data: DiscordGatewayPayload) { eventHandlers.applicationCommandDelete?.( diff --git a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts index b5ac20ee3..b1940c91c 100644 --- a/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts +++ b/src/handlers/commands/APPLICATION_COMMAND_UPDATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { ApplicationCommandCreateUpdateDelete, -} from "../../types/interactions/application_command_create_update_delete.ts"; +} from "../../types/interactions/commands/application_command_create_update_delete.ts"; export function handleApplicationCommandUpdate(data: DiscordGatewayPayload) { eventHandlers.applicationCommandUpdate?.( diff --git a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts index 136db1a4d..0175c6843 100644 --- a/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts +++ b/src/handlers/guilds/GUILD_INTEGRATIONS_UPDATE.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildIntegrationsUpdate } from "../../types/integration/guild_integrations_update.ts"; +import type { GuildIntegrationsUpdate } from "../../types/integrations/guild_integrations_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildIntegrationsUpdate( diff --git a/src/handlers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts index 147831a5a..7b6f31937 100644 --- a/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { IntegrationCreateUpdate, -} from "../../types/integration/integration_create_update.ts"; +} from "../../types/integrations/integration_create_update.ts"; export function handleIntegrationCreate( data: DiscordGatewayPayload, diff --git a/src/handlers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts index d7fcbe088..207bf339a 100644 --- a/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { IntegrationDelete } from "../../types/integration/integration_delete.ts"; +import type { IntegrationDelete } from "../../types/integrations/integration_delete.ts"; export function handleIntegrationDelete(data: DiscordGatewayPayload) { eventHandlers.integrationDelete?.( diff --git a/src/handlers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts index 4ce7fa940..d9953a982 100644 --- a/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import type { IntegrationCreateUpdate, -} from "../../types/integration/integration_create_update.ts"; +} from "../../types/integrations/integration_create_update.ts"; export function handleIntegrationUpdate(data: DiscordGatewayPayload) { eventHandlers.integrationUpdate?.( diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 6c5a03913..6ce6996ec 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -2,8 +2,8 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; import type { Interaction } from "../../types/interactions/interaction.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleInteractionCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/messages/MESSAGE_CREATE.ts b/src/handlers/messages/MESSAGE_CREATE.ts index 5492f8664..2f9dbfb8a 100644 --- a/src/handlers/messages/MESSAGE_CREATE.ts +++ b/src/handlers/messages/MESSAGE_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import type { Message } from "../../types/messages/message.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; diff --git a/src/handlers/messages/MESSAGE_REACTION_ADD.ts b/src/handlers/messages/MESSAGE_REACTION_ADD.ts index 1bd69cf8c..8dc959bae 100644 --- a/src/handlers/messages/MESSAGE_REACTION_ADD.ts +++ b/src/handlers/messages/MESSAGE_REACTION_ADD.ts @@ -6,7 +6,6 @@ import type { MessageReactionAdd, } from "../../types/messages/message_reaction_add.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; -import { snakeKeysToCamelCase } from "../../util/utils.ts"; export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { const payload = data.d as MessageReactionAdd; @@ -56,7 +55,7 @@ export async function handleMessageReactionAdd(data: DiscordGatewayPayload) { } eventHandlers.reactionAdd?.( - snakeKeysToCamelCase(payload), + payload, message, ); } diff --git a/src/handlers/misc/PRESENCE_UPDATE.ts b/src/handlers/misc/PRESENCE_UPDATE.ts index d1c2127c9..c54f2db1c 100644 --- a/src/handlers/misc/PRESENCE_UPDATE.ts +++ b/src/handlers/misc/PRESENCE_UPDATE.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; +import type { PresenceUpdate } from "../../types/activity/presence_update.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { PresenceUpdate } from "../../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handlePresenceUpdate(data: DiscordGatewayPayload) { diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index ec5288575..83aad09d5 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -12,7 +12,7 @@ import { calculateBits, requireOverwritePermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */ export async function createChannel( @@ -34,7 +34,7 @@ export async function createChannel( "post", endpoints.GUILD_CHANNELS(guildId), { - ...camelKeysToSnakeCase(options ?? {}), + ...snakelize(options ?? {}), permission_overwrites: options?.permissionOverwrites?.map((perm) => ({ ...perm, allow: calculateBits(perm.allow), diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index d22feab6e..b0c4247db 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -12,7 +12,7 @@ import { requireBotChannelPermissions, requireOverwritePermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase, hasOwnProperty } from "../../util/utils.ts"; +import { hasOwnProperty, snakelize } from "../../util/utils.ts"; //TODO: implement DM group channel edit //TODO(threads): check thread perms @@ -88,7 +88,7 @@ export async function editChannel( } const payload = { - ...camelKeysToSnakeCase>(options), + ...snakelize>(options), // deno-lint-ignore camelcase permission_overwrites: hasOwnProperty(options, "permissionOverwrites") diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index 4a4de2927..afff32710 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -1,7 +1,7 @@ import { rest } from "../../../rest/rest.ts"; import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_public_archived_threads.ts"; import { endpoints } from "../../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../../util/utils.ts"; +import { snakelize } from "../../../util/utils.ts"; export async function getArchivedThreads( channelId: bigint, @@ -19,6 +19,6 @@ export async function getArchivedThreads( : options?.type === "private" ? endpoints.THREAD_ARCHIVED_PRIVATE(channelId) : endpoints.THREAD_ARCHIVED_PUBLIC(channelId), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); } diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index 60f2fc372..0a6f90e2e 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -4,7 +4,7 @@ import { ChannelTypes } from "../../../types/channels/channel_types.ts"; import { StartThread } from "../../../types/channels/threads/start_thread.ts"; import { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../../util/utils.ts"; +import { snakelize } from "../../../util/utils.ts"; /** * Creates a new public thread from an existing message. Returns a channel on success, and a 400 BAD REQUEST on invalid parameters. Fires a Thread Create Gateway event. @@ -33,6 +33,6 @@ export async function startThread( options?.messageId ? endpoints.THREAD_START_PUBLIC(channelId, options.messageId) : endpoints.THREAD_START_PRIVATE(channelId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/edit_slash_command_permissions.ts b/src/helpers/commands/edit_slash_command_permissions.ts deleted file mode 100644 index bbaae3bc4..000000000 --- a/src/helpers/commands/edit_slash_command_permissions.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; - -/** Edits command permissions for a specific command for your application in a guild. */ -export async function editSlashCommandPermissions( - guildId: bigint, - commandId: bigint, - options: ApplicationCommandPermissions[], -) { - return await rest.runMethod( - "put", - endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), - { permissions: camelKeysToSnakeCase(options) }, - ); -} diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index 71f7e3ab5..e4b48f6f2 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -3,7 +3,7 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } 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( @@ -15,6 +15,6 @@ export async function editDiscovery( return await rest.runMethod( "patch", endpoints.DISCOVERY_MODIFY(guildId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts index 29114dea3..07034cef5 100644 --- a/src/helpers/guilds/edit_welcome_screen.ts +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; export async function editWelcomeScreen( guildId: bigint, @@ -11,6 +11,6 @@ export async function editWelcomeScreen( return await rest.runMethod( "patch", endpoints.GUILD_WELCOME_SCREEN(guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index a090fbf49..a82cce811 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -3,7 +3,7 @@ import type { AuditLog } from "../../types/audit_log/audit_log.ts"; import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs( @@ -15,7 +15,7 @@ export async function getAuditLogs( return await rest.runMethod( "get", endpoints.GUILD_AUDIT_LOGS(guildId), - camelKeysToSnakeCase({ + snakelize({ ...options, limit: options.limit && options.limit >= 1 && options.limit <= 100 ? options.limit diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index aaba70777..327516a5d 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; -import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */ export async function getPruneCount( @@ -20,7 +20,7 @@ export async function getPruneCount( const result = await rest.runMethod( "get", endpoints.GUILD_PRUNE(guildId), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); return result.pruned as number; diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts index 60426da49..8043de974 100644 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ b/src/helpers/guilds/update_bot_voice_state.ts @@ -3,7 +3,7 @@ import type { UpdateSelfVoiceState, } from "../../types/guilds/update_self_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Updates the current user's voice state. @@ -21,6 +21,6 @@ export async function updateBotVoiceState( return await rest.runMethod( "patch", endpoints.UPDATE_VOICE_STATE(guildId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts index 6a8e47ebd..38191274b 100644 --- a/src/helpers/guilds/update_user_voice_state.ts +++ b/src/helpers/guilds/update_user_voice_state.ts @@ -3,7 +3,7 @@ import type { UpdateOthersVoiceState, } from "../../types/guilds/update_others_voice_state.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Updates another user's voice state. @@ -22,6 +22,6 @@ export function updateVoiceState( return rest.runMethod( "patch", endpoints.UPDATE_VOICE_STATE(guildId, userId), - camelKeysToSnakeCase(data), + snakelize(data), ); } diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 1947d3317..340bf8421 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import type { Integration } from "../../types/integration/integration.ts"; +import type { Integration } from "../../types/integrations/integration.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/commands/batch_edit_slash_command_permissions.ts b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts similarity index 54% rename from src/helpers/commands/batch_edit_slash_command_permissions.ts rename to src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts index 8be782bff..f8b957019 100644 --- a/src/helpers/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts @@ -1,8 +1,8 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommandPermissions } from "../../types/interactions/application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize } from "../../../util/utils.ts"; /** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */ export async function batchEditSlashCommandPermissions( @@ -12,6 +12,6 @@ export async function batchEditSlashCommandPermissions( return await rest.runMethod( "put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/create_slash_command.ts b/src/helpers/interactions/commands/create_slash_command.ts similarity index 72% rename from src/helpers/commands/create_slash_command.ts rename to src/helpers/interactions/commands/create_slash_command.ts index b5241f556..2d9c1ebf6 100644 --- a/src/helpers/commands/create_slash_command.ts +++ b/src/helpers/interactions/commands/create_slash_command.ts @@ -1,12 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { - camelKeysToSnakeCase, - validateSlashCommands, -} from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { CreateGlobalApplicationCommand } from "../../../types/interactions/commands/create_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize, validateSlashCommands } from "../../../util/utils.ts"; /** * There are two kinds of Slash Commands: global commands and guild commands. Global commands are available for every guild that adds your app; guild commands are specific to the guild you specify when making them. Command names are unique per application within each scope (global and guild). That means: @@ -30,6 +27,6 @@ export async function createSlashCommand( guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/commands/delete_slash_command.ts b/src/helpers/interactions/commands/delete_slash_command.ts similarity index 66% rename from src/helpers/commands/delete_slash_command.ts rename to src/helpers/interactions/commands/delete_slash_command.ts index 0468ad3e5..d7fd746cb 100644 --- a/src/helpers/commands/delete_slash_command.ts +++ b/src/helpers/interactions/commands/delete_slash_command.ts @@ -1,6 +1,6 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import { endpoints } from "../../../util/constants.ts"; /** Deletes a slash command. */ export async function deleteSlashCommand( diff --git a/src/helpers/commands/delete_slash_response.ts b/src/helpers/interactions/commands/delete_slash_response.ts similarity index 76% rename from src/helpers/commands/delete_slash_response.ts rename to src/helpers/interactions/commands/delete_slash_response.ts index 7e6d7d991..d772f6e64 100644 --- a/src/helpers/commands/delete_slash_response.ts +++ b/src/helpers/interactions/commands/delete_slash_response.ts @@ -1,6 +1,6 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import { endpoints } from "../../../util/constants.ts"; /** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */ export async function deleteSlashResponse( diff --git a/src/helpers/interactions/commands/edit_slash_command_permissions.ts b/src/helpers/interactions/commands/edit_slash_command_permissions.ts new file mode 100644 index 000000000..6bbe374a7 --- /dev/null +++ b/src/helpers/interactions/commands/edit_slash_command_permissions.ts @@ -0,0 +1,18 @@ +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { snakelize } from "../../../util/utils.ts"; + +/** Edits command permissions for a specific command for your application in a guild. */ +export async function editSlashCommandPermissions( + guildId: bigint, + commandId: bigint, + options: ApplicationCommandPermissions[], +) { + return await rest.runMethod( + "put", + endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), + { permissions: snakelize(options) }, + ); +} diff --git a/src/helpers/commands/edit_slash_response.ts b/src/helpers/interactions/commands/edit_slash_response.ts similarity index 80% rename from src/helpers/commands/edit_slash_response.ts rename to src/helpers/interactions/commands/edit_slash_response.ts index 2c60d7836..13ea278a7 100644 --- a/src/helpers/commands/edit_slash_response.ts +++ b/src/helpers/interactions/commands/edit_slash_response.ts @@ -1,10 +1,10 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import { structures } from "../../structures/mod.ts"; -import type { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts"; -import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import { structures } from "../../../structures/mod.ts"; +import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/edit_webhook_message.ts"; +import { Errors } from "../../../types/discordeno/errors.ts"; +import { DiscordAllowedMentionsTypes } from "../../../types/messages/allowed_mentions_types.ts"; +import { endpoints } from "../../../util/constants.ts"; /** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */ export async function editSlashResponse( diff --git a/src/helpers/commands/get_slash_command.ts b/src/helpers/interactions/commands/get_slash_command.ts similarity index 61% rename from src/helpers/commands/get_slash_command.ts rename to src/helpers/interactions/commands/get_slash_command.ts index 846b47bf0..65bebb020 100644 --- a/src/helpers/commands/get_slash_command.ts +++ b/src/helpers/interactions/commands/get_slash_command.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +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: bigint, guildId?: bigint) { diff --git a/src/helpers/commands/get_slash_command_permission.ts b/src/helpers/interactions/commands/get_slash_command_permission.ts similarity index 57% rename from src/helpers/commands/get_slash_command_permission.ts rename to src/helpers/interactions/commands/get_slash_command_permission.ts index f07c92f18..0c3391d39 100644 --- a/src/helpers/commands/get_slash_command_permission.ts +++ b/src/helpers/interactions/commands/get_slash_command_permission.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; /** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ export async function getSlashCommandPermission( diff --git a/src/helpers/commands/get_slash_command_permissions.ts b/src/helpers/interactions/commands/get_slash_command_permissions.ts similarity index 55% rename from src/helpers/commands/get_slash_command_permissions.ts rename to src/helpers/interactions/commands/get_slash_command_permissions.ts index 07c12fb8f..f40dd9576 100644 --- a/src/helpers/commands/get_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/get_slash_command_permissions.ts @@ -1,7 +1,7 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { GuildApplicationCommandPermissions } from "../../types/interactions/guild_application_command_permissions.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; +import { endpoints } from "../../../util/constants.ts"; /** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ export async function getSlashCommandPermissions(guildId: bigint) { diff --git a/src/helpers/commands/get_slash_commands.ts b/src/helpers/interactions/commands/get_slash_commands.ts similarity index 55% rename from src/helpers/commands/get_slash_commands.ts rename to src/helpers/interactions/commands/get_slash_commands.ts index c4f4c8eff..15163ad88 100644 --- a/src/helpers/commands/get_slash_commands.ts +++ b/src/helpers/interactions/commands/get_slash_commands.ts @@ -1,8 +1,8 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import { Collection } from "../../util/collection.ts"; -import { endpoints } from "../../util/constants.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import { Collection } from "../../../util/collection.ts"; +import { endpoints } from "../../../util/constants.ts"; /** Fetch all of the global commands for your application. */ export async function getSlashCommands(guildId?: bigint) { diff --git a/src/helpers/commands/upsert_slash_command.ts b/src/helpers/interactions/commands/upsert_slash_command.ts similarity index 52% rename from src/helpers/commands/upsert_slash_command.ts rename to src/helpers/interactions/commands/upsert_slash_command.ts index ed2dc20f9..b6eea60e8 100644 --- a/src/helpers/commands/upsert_slash_command.ts +++ b/src/helpers/interactions/commands/upsert_slash_command.ts @@ -1,9 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { validateSlashCommands } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { validateSlashCommands } from "../../../util/utils.ts"; /** * Edit an existing slash command. If this command did not exist, it will create it. diff --git a/src/helpers/commands/upsert_slash_commands.ts b/src/helpers/interactions/commands/upsert_slash_commands.ts similarity index 58% rename from src/helpers/commands/upsert_slash_commands.ts rename to src/helpers/interactions/commands/upsert_slash_commands.ts index b49c2cb41..6598910f7 100644 --- a/src/helpers/commands/upsert_slash_commands.ts +++ b/src/helpers/interactions/commands/upsert_slash_commands.ts @@ -1,9 +1,9 @@ -import { applicationId } from "../../bot.ts"; -import { rest } from "../../rest/rest.ts"; -import type { ApplicationCommand } from "../../types/interactions/application_command.ts"; -import type { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts"; -import { endpoints } from "../../util/constants.ts"; -import { validateSlashCommands } from "../../util/utils.ts"; +import { applicationId } from "../../../bot.ts"; +import { rest } from "../../../rest/rest.ts"; +import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; +import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; +import { endpoints } from "../../../util/constants.ts"; +import { validateSlashCommands } from "../../../util/utils.ts"; /** * Bulk edit existing slash commands. If a command does not exist, it will create it. diff --git a/src/helpers/commands/get_original_interaction_response.ts b/src/helpers/interactions/get_original_interaction_response.ts similarity index 100% rename from src/helpers/commands/get_original_interaction_response.ts rename to src/helpers/interactions/get_original_interaction_response.ts diff --git a/src/helpers/commands/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts similarity index 100% rename from src/helpers/commands/send_interaction_response.ts rename to src/helpers/interactions/send_interaction_response.ts diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 8e5b177e4..5d916264c 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -2,13 +2,13 @@ import { rest } from "../../rest/rest.ts"; import { GetInvite } from "../../types/invites/get_invite.ts"; import type { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } 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, options?: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), - camelKeysToSnakeCase(options ?? {}), + snakelize(options ?? {}), ); } diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index 7af64906c..52424f5ff 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts"; import type { 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"; +import { snakelize } from "../../util/utils.ts"; /** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */ export async function ban( @@ -15,7 +15,7 @@ export async function ban( return await rest.runMethod( "put", endpoints.GUILD_BAN(guildId, id), - camelKeysToSnakeCase(options), + snakelize(options), ); } diff --git a/src/helpers/members/edit_member.ts b/src/helpers/members/edit_member.ts index e16958e89..efeca3ebd 100644 --- a/src/helpers/members/edit_member.ts +++ b/src/helpers/members/edit_member.ts @@ -1,9 +1,9 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { ModifyGuildMember } from "../../types/guilds/modify_guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,7 +11,7 @@ import { requireBotChannelPermissions, requireBotGuildPermissions, } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** Edit the member */ export async function editMember( @@ -73,7 +73,7 @@ export async function editMember( const result = await rest.runMethod( "patch", endpoints.GUILD_MEMBER(guildId, memberId), - camelKeysToSnakeCase({ + snakelize({ ...options, channelId: options.channelId ? bigintToSnowflake(options.channelId) diff --git a/src/helpers/members/fetch_members.ts b/src/helpers/members/fetch_members.ts index ba94ca136..5f02762dd 100644 --- a/src/helpers/members/fetch_members.ts +++ b/src/helpers/members/fetch_members.ts @@ -1,9 +1,9 @@ import { cache } from "../../cache.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts"; -import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; -import type { RequestGuildMembers } from "../../types/guilds/request_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; +import type { RequestGuildMembers } from "../../types/members/request_guild_members.ts"; import { Collection } from "../../util/collection.ts"; import { sendShardMessage } from "../../ws/send_shard_message.ts"; import { ws } from "../../ws/ws.ts"; diff --git a/src/helpers/members/get_member.ts b/src/helpers/members/get_member.ts index b2c17db17..e7887bc65 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 type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a guild member object for the specified user. diff --git a/src/helpers/members/get_members.ts b/src/helpers/members/get_members.ts index 15d8975c4..602657df5 100644 --- a/src/helpers/members/get_members.ts +++ b/src/helpers/members/get_members.ts @@ -3,10 +3,10 @@ import { cacheHandlers } from "../../cache.ts"; 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 type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { ListGuildMembers } from "../../types/guilds/list_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; +import type { ListGuildMembers } from "../../types/members/list_guild_members.ts"; import { bigintToSnowflake } from "../../util/bigint.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 05e950a97..523daa2c1 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -1,9 +1,9 @@ import { rest } from "../../rest/rest.ts"; -import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { BeginGuildPrune } from "../../types/guilds/begin_guild_prune.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; /** * Begin a prune operation. Requires the KICK_MEMBERS permission. Returns an object with one 'pruned' key indicating the number of members that were removed in the prune operation. For large guilds it's recommended to set the computePruneCount option to false, forcing 'pruned' to null. Fires multiple Guild Member Remove Gateway events. @@ -22,7 +22,7 @@ export async function pruneMembers( const result = await rest.runMethod<{ pruned: number }>( "post", endpoints.GUILD_PRUNE(guildId), - camelKeysToSnakeCase(options), + snakelize(options), ); return result.pruned; diff --git a/src/helpers/members/search_members.ts b/src/helpers/members/search_members.ts index 6a9d2fede..0c27f884a 100644 --- a/src/helpers/members/search_members.ts +++ b/src/helpers/members/search_members.ts @@ -2,9 +2,9 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { DiscordenoMember } from "../../structures/member.ts"; import { structures } from "../../structures/mod.ts"; -import type { GuildMemberWithUser } from "../../types/guilds/guild_member.ts"; -import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Errors } from "../../types/discordeno/errors.ts"; +import type { GuildMemberWithUser } from "../../types/members/guild_member.ts"; +import type { SearchGuildMembers } from "../../types/members/search_guild_members.ts"; import { Collection } from "../../util/collection.ts"; import { endpoints } from "../../util/constants.ts"; diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 2de5fcb1e..6f21f6912 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -2,15 +2,15 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts"; import { ButtonStyles } from "../../types/messages/components/button_styles.ts"; import type { CreateMessage } from "../../types/messages/create_message.ts"; import type { Message } from "../../types/messages/message.ts"; -import { Errors } from "../../types/discordeno/errors.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; -import { camelKeysToSnakeCase } from "../../util/utils.ts"; +import { snakelize } from "../../util/utils.ts"; import { validateLength } from "../../util/validate_length.ts"; import { isActionRow } from "../type_guards/is_action_row.ts"; import { isButton } from "../type_guards/is_button.ts"; @@ -148,7 +148,7 @@ export async function sendMessage( const result = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGES(channelId), - camelKeysToSnakeCase({ + snakelize({ ...content, ...(content.messageReference?.messageId ? { diff --git a/src/helpers/members/edit_bot_profile.ts b/src/helpers/misc/edit_bot_profile.ts similarity index 100% rename from src/helpers/members/edit_bot_profile.ts rename to src/helpers/misc/edit_bot_profile.ts diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 903614119..c0a814870 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,20 +13,6 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; -import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; -import { createSlashCommand } from "./commands/create_slash_command.ts"; -import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; -import { deleteSlashResponse } from "./commands/delete_slash_response.ts"; -import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts"; -import { editSlashResponse } from "./commands/edit_slash_response.ts"; -import { getOriginalInteractionResponse } from "./commands/get_original_interaction_response.ts"; -import { getSlashCommand } from "./commands/get_slash_command.ts"; -import { getSlashCommands } from "./commands/get_slash_commands.ts"; -import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; -import { getSlashCommandPermissions } from "./commands/get_slash_command_permissions.ts"; -import { sendInteractionResponse } from "./commands/send_interaction_response.ts"; -import { upsertSlashCommand } from "./commands/upsert_slash_command.ts"; -import { upsertSlashCommands } from "./commands/upsert_slash_commands.ts"; import { addDiscoverySubcategory } from "./discovery/add_discovery_subcategory.ts"; import { editDiscovery } from "./discovery/edit_discovery.ts"; import { getDiscoveryCategories } from "./discovery/get_discovery_categories.ts"; @@ -62,6 +48,20 @@ import { guildSplashURL } from "./guilds/guild_splash_url.ts"; import { leaveGuild } from "./guilds/leave_guild.ts"; import { deleteIntegration } from "./integrations/delete_integration.ts"; import { getIntegrations } from "./integrations/get_integrations.ts"; +import { batchEditSlashCommandPermissions } from "./interactions/commands/batch_edit_slash_command_permissions.ts"; +import { createSlashCommand } from "./interactions/commands/create_slash_command.ts"; +import { deleteSlashCommand } from "./interactions/commands/delete_slash_command.ts"; +import { deleteSlashResponse } from "./interactions/commands/delete_slash_response.ts"; +import { editSlashCommandPermissions } from "./interactions/commands/edit_slash_command_permissions.ts"; +import { editSlashResponse } from "./interactions/commands/edit_slash_response.ts"; +import { getSlashCommand } from "./interactions/commands/get_slash_command.ts"; +import { getSlashCommands } from "./interactions/commands/get_slash_commands.ts"; +import { getSlashCommandPermission } from "./interactions/commands/get_slash_command_permission.ts"; +import { getSlashCommandPermissions } from "./interactions/commands/get_slash_command_permissions.ts"; +import { upsertSlashCommand } from "./interactions/commands/upsert_slash_command.ts"; +import { upsertSlashCommands } from "./interactions/commands/upsert_slash_commands.ts"; +import { getOriginalInteractionResponse } from "./interactions/get_original_interaction_response.ts"; +import { sendInteractionResponse } from "./interactions/send_interaction_response.ts"; import { createInvite } from "./invites/create_invite.ts"; import { deleteInvite } from "./invites/delete_invite.ts"; import { getChannelInvites } from "./invites/get_channel_invites.ts"; @@ -71,7 +71,6 @@ import { avatarURL } from "./members/avatar_url.ts"; import { ban, banMember } from "./members/ban_member.ts"; import { disconnectMember } from "./members/disconnect_member.ts"; import { editBotNickname } from "./members/edit_bot_nickname.ts"; -import { editBotProfile } from "./members/edit_bot_profile.ts"; import { editMember } from "./members/edit_member.ts"; import { fetchMembers } from "./members/fetch_members.ts"; import { getMember } from "./members/get_member.ts"; @@ -96,6 +95,7 @@ import { removeReaction } from "./messages/remove_reaction.ts"; import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts"; import { sendMessage } from "./messages/send_message.ts"; import { unpin, unpinMessage } from "./messages/unpin_message.ts"; +import { editBotProfile } from "./misc/edit_bot_profile.ts"; import { editBotStatus } from "./misc/edit_bot_status.ts"; import { getGatewayBot } from "./misc/get_gateway_bot.ts"; import { getUser } from "./misc/get_user.ts"; diff --git a/src/rest/run_method.ts b/src/rest/run_method.ts index 53ff1f34b..5593b89d5 100644 --- a/src/rest/run_method.ts +++ b/src/rest/run_method.ts @@ -1,6 +1,6 @@ import { API_VERSION, BASE_URL, IMAGE_BASE_URL } from "../util/constants.ts"; import { loopObject } from "../util/loop_object.ts"; -import { snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize } from "../util/utils.ts"; import { rest } from "./rest.ts"; // deno-lint-ignore no-explicit-any @@ -62,7 +62,7 @@ export async function runMethod( method, reject, respond: (data: { status: number; body?: string }) => - resolve(snakeKeysToCamelCase(JSON.parse(data.body || "{}"))), + resolve(camelize(JSON.parse(data.body || "{}"))), }, { bucketId, diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 80253cd91..75bc4a09b 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -12,19 +12,19 @@ import { leaveGuild } from "../helpers/guilds/leave_guild.ts"; import { getInvites } from "../helpers/invites/get_invites.ts"; import { banMember } from "../helpers/members/ban_member.ts"; import { unbanMember } from "../helpers/members/unban_member.ts"; +import type { PresenceUpdate } from "../types/activity/presence_update.ts"; import { GetGuildAuditLog } from "../types/audit_log/get_guild_audit_log.ts"; import type { Emoji } from "../types/emojis/emoji.ts"; import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; import type { Guild } from "../types/guilds/guild.ts"; import { DiscordGuildFeatures } from "../types/guilds/guild_features.ts"; +import type { ModifyGuild } from "../types/guilds/modify_guild.ts"; import type { GuildMember, GuildMemberWithUser, -} from "../types/guilds/guild_member.ts"; -import type { ModifyGuild } from "../types/guilds/modify_guild.ts"; +} from "../types/members/guild_member.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; -import type { PresenceUpdate } from "../types/misc/presence_update.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { cacheMembers } from "../util/cache_members.ts"; import { Collection } from "../util/collection.ts"; diff --git a/src/structures/member.ts b/src/structures/member.ts index d592dcabd..3ee3ff30d 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -8,11 +8,11 @@ import { sendDirectMessage } from "../helpers/members/send_direct_message.ts"; import { addRole } from "../helpers/roles/add_role.ts"; import { removeRole } from "../helpers/roles/remove_role.ts"; import type { CreateGuildBan } from "../types/guilds/create_guild_ban.ts"; +import type { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; import type { GuildMember, GuildMemberWithUser, -} from "../types/guilds/guild_member.ts"; -import type { ModifyGuildMember } from "../types/guilds/modify_guild_member.ts"; +} from "../types/members/guild_member.ts"; import type { CreateMessage } from "../types/messages/create_message.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; diff --git a/src/structures/message.ts b/src/structures/message.ts index af8832351..0525d254f 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -10,7 +10,7 @@ import { removeAllReactions } from "../helpers/messages/remove_all_reactions.ts" import { removeReaction } from "../helpers/messages/remove_reaction.ts"; import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts"; import { sendMessage } from "../helpers/messages/send_message.ts"; -import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { GuildMember } from "../types/members/guild_member.ts"; import type { CreateMessage } from "../types/messages/create_message.ts"; import type { EditMessage } from "../types/messages/edit_message.ts"; import type { Message } from "../types/messages/message.ts"; diff --git a/src/structures/voice_state.ts b/src/structures/voice_state.ts index 48a7f906b..737b4e335 100644 --- a/src/structures/voice_state.ts +++ b/src/structures/voice_state.ts @@ -1,6 +1,6 @@ import { eventHandlers } from "../bot.ts"; import { cache } from "../cache.ts"; -import type { GuildMember } from "../types/guilds/guild_member.ts"; +import type { GuildMember } from "../types/members/guild_member.ts"; import type { VoiceState } from "../types/voice/voice_state.ts"; import { snowflakeToBigint } from "../util/bigint.ts"; import { createNewProp } from "../util/utils.ts"; diff --git a/src/types/misc/activity.ts b/src/types/activity/activity.ts similarity index 100% rename from src/types/misc/activity.ts rename to src/types/activity/activity.ts diff --git a/src/types/misc/activity_assets.ts b/src/types/activity/activity_assets.ts similarity index 100% rename from src/types/misc/activity_assets.ts rename to src/types/activity/activity_assets.ts diff --git a/src/types/misc/activity_button.ts b/src/types/activity/activity_button.ts similarity index 100% rename from src/types/misc/activity_button.ts rename to src/types/activity/activity_button.ts diff --git a/src/types/misc/activity_emoji.ts b/src/types/activity/activity_emoji.ts similarity index 100% rename from src/types/misc/activity_emoji.ts rename to src/types/activity/activity_emoji.ts diff --git a/src/types/misc/activity_flags.ts b/src/types/activity/activity_flags.ts similarity index 100% rename from src/types/misc/activity_flags.ts rename to src/types/activity/activity_flags.ts diff --git a/src/types/misc/activity_party.ts b/src/types/activity/activity_party.ts similarity index 100% rename from src/types/misc/activity_party.ts rename to src/types/activity/activity_party.ts diff --git a/src/types/misc/activity_secrets.ts b/src/types/activity/activity_secrets.ts similarity index 100% rename from src/types/misc/activity_secrets.ts rename to src/types/activity/activity_secrets.ts diff --git a/src/types/misc/activity_timestamps.ts b/src/types/activity/activity_timestamps.ts similarity index 100% rename from src/types/misc/activity_timestamps.ts rename to src/types/activity/activity_timestamps.ts diff --git a/src/types/misc/activity_types.ts b/src/types/activity/activity_types.ts similarity index 100% rename from src/types/misc/activity_types.ts rename to src/types/activity/activity_types.ts diff --git a/src/types/misc/client_status.ts b/src/types/activity/client_status.ts similarity index 100% rename from src/types/misc/client_status.ts rename to src/types/activity/client_status.ts diff --git a/src/types/misc/presence_update.ts b/src/types/activity/presence_update.ts similarity index 100% rename from src/types/misc/presence_update.ts rename to src/types/activity/presence_update.ts diff --git a/src/types/audit_log/audit_log.ts b/src/types/audit_log/audit_log.ts index 41ccff42b..578a54d73 100644 --- a/src/types/audit_log/audit_log.ts +++ b/src/types/audit_log/audit_log.ts @@ -1,4 +1,4 @@ -import { Integration } from "../integration/integration.ts"; +import { Integration } from "../integrations/integration.ts"; import { User } from "../users/user.ts"; import { Webhook } from "../webhooks/webhook.ts"; import { AuditLogEntry } from "./audit_log_entry.ts"; diff --git a/src/types/discordeno/create_slash_command.ts b/src/types/discordeno/create_slash_command.ts index 969ac33fc..b0008fca1 100644 --- a/src/types/discordeno/create_slash_command.ts +++ b/src/types/discordeno/create_slash_command.ts @@ -1,4 +1,4 @@ -import { CreateGlobalApplicationCommand } from "../interactions/create_global_application_command.ts"; +import { CreateGlobalApplicationCommand } from "../interactions/commands/create_global_application_command.ts"; export interface DiscordenoCreateApplicationCommand extends CreateGlobalApplicationCommand { diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/eventHandlers.ts index 5386935ab..c456c91ee 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/eventHandlers.ts @@ -6,8 +6,8 @@ import { DiscordenoRole } from "../../structures/role.ts"; import { Collection } from "../../util/collection.ts"; import { ThreadMember } from "../channels/threads/thread_member.ts"; import { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts"; -import { IntegrationCreateUpdate } from "../integration/integration_create_update.ts"; -import { ApplicationCommandCreateUpdateDelete } from "../interactions/application_command_create_update_delete.ts"; +import { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts"; +import { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts"; import { DiscordGatewayPayload, Emoji, diff --git a/src/types/gateway/status_update.ts b/src/types/gateway/status_update.ts index 27f65b9ca..12092cbdd 100644 --- a/src/types/gateway/status_update.ts +++ b/src/types/gateway/status_update.ts @@ -1,4 +1,4 @@ -import { Activity } from "../misc/activity.ts"; +import { Activity } from "../activity/activity.ts"; import { DiscordStatusTypes } from "./status_types.ts"; /** https://discord.com/developers/docs/topics/gateway#update-status */ diff --git a/src/types/guilds/guild.ts b/src/types/guilds/guild.ts index a6b050529..14e9676fe 100644 --- a/src/types/guilds/guild.ts +++ b/src/types/guilds/guild.ts @@ -1,12 +1,12 @@ +import { PresenceUpdate } from "../activity/presence_update.ts"; import { Channel } from "../channels/channel.ts"; import { Emoji } from "../emojis/emoji.ts"; -import { PresenceUpdate } from "../misc/presence_update.ts"; +import { GuildMember } from "../members/guild_member.ts"; import { Role } from "../permissions/role.ts"; import { VoiceState } from "../voice/voice_state.ts"; import { DiscordDefaultMessageNotificationLevels } from "./default_message_notification_levels.ts"; import { DiscordExplicitContentFilterLevels } from "./explicit_content_filter_levels.ts"; import { DiscordGuildFeatures } from "./guild_features.ts"; -import { GuildMember } from "./guild_member.ts"; import { DiscordMfaLevels } from "./mfa_levels.ts"; import { DiscordPremiumTiers } from "./premium_tiers.ts"; import { DiscordSystemChannelFlags } from "./system_channel_flags.ts"; diff --git a/src/types/integration/guild_integrations_update.ts b/src/types/integrations/guild_integrations_update.ts similarity index 100% rename from src/types/integration/guild_integrations_update.ts rename to src/types/integrations/guild_integrations_update.ts diff --git a/src/types/integration/integration.ts b/src/types/integrations/integration.ts similarity index 100% rename from src/types/integration/integration.ts rename to src/types/integrations/integration.ts diff --git a/src/types/integration/integration_account.ts b/src/types/integrations/integration_account.ts similarity index 100% rename from src/types/integration/integration_account.ts rename to src/types/integrations/integration_account.ts diff --git a/src/types/integration/integration_application.ts b/src/types/integrations/integration_application.ts similarity index 100% rename from src/types/integration/integration_application.ts rename to src/types/integrations/integration_application.ts diff --git a/src/types/integration/integration_create_update.ts b/src/types/integrations/integration_create_update.ts similarity index 100% rename from src/types/integration/integration_create_update.ts rename to src/types/integrations/integration_create_update.ts diff --git a/src/types/integration/integration_delete.ts b/src/types/integrations/integration_delete.ts similarity index 100% rename from src/types/integration/integration_delete.ts rename to src/types/integrations/integration_delete.ts diff --git a/src/types/integration/integration_expire_behaviors.ts b/src/types/integrations/integration_expire_behaviors.ts similarity index 100% rename from src/types/integration/integration_expire_behaviors.ts rename to src/types/integrations/integration_expire_behaviors.ts diff --git a/src/types/interactions/application_command.ts b/src/types/interactions/commands/application_command.ts similarity index 100% rename from src/types/interactions/application_command.ts rename to src/types/interactions/commands/application_command.ts diff --git a/src/types/interactions/application_command_callback_data.ts b/src/types/interactions/commands/application_command_callback_data.ts similarity index 80% rename from src/types/interactions/application_command_callback_data.ts rename to src/types/interactions/commands/application_command_callback_data.ts index 5844862d2..6857815af 100644 --- a/src/types/interactions/application_command_callback_data.ts +++ b/src/types/interactions/commands/application_command_callback_data.ts @@ -1,5 +1,5 @@ -import { Embed } from "../embeds/embed.ts"; -import { AllowedMentions } from "../messages/allowed_mentions.ts"; +import { Embed } from "../../embeds/embed.ts"; +import { AllowedMentions } from "../../messages/allowed_mentions.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ export interface InteractionApplicationCommandCallbackData { diff --git a/src/types/interactions/application_command_create_update_delete.ts b/src/types/interactions/commands/application_command_create_update_delete.ts similarity index 100% rename from src/types/interactions/application_command_create_update_delete.ts rename to src/types/interactions/commands/application_command_create_update_delete.ts diff --git a/src/types/interactions/application_command_interaction_data.ts b/src/types/interactions/commands/application_command_interaction_data.ts similarity index 100% rename from src/types/interactions/application_command_interaction_data.ts rename to src/types/interactions/commands/application_command_interaction_data.ts diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/commands/application_command_interaction_data_option.ts similarity index 100% rename from src/types/interactions/application_command_interaction_data_option.ts rename to src/types/interactions/commands/application_command_interaction_data_option.ts diff --git a/src/types/interactions/application_command_interaction_data_resolved.ts b/src/types/interactions/commands/application_command_interaction_data_resolved.ts similarity index 68% rename from src/types/interactions/application_command_interaction_data_resolved.ts rename to src/types/interactions/commands/application_command_interaction_data_resolved.ts index db967bb97..976129ece 100644 --- a/src/types/interactions/application_command_interaction_data_resolved.ts +++ b/src/types/interactions/commands/application_command_interaction_data_resolved.ts @@ -1,7 +1,7 @@ -import { Channel } from "../channels/channel.ts"; -import { GuildMember } from "../guilds/guild_member.ts"; -import { Role } from "../permissions/role.ts"; -import { User } from "../users/user.ts"; +import { Channel } from "../../channels/channel.ts"; +import { GuildMember } from "../../members/guild_member.ts"; +import { Role } from "../../permissions/role.ts"; +import { User } from "../../users/user.ts"; export interface ApplicationCommandInteractionDataResolved { /** The Ids and User objects */ diff --git a/src/types/interactions/application_command_option.ts b/src/types/interactions/commands/application_command_option.ts similarity index 100% rename from src/types/interactions/application_command_option.ts rename to src/types/interactions/commands/application_command_option.ts diff --git a/src/types/interactions/application_command_option_choice.ts b/src/types/interactions/commands/application_command_option_choice.ts similarity index 100% rename from src/types/interactions/application_command_option_choice.ts rename to src/types/interactions/commands/application_command_option_choice.ts diff --git a/src/types/interactions/application_command_option_types.ts b/src/types/interactions/commands/application_command_option_types.ts similarity index 100% rename from src/types/interactions/application_command_option_types.ts rename to src/types/interactions/commands/application_command_option_types.ts diff --git a/src/types/interactions/application_command_permission_types.ts b/src/types/interactions/commands/application_command_permission_types.ts similarity index 100% rename from src/types/interactions/application_command_permission_types.ts rename to src/types/interactions/commands/application_command_permission_types.ts diff --git a/src/types/interactions/application_command_permissions.ts b/src/types/interactions/commands/application_command_permissions.ts similarity index 100% rename from src/types/interactions/application_command_permissions.ts rename to src/types/interactions/commands/application_command_permissions.ts diff --git a/src/types/interactions/create_global_application_command.ts b/src/types/interactions/commands/create_global_application_command.ts similarity index 100% rename from src/types/interactions/create_global_application_command.ts rename to src/types/interactions/commands/create_global_application_command.ts diff --git a/src/types/interactions/create_guild_application_command.ts b/src/types/interactions/commands/create_guild_application_command.ts similarity index 100% rename from src/types/interactions/create_guild_application_command.ts rename to src/types/interactions/commands/create_guild_application_command.ts diff --git a/src/types/interactions/edit_global_application_command.ts b/src/types/interactions/commands/edit_global_application_command.ts similarity index 100% rename from src/types/interactions/edit_global_application_command.ts rename to src/types/interactions/commands/edit_global_application_command.ts diff --git a/src/types/interactions/edit_guild_application_command.ts b/src/types/interactions/commands/edit_guild_application_command.ts similarity index 100% rename from src/types/interactions/edit_guild_application_command.ts rename to src/types/interactions/commands/edit_guild_application_command.ts diff --git a/src/types/interactions/guild_application_command_permissions.ts b/src/types/interactions/commands/guild_application_command_permissions.ts similarity index 100% rename from src/types/interactions/guild_application_command_permissions.ts rename to src/types/interactions/commands/guild_application_command_permissions.ts diff --git a/src/types/interactions/interaction.ts b/src/types/interactions/interaction.ts index 975238ac8..adf4ab521 100644 --- a/src/types/interactions/interaction.ts +++ b/src/types/interactions/interaction.ts @@ -1,7 +1,7 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; import { Message } from "../messages/message.ts"; import { User } from "../users/user.ts"; -import { ApplicationCommandInteractionData } from "./application_command_interaction_data.ts"; +import { ApplicationCommandInteractionData } from "./commands/application_command_interaction_data.ts"; import { DiscordInteractionTypes } from "./interaction_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction */ diff --git a/src/types/interactions/interaction_guild_member.ts b/src/types/interactions/interaction_guild_member.ts index fb9cebc78..d7ab18d57 100644 --- a/src/types/interactions/interaction_guild_member.ts +++ b/src/types/interactions/interaction_guild_member.ts @@ -1,4 +1,4 @@ -import { GuildMember } from "../guilds/guild_member.ts"; +import { GuildMember } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/resources/guild#guild-member-object */ export interface InteractionGuildMember extends GuildMember { diff --git a/src/types/interactions/interaction_response.ts b/src/types/interactions/interaction_response.ts index 5460cbb4e..4b0ac1b8c 100644 --- a/src/types/interactions/interaction_response.ts +++ b/src/types/interactions/interaction_response.ts @@ -1,4 +1,4 @@ -import { InteractionApplicationCommandCallbackData } from "./application_command_callback_data.ts"; +import { InteractionApplicationCommandCallbackData } from "./commands/application_command_callback_data.ts"; import { DiscordInteractionResponseTypes } from "./interaction_response_types.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ diff --git a/src/types/guilds/guild_member.ts b/src/types/members/guild_member.ts similarity index 100% rename from src/types/guilds/guild_member.ts rename to src/types/members/guild_member.ts diff --git a/src/types/members/guild_member_add.ts b/src/types/members/guild_member_add.ts index a39685228..f5b8bd9ee 100644 --- a/src/types/members/guild_member_add.ts +++ b/src/types/members/guild_member_add.ts @@ -1,4 +1,4 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#guild-member-add */ export interface GuildMemberAdd extends GuildMemberWithUser { diff --git a/src/types/members/guild_members_chunk.ts b/src/types/members/guild_members_chunk.ts index a4b801f33..0e0cd7a32 100644 --- a/src/types/members/guild_members_chunk.ts +++ b/src/types/members/guild_members_chunk.ts @@ -1,5 +1,5 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; -import { PresenceUpdate } from "../misc/presence_update.ts"; +import { PresenceUpdate } from "../activity/presence_update.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */ export interface GuildMembersChunk { diff --git a/src/types/guilds/list_guild_members.ts b/src/types/members/list_guild_members.ts similarity index 100% rename from src/types/guilds/list_guild_members.ts rename to src/types/members/list_guild_members.ts diff --git a/src/types/guilds/modify_current_user_nick.ts b/src/types/members/modify_current_user_nick.ts similarity index 100% rename from src/types/guilds/modify_current_user_nick.ts rename to src/types/members/modify_current_user_nick.ts diff --git a/src/types/guilds/request_guild_members.ts b/src/types/members/request_guild_members.ts similarity index 100% rename from src/types/guilds/request_guild_members.ts rename to src/types/members/request_guild_members.ts diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index 9ae7b8879..72934232f 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -2,8 +2,8 @@ import { Channel } from "../channels/channel.ts"; import { ChannelMention } from "../channels/channel_mention.ts"; import { ThreadMember } from "../channels/threads/thread_member.ts"; import { Embed } from "../embeds/embed.ts"; -import { GuildMember } from "../guilds/guild_member.ts"; import { MessageInteraction } from "../interactions/message_interaction.ts"; +import { GuildMember } from "../members/guild_member.ts"; import { Application } from "../oauth2/application.ts"; import { User } from "../users/user.ts"; import { Attachment } from "./attachment.ts"; diff --git a/src/types/messages/message_reaction_add.ts b/src/types/messages/message_reaction_add.ts index ef3709af3..c0846e858 100644 --- a/src/types/messages/message_reaction_add.ts +++ b/src/types/messages/message_reaction_add.ts @@ -1,5 +1,5 @@ import { Emoji } from "../emojis/emoji.ts"; -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#message-reaction-add */ export interface MessageReactionAdd { diff --git a/src/types/misc/typing_start.ts b/src/types/misc/typing_start.ts index 4c23b7d2b..748de7b3f 100644 --- a/src/types/misc/typing_start.ts +++ b/src/types/misc/typing_start.ts @@ -1,4 +1,4 @@ -import { GuildMember } from "../guilds/guild_member.ts"; +import { GuildMember } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/topics/gateway#typing-start */ export interface TypingStart { diff --git a/src/types/mod.ts b/src/types/mod.ts index 61ed15cc6..2bd4c0e92 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -1,3 +1,14 @@ +export * from "./activity/activity.ts"; +export * from "./activity/activity_assets.ts"; +export * from "./activity/activity_button.ts"; +export * from "./activity/activity_emoji.ts"; +export * from "./activity/activity_flags.ts"; +export * from "./activity/activity_party.ts"; +export * from "./activity/activity_secrets.ts"; +export * from "./activity/activity_timestamps.ts"; +export * from "./activity/activity_types.ts"; +export * from "./activity/client_status.ts"; +export * from "./activity/presence_update.ts"; export * from "./audit_log/audit_log.ts"; export * from "./audit_log/audit_log_change.ts"; export * from "./audit_log/audit_log_change_value.ts"; @@ -13,6 +24,14 @@ export * from "./channels/followed_channel.ts"; export * from "./channels/modify_channel.ts"; export * from "./channels/overwrite.ts"; export * from "./channels/overwrite_types.ts"; +export * from "./channels/threads/list_active_threads.ts"; +export * from "./channels/threads/list_public_archived_threads.ts"; +export * from "./channels/threads/modify_thread.ts"; +export * from "./channels/threads/start_thread.ts"; +export * from "./channels/threads/thread_list_sync.ts"; +export * from "./channels/threads/thread_member.ts"; +export * from "./channels/threads/thread_members_update.ts"; +export * from "./channels/threads/thread_metadata.ts"; export * from "./channels/video_quality_modes.ts"; export * from "./codes/gateway_close_event_codes.ts"; export * from "./codes/gateway_opcodes.ts"; @@ -25,10 +44,19 @@ export * from "./codes/voice_opcodes.ts"; export * from "./discordeno/create_slash_command.ts"; export * from "./discordeno/debug_arg.ts"; export * from "./discordeno/edit_webhook_message.ts"; +export * from "./discordeno/errors.ts"; export * from "./discordeno/eventHandlers.ts"; +export * from "./discordeno/file_content.ts"; export * from "./discordeno/guild_member.ts"; export * from "./discordeno/guild_update_change.ts"; export * from "./discordeno/interaction_response.ts"; +export * from "./discovery/add_guild_discovery_subcategory.ts"; +export * from "./discovery/discovery_category.ts"; +export * from "./discovery/discovery_metadata.ts"; +export * from "./discovery/discovery_name.ts"; +export * from "./discovery/modify_guild_discovery_metadata.ts"; +export * from "./discovery/validate_discovery_search_term.ts"; +export * from "./discovery/validate_discovery_search_term_params.ts"; export * from "./embeds/embed.ts"; export * from "./embeds/embed_author.ts"; export * from "./embeds/embed_field.ts"; @@ -70,15 +98,13 @@ export * from "./guilds/guild.ts"; export * from "./guilds/guild_ban_add_remove.ts"; export * from "./guilds/guild_ban_remove.ts"; export * from "./guilds/guild_features.ts"; -export * from "./guilds/guild_member.ts"; export * from "./guilds/guild_preview.ts"; export * from "./guilds/guild_role_create.ts"; export * from "./guilds/guild_role_delete.ts"; export * from "./guilds/guild_role_update.ts"; export * from "./guilds/guild_widget.ts"; -export * from "./guilds/list_guild_members.ts"; +export * from "./guilds/guild_widget_details.ts"; export * from "./guilds/mfa_levels.ts"; -export * from "./guilds/modify_current_user_nick.ts"; export * from "./guilds/modify_guild.ts"; export * from "./guilds/modify_guild_channel_position.ts"; export * from "./guilds/modify_guild_member.ts"; @@ -86,32 +112,36 @@ export * from "./guilds/modify_guild_role.ts"; export * from "./guilds/modify_guild_role_positions.ts"; export * from "./guilds/modify_guild_welcome_screen.ts"; export * from "./guilds/premium_tiers.ts"; -export * from "./guilds/request_guild_members.ts"; export * from "./guilds/system_channel_flags.ts"; export * from "./guilds/unavailable_guild.ts"; +export * from "./guilds/update_others_voice_state.ts"; +export * from "./guilds/update_self_voice_state.ts"; export * from "./guilds/verification_levels.ts"; export * from "./guilds/welcome_screen.ts"; export * from "./guilds/welcome_screen_channel.ts"; -export * from "./integration/guild_integrations_update.ts"; -export * from "./integration/integration.ts"; -export * from "./integration/integration_account.ts"; -export * from "./integration/integration_application.ts"; -export * from "./integration/integration_create_update.ts"; -export * from "./integration/integration_delete.ts"; -export * from "./integration/integration_expire_behaviors.ts"; -export * from "./interactions/application_command.ts"; -export * from "./interactions/application_command_callback_data.ts"; -export * from "./interactions/application_command_create_update_delete.ts"; -export * from "./interactions/application_command_interaction_data.ts"; -export * from "./interactions/application_command_interaction_data_option.ts"; -export * from "./interactions/application_command_interaction_data_resolved.ts"; -export * from "./interactions/application_command_option.ts"; -export * from "./interactions/application_command_option_choice.ts"; -export * from "./interactions/application_command_option_types.ts"; -export * from "./interactions/create_global_application_command.ts"; -export * from "./interactions/create_guild_application_command.ts"; -export * from "./interactions/edit_global_application_command.ts"; -export * from "./interactions/edit_guild_application_command.ts"; +export * from "./integrations/guild_integrations_update.ts"; +export * from "./integrations/integration.ts"; +export * from "./integrations/integration_account.ts"; +export * from "./integrations/integration_application.ts"; +export * from "./integrations/integration_create_update.ts"; +export * from "./integrations/integration_delete.ts"; +export * from "./integrations/integration_expire_behaviors.ts"; +export * from "./interactions/commands/application_command.ts"; +export * from "./interactions/commands/application_command_callback_data.ts"; +export * from "./interactions/commands/application_command_create_update_delete.ts"; +export * from "./interactions/commands/application_command_interaction_data.ts"; +export * from "./interactions/commands/application_command_interaction_data_option.ts"; +export * from "./interactions/commands/application_command_interaction_data_resolved.ts"; +export * from "./interactions/commands/application_command_option.ts"; +export * from "./interactions/commands/application_command_option_choice.ts"; +export * from "./interactions/commands/application_command_option_types.ts"; +export * from "./interactions/commands/application_command_permissions.ts"; +export * from "./interactions/commands/application_command_permission_types.ts"; +export * from "./interactions/commands/create_global_application_command.ts"; +export * from "./interactions/commands/create_guild_application_command.ts"; +export * from "./interactions/commands/edit_global_application_command.ts"; +export * from "./interactions/commands/edit_guild_application_command.ts"; +export * from "./interactions/commands/guild_application_command_permissions.ts"; export * from "./interactions/interaction.ts"; export * from "./interactions/interaction_guild_member.ts"; export * from "./interactions/interaction_response.ts"; @@ -126,19 +156,23 @@ export * from "./invites/invite_delete.ts"; export * from "./invites/invite_metadata.ts"; export * from "./invites/invite_target_types.ts"; export * from "./invites/target_types.ts"; +export * from "./members/guild_member.ts"; export * from "./members/guild_members_chunk.ts"; export * from "./members/guild_member_add.ts"; export * from "./members/guild_member_remove.ts"; export * from "./members/guild_member_update.ts"; +export * from "./members/list_guild_members.ts"; +export * from "./members/modify_current_user_nick.ts"; +export * from "./members/request_guild_members.ts"; export * from "./members/search_guild_members.ts"; -export * from "./messages/components/action_row.ts"; -export * from "./messages/components/button_component.ts"; -export * from "./messages/components/button_styles.ts"; -export * from "./messages/components/message_component_types.ts"; -export * from "./messages/components/message_components.ts"; export * from "./messages/allowed_mentions.ts"; export * from "./messages/allowed_mentions_types.ts"; export * from "./messages/attachment.ts"; +export * from "./messages/components/action_row.ts"; +export * from "./messages/components/button_component.ts"; +export * from "./messages/components/button_styles.ts"; +export * from "./messages/components/message_components.ts"; +export * from "./messages/components/message_component_types.ts"; export * from "./messages/create_message.ts"; export * from "./messages/edit_message.ts"; export * from "./messages/get_messages.ts"; @@ -158,21 +192,8 @@ export * from "./messages/message_sticker.ts"; export * from "./messages/message_sticker_format_types.ts"; export * from "./messages/message_types.ts"; export * from "./messages/reaction.ts"; -export * from "./misc/activity.ts"; -export * from "./misc/activity_assets.ts"; -export * from "./misc/activity_button.ts"; -export * from "./misc/activity_emoji.ts"; -export * from "./misc/activity_flags.ts"; -export * from "./misc/activity_party.ts"; -export * from "./misc/activity_secrets.ts"; -export * from "./misc/activity_timestamps.ts"; -export * from "./misc/activity_types.ts"; -export * from "./misc/client_status.ts"; -export * from "./discordeno/errors.ts"; -export * from "./discordeno/file_content.ts"; export * from "./misc/image_format.ts"; export * from "./misc/image_size.ts"; -export * from "./misc/presence_update.ts"; export * from "./misc/typing_start.ts"; export * from "./mod.ts"; export * from "./oauth2/application.ts"; diff --git a/src/types/users/connection.ts b/src/types/users/connection.ts index 4d3f64f26..69e8de021 100644 --- a/src/types/users/connection.ts +++ b/src/types/users/connection.ts @@ -1,4 +1,4 @@ -import { Integration } from "../integration/integration.ts"; +import { Integration } from "../integrations/integration.ts"; import { DiscordVisibilityTypes } from "./visibility_types.ts"; /** https://discord.com/developers/docs/resources/user#connection-objecthttps://discord.com/developers/docs/resources/user#user-object-premium-types */ diff --git a/src/types/voice/voice_state.ts b/src/types/voice/voice_state.ts index 8aa38f68b..156e15ad4 100644 --- a/src/types/voice/voice_state.ts +++ b/src/types/voice/voice_state.ts @@ -1,4 +1,4 @@ -import { GuildMemberWithUser } from "../guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../members/guild_member.ts"; /** https://discord.com/developers/docs/resources/voice#voice-state-object-voice-state-structure */ export interface VoiceState { diff --git a/src/util/cache_members.ts b/src/util/cache_members.ts index c2b9b81d6..86e27d15a 100644 --- a/src/util/cache_members.ts +++ b/src/util/cache_members.ts @@ -1,7 +1,7 @@ import { eventHandlers } from "../bot.ts"; import { cacheHandlers } from "../cache.ts"; import { structures } from "../structures/mod.ts"; -import { GuildMemberWithUser } from "../types/guilds/guild_member.ts"; +import { GuildMemberWithUser } from "../types/members/guild_member.ts"; const guildMemberQueue = new Map< bigint, diff --git a/src/util/utils.ts b/src/util/utils.ts index 8ae7511f9..d936d291b 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -1,11 +1,11 @@ import { encode } from "../../deps.ts"; import { eventHandlers } from "../bot.ts"; -import type { ApplicationCommandOption } from "../types/interactions/application_command_option.ts"; -import type { ApplicationCommandOptionChoice } from "../types/interactions/application_command_option_choice.ts"; -import { DiscordApplicationCommandOptionTypes } from "../types/interactions/application_command_option_types.ts"; -import type { CreateGlobalApplicationCommand } from "../types/interactions/create_global_application_command.ts"; -import type { EditGlobalApplicationCommand } from "../types/interactions/edit_global_application_command.ts"; import { Errors } from "../types/discordeno/errors.ts"; +import type { ApplicationCommandOption } from "../types/interactions/commands/application_command_option.ts"; +import type { ApplicationCommandOptionChoice } from "../types/interactions/commands/application_command_option_choice.ts"; +import { DiscordApplicationCommandOptionTypes } from "../types/interactions/commands/application_command_option_types.ts"; +import type { CreateGlobalApplicationCommand } from "../types/interactions/commands/create_global_application_command.ts"; +import type { EditGlobalApplicationCommand } from "../types/interactions/commands/edit_global_application_command.ts"; import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; @@ -61,7 +61,7 @@ function isConvertableObject(obj: unknown) { ); } -export function camelKeysToSnakeCase( +export function snakelize( // deno-lint-ignore no-explicit-any obj: Record | Record[], ): T { @@ -72,9 +72,9 @@ export function camelKeysToSnakeCase( Object.keys(obj).forEach((key) => { eventHandlers.debug?.( "loop", - `Running forEach loop in camelKeysToSnakeCase function.`, + `Running forEach loop in snakelize function.`, ); - convertedObject[camelToSnakeCase(key)] = camelKeysToSnakeCase( + convertedObject[camelToSnakeCase(key)] = snakelize( // deno-lint-ignore no-explicit-any (obj as Record)[key], ); @@ -82,13 +82,13 @@ export function camelKeysToSnakeCase( return convertedObject as T; } else if (Array.isArray(obj)) { - obj = obj.map((element) => camelKeysToSnakeCase(element)); + obj = obj.map((element) => snakelize(element)); } return obj as T; } -export function snakeKeysToCamelCase( +export function camelize( // deno-lint-ignore no-explicit-any obj: Record | Record[], ): T { @@ -99,9 +99,9 @@ export function snakeKeysToCamelCase( Object.keys(obj).forEach((key) => { eventHandlers.debug?.( "loop", - `Running forEach loop in snakeKeysToCamelCase function.`, + `Running forEach loop in camelize function.`, ); - convertedObject[snakeToCamelCase(key)] = snakeKeysToCamelCase( + convertedObject[snakeToCamelCase(key)] = camelize( // deno-lint-ignore no-explicit-any (obj as Record)[key], ); @@ -109,7 +109,7 @@ export function snakeKeysToCamelCase( return convertedObject as T; } else if (Array.isArray(obj)) { - obj = obj.map((element) => snakeKeysToCamelCase(element)); + obj = obj.map((element) => camelize(element)); } return obj as T; diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index 2dee79979..33335c8da 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -4,7 +4,7 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import type { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; import type { DiscordHello } from "../types/gateway/hello.ts"; import type { DiscordReady } from "../types/gateway/ready.ts"; -import { delay, snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize, delay } from "../util/utils.ts"; import { decompressWith } from "./deps.ts"; import { identify } from "./identify.ts"; import { resume } from "./resume.ts"; @@ -128,7 +128,7 @@ export async function handleOnMessage(message: any, shardId: number) { if (!messageData.t) return; return handlers[messageData.t]?.( - snakeKeysToCamelCase(messageData), + camelize(messageData), shardId, ); } diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index 11062276f..281611bcd 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -1,6 +1,6 @@ import { DiscordGatewayIntents } from "../types/gateway/gateway_intents.ts"; import type { GetGatewayBot } from "../types/gateway/get_gateway_bot.ts"; -import { snakeKeysToCamelCase } from "../util/utils.ts"; +import { camelize } from "../util/utils.ts"; import { StartGatewayOptions } from "./start_gateway_options.ts"; import { ws } from "./ws.ts"; @@ -33,7 +33,7 @@ export async function startGateway(options: StartGatewayOptions) { 0, ); - ws.botGatewayData = snakeKeysToCamelCase( + ws.botGatewayData = camelize( await fetch(`https://discord.com/api/gateway/bot`, { headers: { Authorization: ws.identifyPayload.token }, }).then((res) => res.json()), diff --git a/tests/util/utils.ts b/tests/util/utils.ts index 4cf2ef05e..233bf229e 100644 --- a/tests/util/utils.ts +++ b/tests/util/utils.ts @@ -1,8 +1,8 @@ -import { ApplicationCommandOption } from "../../src/types/interactions/application_command_option.ts"; -import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/application_command_option_types.ts"; +import { ApplicationCommandOption } from "../../src/types/interactions/commands/application_command_option.ts"; +import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/commands/application_command_option_types.ts"; import { - camelKeysToSnakeCase, - snakeKeysToCamelCase, + camelize, + snakelize, validateSlashCommands, } from "../../src/util/utils.ts"; import { assertEquals, assertThrows } from "../deps.ts"; @@ -61,9 +61,9 @@ const someElseOther = { Deno.test({ name: "[utils] convert snake case keys to camel case", fn() { - const result = snakeKeysToCamelCase(testSnakeObject); + const result = camelize(testSnakeObject); assertEquals(result, testCamelObject); - const resultTwo = snakeKeysToCamelCase(someOther); + const resultTwo = camelize(someOther); assertEquals(resultTwo, someOther); }, }); @@ -71,9 +71,9 @@ Deno.test({ Deno.test({ name: "[utils] convert camel case keys to snake case", fn() { - const result = camelKeysToSnakeCase(testCamelObject); + const result = snakelize(testCamelObject); assertEquals(result, testSnakeObject); - const resultTwo = camelKeysToSnakeCase(someElseOther); + const resultTwo = snakelize(someElseOther); assertEquals(resultTwo, someElseOther); }, }); From 781537bd170bf35687ddd615a16a68adb9a3fb96 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:19:19 +0200 Subject: [PATCH 2/4] change this --- src/helpers/channels/update_voice_state.ts | 32 ++++++++++++++++++++++ src/helpers/mod.ts | 3 ++ 2 files changed, 35 insertions(+) create mode 100644 src/helpers/channels/update_voice_state.ts diff --git a/src/helpers/channels/update_voice_state.ts b/src/helpers/channels/update_voice_state.ts new file mode 100644 index 000000000..17ead3140 --- /dev/null +++ b/src/helpers/channels/update_voice_state.ts @@ -0,0 +1,32 @@ +import { rest } from "../../rest/rest.ts"; +import { UpdateOthersVoiceState } from "../../types/guilds/update_others_voice_state.ts"; +import type { + UpdateSelfVoiceState, +} from "../../types/guilds/update_self_voice_state.ts"; +import { endpoints } from "../../util/constants.ts"; +import { hasOwnProperty, snakelize } from "../../util/utils.ts"; + +/** + * Updates the a user's voice state, defaults to the current user + * Caveats: + * - `channel_id` must currently point to a stage channel. + * - User must already have joined `channel_id`. + * - You must have the `MUTE_MEMBERS` permission. But can always suppress yourself. + * - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not. + * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. + * - You are able to set `request_to_speak_timestamp` to any present or future time. + * - When suppressed, the user will have their `request_to_speak_timestamp` removed. + */ +export async function updateBotVoiceState( + guildId: bigint, + options: UpdateSelfVoiceState | { userId: bigint } & UpdateOthersVoiceState, +) { + return await rest.runMethod( + "patch", + endpoints.UPDATE_VOICE_STATE( + guildId, + hasOwnProperty(options, "userId") ? options.userId : undefined, + ), + snakelize(options), + ); +} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 903614119..fa610049d 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -13,6 +13,7 @@ import { getPins } from "./channels/get_pins.ts"; import { isChannelSynced } from "./channels/is_channel_synced.ts"; import { startTyping } from "./channels/start_typing.ts"; import { swapChannels } from "./channels/swap_channels.ts"; +import { updateBotVoiceState } from "./channels/update_voice_state.ts"; import { batchEditSlashCommandPermissions } from "./commands/batch_edit_slash_command_permissions.ts"; import { createSlashCommand } from "./commands/create_slash_command.ts"; import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; @@ -258,6 +259,7 @@ export { unbanMember, unpin, unpinMessage, + updateBotVoiceState, upsertSlashCommand, upsertSlashCommands, validDiscoveryTerm, @@ -279,6 +281,7 @@ export let helpers = { isChannelSynced, startTyping, swapChannels, + updateBotVoiceState, // commands createSlashCommand, deleteSlashCommand, From be3889b5b00edeb949100d7d31127d1dab5d4e14 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 20:20:50 +0200 Subject: [PATCH 3/4] rem --- src/helpers/guilds/update_bot_voice_state.ts | 26 ------------------ src/helpers/guilds/update_user_voice_state.ts | 27 ------------------- 2 files changed, 53 deletions(-) delete mode 100644 src/helpers/guilds/update_bot_voice_state.ts delete mode 100644 src/helpers/guilds/update_user_voice_state.ts diff --git a/src/helpers/guilds/update_bot_voice_state.ts b/src/helpers/guilds/update_bot_voice_state.ts deleted file mode 100644 index 8043de974..000000000 --- a/src/helpers/guilds/update_bot_voice_state.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import type { - UpdateSelfVoiceState, -} from "../../types/guilds/update_self_voice_state.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; - -/** - * Updates the current user's voice state. - * Caveats: - * - `channel_id` must currently point to a stage channel. - * - current user must already have joined `channel_id`. - * - You must have the `MUTE_MEMBERS` permission to unsuppress yourself. You can always suppress yourself. - * - You must have the `REQUEST_TO_SPEAK` permission to request to speak. You can always clear your own request to speak. - * - You are able to set `request_to_speak_timestamp` to any present or future time. - */ -export async function updateBotVoiceState( - guildId: bigint, - data: UpdateSelfVoiceState, -) { - return await rest.runMethod( - "patch", - endpoints.UPDATE_VOICE_STATE(guildId), - snakelize(data), - ); -} diff --git a/src/helpers/guilds/update_user_voice_state.ts b/src/helpers/guilds/update_user_voice_state.ts deleted file mode 100644 index 38191274b..000000000 --- a/src/helpers/guilds/update_user_voice_state.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import type { - UpdateOthersVoiceState, -} from "../../types/guilds/update_others_voice_state.ts"; -import { endpoints } from "../../util/constants.ts"; -import { snakelize } from "../../util/utils.ts"; - -/** - * Updates another user's voice state. - * Caveats: - * - `channel_id` must currently point to a stage channel. - * - User must already have joined `channel_id`. - * - You must have the `MUTE_MEMBERS` permission. (Since suppression is the only thing that is available currently.) - * - When unsuppressed, non-bot users will have their `request_to_speak_timestamp` set to the current time. Bot users will not. - * - When suppressed, the user will have their `request_to_speak_timestamp` removed. - */ -export function updateVoiceState( - guildId: bigint, - userId: bigint, - data: UpdateOthersVoiceState, -) { - return rest.runMethod( - "patch", - endpoints.UPDATE_VOICE_STATE(guildId, userId), - snakelize(data), - ); -} From 95e3c796ec5057bb407dcb1f6edbf0e8a972b659 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 21:51:02 +0200 Subject: [PATCH 4/4] remove author for better auto completion --- src/structures/message.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index 0525d254f..97bf7ff40 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -253,7 +253,6 @@ export interface DiscordenoMessage extends | "author" > { id: bigint; - author: undefined; /** Whether or not this message was sent by a bot */ isBot: boolean; /** The username#discrimnator for the user who sent this message */