Merge branch 'main' into test-utils

This commit is contained in:
rigormorrtiss
2021-05-06 12:34:27 +04:00
committed by GitHub
114 changed files with 296 additions and 298 deletions

View File

@@ -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 = {

View File

@@ -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,

View File

@@ -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?.(

View File

@@ -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?.(

View File

@@ -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(

View File

@@ -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,

View File

@@ -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?.(

View File

@@ -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?.(

View File

@@ -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) {

View File

@@ -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";

View File

@@ -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<MessageReactionAdd>(payload),
payload,
message,
);
}

View File

@@ -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) {

View File

@@ -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<DiscordCreateGuildChannel>(options ?? {}),
...snakelize<DiscordCreateGuildChannel>(options ?? {}),
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
...perm,
allow: calculateBits(perm.allow),

View File

@@ -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<Record<string, unknown>>(options),
...snakelize<Record<string, unknown>>(options),
// deno-lint-ignore camelcase
permission_overwrites:
hasOwnProperty<ModifyChannel>(options, "permissionOverwrites")

View File

@@ -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 ?? {}),
);
}

View File

@@ -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),
);
}

View File

@@ -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),
);
}

View File

@@ -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) },
);
}

View File

@@ -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<DiscoveryMetadata>(
"patch",
endpoints.DISCOVERY_MODIFY(guildId),
camelKeysToSnakeCase(data),
snakelize(data),
);
}

View File

@@ -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<WelcomeScreen>(
"patch",
endpoints.GUILD_WELCOME_SCREEN(guildId),
camelKeysToSnakeCase(options),
snakelize(options),
);
}

View File

@@ -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<AuditLog>(
"get",
endpoints.GUILD_AUDIT_LOGS(guildId),
camelKeysToSnakeCase({
snakelize({
...options,
limit: options.limit && options.limit >= 1 && options.limit <= 100
? options.limit

View File

@@ -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;

View File

@@ -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 { camelKeysToSnakeCase } 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),
camelKeysToSnakeCase(data),
);
}

View File

@@ -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 { camelKeysToSnakeCase } 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),
camelKeysToSnakeCase(data),
);
}

View File

@@ -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";

View File

@@ -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),
);
}

View File

@@ -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),
);
}

View File

@@ -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(

View File

@@ -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(

View File

@@ -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) },
);
}

View File

@@ -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(

View File

@@ -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) {

View File

@@ -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(

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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.

View File

@@ -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.

View File

@@ -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<Invite>(
"get",
endpoints.INVITE(inviteCode),
camelKeysToSnakeCase(options ?? {}),
snakelize(options ?? {}),
);
}

View File

@@ -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<undefined>(
"put",
endpoints.GUILD_BAN(guildId, id),
camelKeysToSnakeCase(options),
snakelize(options),
);
}

View File

@@ -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<GuildMemberWithUser>(
"patch",
endpoints.GUILD_MEMBER(guildId, memberId),
camelKeysToSnakeCase({
snakelize({
...options,
channelId: options.channelId
? bigintToSnowflake(options.channelId)

View File

@@ -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";

View File

@@ -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.

View File

@@ -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";

View File

@@ -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;

View File

@@ -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";

View File

@@ -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<Message>(
"post",
endpoints.CHANNEL_MESSAGES(channelId),
camelKeysToSnakeCase({
snakelize({
...content,
...(content.messageReference?.messageId
? {

View File

@@ -13,20 +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 { 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 { updateBotVoiceState } from "./channels/update_voice_state.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 +49,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 +72,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 +96,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";
@@ -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,

View File

@@ -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<T = any>(
method,
reject,
respond: (data: { status: number; body?: string }) =>
resolve(snakeKeysToCamelCase<T>(JSON.parse(data.body || "{}"))),
resolve(camelize<T>(JSON.parse(data.body || "{}"))),
},
{
bucketId,

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";
@@ -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 */

View File

@@ -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";

View File

@@ -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";

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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 */

View File

@@ -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";

View File

@@ -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 {

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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 {

View File

@@ -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 */

View File

@@ -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 {

View File

@@ -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 {

Some files were not shown because too many files have changed in this diff Show More