From baf85839762c25bfece9e3c77a2bec103a4d29af Mon Sep 17 00:00:00 2001 From: TriForMine Date: Thu, 21 Oct 2021 17:07:31 +0000 Subject: [PATCH] change: prettier code --- .../batch_edit_slash_command_permissions.ts | 11 ++- .../commands/create_slash_command.ts | 8 +- .../commands/delete_slash_command.ts | 8 +- .../commands/delete_slash_response.ts | 4 +- .../edit_slash_command_permissions.ts | 15 ++-- .../commands/edit_slash_response.ts | 38 ++++---- .../commands/get_slash_command.ts | 2 +- .../commands/get_slash_command_permission.ts | 4 +- .../commands/get_slash_command_permissions.ts | 4 +- .../commands/get_slash_commands.ts | 14 ++- .../commands/upsert_slash_command.ts | 11 ++- .../commands/upsert_slash_commands.ts | 10 ++- .../get_original_interaction_response.ts | 10 ++- .../interactions/send_interaction_response.ts | 86 +++++++++---------- src/helpers/messages/send_message.ts | 4 +- src/helpers/webhooks/edit_webhook_message.ts | 2 +- 16 files changed, 132 insertions(+), 99 deletions(-) diff --git a/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts index 502a45933..a9682981c 100644 --- a/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/batch_edit_slash_command_permissions.ts @@ -1,11 +1,16 @@ -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.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( - bot: Bot, + bot: Bot, guildId: bigint, options: { id: string; permissions: ApplicationCommandPermissions[] }[] ) { - return await bot.rest.runMethod(bot.rest,"put", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), options); + return await bot.rest.runMethod( + bot.rest, + "put", + bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), + options + ); } diff --git a/src/helpers/interactions/commands/create_slash_command.ts b/src/helpers/interactions/commands/create_slash_command.ts index 6448fc6e7..30ce8c170 100644 --- a/src/helpers/interactions/commands/create_slash_command.ts +++ b/src/helpers/interactions/commands/create_slash_command.ts @@ -1,6 +1,6 @@ import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import type { CreateGlobalApplicationCommand } from "../../../types/interactions/commands/create_global_application_command.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.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: @@ -17,9 +17,11 @@ export async function createSlashCommand(bot: Bot, options: CreateGlobalApplicat [options] = bot.utils.validateSlashCommands([options], true) as CreateGlobalApplicationCommand[]; return await bot.rest.runMethod( - bot.rest, + bot.rest, "post", - guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId), + guildId + ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.endpoints.COMMANDS(bot.applicationId), options ); } diff --git a/src/helpers/interactions/commands/delete_slash_command.ts b/src/helpers/interactions/commands/delete_slash_command.ts index 5fb105ecc..6367deb65 100644 --- a/src/helpers/interactions/commands/delete_slash_command.ts +++ b/src/helpers/interactions/commands/delete_slash_command.ts @@ -1,10 +1,12 @@ -import type { Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** Deletes a slash command. */ export async function deleteSlashCommand(bot: Bot, id: bigint, guildId?: bigint) { return await bot.rest.runMethod( - bot.rest, + bot.rest, "delete", - guildId ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, id) : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, id) + guildId + ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, id) + : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, id) ); } diff --git a/src/helpers/interactions/commands/delete_slash_response.ts b/src/helpers/interactions/commands/delete_slash_response.ts index 70b26c320..152dba779 100644 --- a/src/helpers/interactions/commands/delete_slash_response.ts +++ b/src/helpers/interactions/commands/delete_slash_response.ts @@ -1,9 +1,9 @@ -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.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(bot: Bot, token: string, messageId?: bigint) { return await bot.rest.runMethod( - bot.rest, + bot.rest, "delete", messageId ? bot.constants.endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(bot.applicationId, token, messageId) diff --git a/src/helpers/interactions/commands/edit_slash_command_permissions.ts b/src/helpers/interactions/commands/edit_slash_command_permissions.ts index 3ccdb9e4d..0ead8eaf2 100644 --- a/src/helpers/interactions/commands/edit_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/edit_slash_command_permissions.ts @@ -1,14 +1,19 @@ import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** Edits command permissions for a specific command for your application in a guild. */ export async function editSlashCommandPermissions( - bot: Bot, + bot: Bot, guildId: bigint, commandId: bigint, options: ApplicationCommandPermissions[] ) { - return await bot.rest.runMethod(bot.rest,"put", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), { - permissions: options, - }); + return await bot.rest.runMethod( + bot.rest, + "put", + bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), + { + permissions: options, + } + ); } diff --git a/src/helpers/interactions/commands/edit_slash_response.ts b/src/helpers/interactions/commands/edit_slash_response.ts index 4cf36ffa6..c2bb4cbf2 100644 --- a/src/helpers/interactions/commands/edit_slash_response.ts +++ b/src/helpers/interactions/commands/edit_slash_response.ts @@ -1,6 +1,6 @@ import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/edit_webhook_message.ts"; -import type {Bot} from "../../../bot.ts"; -import {DiscordAllowedMentionsTypes} from "../../../types/messages/allowed_mentions_types.ts"; +import type { Bot } from "../../../bot.ts"; +import { DiscordAllowedMentionsTypes } from "../../../types/messages/allowed_mentions_types.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(bot: Bot, token: string, options: DiscordenoEditWebhookMessage) { @@ -39,26 +39,28 @@ export async function editSlashResponse(bot: Bot, token: string, options: Discor } const result = await bot.rest.runMethod( - bot.rest, + bot.rest, "patch", options.messageId ? bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, token, options.messageId) : bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token), - { - content: options.content, - embeds: options.embeds, - file: options.file, - allowed_mentions: options.allowedMentions ? { - parse: options.allowedMentions.parse, - roles: options.allowedMentions.roles, - users: options.allowedMentions.users, - replied_user: options.allowedMentions.repliedUser - } : undefined, - attachments: options.attachments, - // TODO: Snakelize components?? - components: options.components, - message_id: options.messageId, - } + { + content: options.content, + embeds: options.embeds, + file: options.file, + allowed_mentions: options.allowedMentions + ? { + parse: options.allowedMentions.parse, + roles: options.allowedMentions.roles, + users: options.allowedMentions.users, + replied_user: options.allowedMentions.repliedUser, + } + : undefined, + attachments: options.attachments, + // TODO: Snakelize components?? + components: options.components, + message_id: options.messageId, + } ); // If the original message was edited, this will not return a message diff --git a/src/helpers/interactions/commands/get_slash_command.ts b/src/helpers/interactions/commands/get_slash_command.ts index 8e0acdebf..30fba39b1 100644 --- a/src/helpers/interactions/commands/get_slash_command.ts +++ b/src/helpers/interactions/commands/get_slash_command.ts @@ -1,5 +1,5 @@ import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */ export async function getSlashCommand(bot: Bot, commandId: bigint, guildId?: bigint) { diff --git a/src/helpers/interactions/commands/get_slash_command_permission.ts b/src/helpers/interactions/commands/get_slash_command_permission.ts index 86fafe5a9..10a4c2a07 100644 --- a/src/helpers/interactions/commands/get_slash_command_permission.ts +++ b/src/helpers/interactions/commands/get_slash_command_permission.ts @@ -1,10 +1,10 @@ import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */ export async function getSlashCommandPermission(bot: Bot, guildId: bigint, commandId: bigint) { return await bot.rest.runMethod( - bot.rest, + bot.rest, "get", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId) ); diff --git a/src/helpers/interactions/commands/get_slash_command_permissions.ts b/src/helpers/interactions/commands/get_slash_command_permissions.ts index 6f7a54df1..56e0a8316 100644 --- a/src/helpers/interactions/commands/get_slash_command_permissions.ts +++ b/src/helpers/interactions/commands/get_slash_command_permissions.ts @@ -1,10 +1,10 @@ -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts"; /** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */ export async function getSlashCommandPermissions(bot: Bot, guildId: bigint) { return await bot.rest.runMethod( - bot.rest, + bot.rest, "get", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId) ); diff --git a/src/helpers/interactions/commands/get_slash_commands.ts b/src/helpers/interactions/commands/get_slash_commands.ts index cbba87954..e037ea2ac 100644 --- a/src/helpers/interactions/commands/get_slash_commands.ts +++ b/src/helpers/interactions/commands/get_slash_commands.ts @@ -1,19 +1,25 @@ import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import { Collection } from "../../../util/collection.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** Fetch all the global commands for your application. */ export async function getSlashCommands(bot: Bot, guildId?: bigint) { const result = await bot.rest.runMethod( - bot.rest, + bot.rest, "get", - guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId) + guildId + ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.endpoints.COMMANDS(bot.applicationId) ); return new Collection( result.map((command) => [ command.name, - { ...command, id: bot.transformers.snowflake(command.id), applicationId: bot.transformers.snowflake(command.applicationId) }, + { + ...command, + id: bot.transformers.snowflake(command.id), + applicationId: bot.transformers.snowflake(command.applicationId), + }, ]) ); } diff --git a/src/helpers/interactions/commands/upsert_slash_command.ts b/src/helpers/interactions/commands/upsert_slash_command.ts index 765209862..7bd3c34ba 100644 --- a/src/helpers/interactions/commands/upsert_slash_command.ts +++ b/src/helpers/interactions/commands/upsert_slash_command.ts @@ -1,15 +1,20 @@ import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** * Edit an existing slash command. If this command did not exist, it will create it. */ -export async function upsertSlashCommand(bot: Bot, commandId: bigint, options: EditGlobalApplicationCommand, guildId?: bigint) { +export async function upsertSlashCommand( + bot: Bot, + commandId: bigint, + options: EditGlobalApplicationCommand, + guildId?: bigint +) { [options] = bot.utils.validateSlashCommands([options]); return await bot.rest.runMethod( - bot.rest, + bot.rest, "patch", guildId ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId) diff --git a/src/helpers/interactions/commands/upsert_slash_commands.ts b/src/helpers/interactions/commands/upsert_slash_commands.ts index 99e32c571..f7cd4e83f 100644 --- a/src/helpers/interactions/commands/upsert_slash_commands.ts +++ b/src/helpers/interactions/commands/upsert_slash_commands.ts @@ -1,7 +1,7 @@ import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts"; import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts"; import type { MakeRequired } from "../../../types/util.ts"; -import type {Bot} from "../../../bot.ts"; +import type { Bot } from "../../../bot.ts"; /** * Bulk edit existing slash commands. If a command does not exist, it will create it. @@ -9,16 +9,18 @@ import type {Bot} from "../../../bot.ts"; * **NOTE:** Any slash commands that are not specified in this function will be **deleted**. If you don't provide the commandId and rename your command, the command gets a new Id. */ export async function upsertSlashCommands( - bot: Bot, + bot: Bot, options: MakeRequired[], guildId?: bigint ) { options = bot.utils.validateSlashCommands(options) as MakeRequired[]; return await bot.rest.runMethod( - bot.rest, + bot.rest, "put", - guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId), + guildId + ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) + : bot.constants.endpoints.COMMANDS(bot.applicationId), options ); } diff --git a/src/helpers/interactions/get_original_interaction_response.ts b/src/helpers/interactions/get_original_interaction_response.ts index d2a0ee7e3..83cc029ae 100644 --- a/src/helpers/interactions/get_original_interaction_response.ts +++ b/src/helpers/interactions/get_original_interaction_response.ts @@ -1,10 +1,14 @@ -import type {Bot} from "../../bot.ts"; +import type { Bot } from "../../bot.ts"; import type { Message } from "../../types/messages/message.ts"; -import type {SnakeCasedPropertiesDeep} from "../../types/util.ts"; +import type { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Returns the initial Interaction response. Functions the same as Get Webhook Message */ export async function getOriginalInteractionResponse(bot: Bot, token: string) { - const result = await bot.rest.runMethod>(bot.rest,"get", bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token)); + const result = await bot.rest.runMethod>( + bot.rest, + "get", + bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token) + ); return bot.transformers.message(result); } diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 006f96ea7..335fdc0d2 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -1,10 +1,10 @@ import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts"; -import type {Bot} from "../../bot.ts"; -import {Embed} from "../../types/embeds/embed.ts"; -import {AllowedMentions} from "../../types/messages/allowed_mentions.ts"; -import {MessageReference} from "../../types/messages/message_reference.ts"; -import {FileContent} from "../../types/discordeno/file_content.ts"; -import {MessageComponents} from "../../types/messages/components/message_components.ts"; +import type { Bot } from "../../bot.ts"; +import { Embed } from "../../types/embeds/embed.ts"; +import { AllowedMentions } from "../../types/messages/allowed_mentions.ts"; +import { MessageReference } from "../../types/messages/message_reference.ts"; +import { FileContent } from "../../types/discordeno/file_content.ts"; +import { MessageComponents } from "../../types/messages/components/message_components.ts"; // TODO: v12 remove | string /** @@ -14,10 +14,10 @@ import {MessageComponents} from "../../types/messages/components/message_compone * NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object. */ export async function sendInteractionResponse( - bot: Bot, - id: bigint | string, - token: string, - options: DiscordenoInteractionResponse + bot: Bot, + id: bigint | string, + token: string, + options: DiscordenoInteractionResponse ) { // TODO: add more options validations if (options.data?.components) bot.utils.validateComponents(bot, options.data?.components); @@ -34,7 +34,7 @@ export async function sendInteractionResponse( // If its already been executed, we need to send a followup response if (bot.cache.executedSlashCommands.has(token)) { - return await bot.rest.runMethod(bot.rest,"post", bot.cosntants.endpoints.WEBHOOK(bot.applicationId, token), { + return await bot.rest.runMethod(bot.rest, "post", bot.cosntants.endpoints.WEBHOOK(bot.applicationId, token), { content: options.data.content, tts: options.data.tts, embeds: options.data.embeds, @@ -42,10 +42,10 @@ export async function sendInteractionResponse( parse: options.data.allowedMentions.parse, roles: options.data.allowedMentions.roles, users: options.data.allowedMentions.users, - replied_user: options.data.allowedMentions.repliedUser + replied_user: options.data.allowedMentions.repliedUser, }, ...(options.data.messageReference?.messageId - ? { + ? { message_reference: { message_id: options.data.messageReference.messageId, channel_id: options.data.messageReference.channelId, @@ -53,11 +53,11 @@ export async function sendInteractionResponse( fail_if_not_exists: options.data.messageReference.failIfNotExists === true, }, } - : {}), + : {}), file: options.data.file, // TODO: Snakelize components?? components: options.data.components, - flags: options.data.flags + flags: options.data.flags, }); } @@ -69,33 +69,33 @@ export async function sendInteractionResponse( }, 900000); return await bot.rest.runMethod( - bot.rest, - "post", - bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token), - { - content: options.data.content, - tts: options.data.tts, - embeds: options.data.embeds, - allowed_mentions: { - parse: options.data.allowedMentions.parse, - roles: options.data.allowedMentions.roles, - users: options.data.allowedMentions.users, - replied_user: options.data.allowedMentions.repliedUser - }, - ...(options.data.messageReference?.messageId - ? { - message_reference: { - message_id: options.data.messageReference.messageId, - channel_id: options.data.messageReference.channelId, - guild_id: options.data.messageReference.guildId, - fail_if_not_exists: options.data.messageReference.failIfNotExists === true, - }, - } - : {}), - file: options.data.file, - // TODO: Snakelize components?? - components: options.data.components, - flags: options.data.flags - } + bot.rest, + "post", + bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token), + { + content: options.data.content, + tts: options.data.tts, + embeds: options.data.embeds, + allowed_mentions: { + parse: options.data.allowedMentions.parse, + roles: options.data.allowedMentions.roles, + users: options.data.allowedMentions.users, + replied_user: options.data.allowedMentions.repliedUser, + }, + ...(options.data.messageReference?.messageId + ? { + message_reference: { + message_id: options.data.messageReference.messageId, + channel_id: options.data.messageReference.channelId, + guild_id: options.data.messageReference.guildId, + fail_if_not_exists: options.data.messageReference.failIfNotExists === true, + }, + } + : {}), + file: options.data.file, + // TODO: Snakelize components?? + components: options.data.components, + flags: options.data.flags, + } ); } diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index fcde4b26b..c9e0f5b99 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -74,7 +74,7 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | } const result = await bot.rest.runMethod>( - bot.rest, + bot.rest, "post", bot.constants.endpoints.CHANNEL_MESSAGES(channelId), bot.utils.snakelize({ @@ -85,7 +85,7 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | parse: content.allowedMentions.parse, roles: content.allowedMentions.roles, users: content.allowedMentions.users, - replied_user: content.allowedMentions.repliedUser + replied_user: content.allowedMentions.repliedUser, }, file: content.file, // TODO: Snakelize components?? diff --git a/src/helpers/webhooks/edit_webhook_message.ts b/src/helpers/webhooks/edit_webhook_message.ts index 4ffd8e84e..16760855c 100644 --- a/src/helpers/webhooks/edit_webhook_message.ts +++ b/src/helpers/webhooks/edit_webhook_message.ts @@ -58,7 +58,7 @@ export async function editWebhookMessage( parse: content.allowedMentions.parse, roles: content.allowedMentions.roles, users: content.allowedMentions.users, - replied_user: content.allowedMentions.repliedUser + replied_user: content.allowedMentions.repliedUser, }, attachments: options.attachments, // TODO: Snakelize components??