change: prettier code

This commit is contained in:
TriForMine
2021-10-21 17:07:31 +00:00
committed by GitHub Action
parent a8ccf05e8b
commit baf8583976
16 changed files with 132 additions and 99 deletions
@@ -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
);
}
@@ -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<ApplicationCommand>(
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
);
}
@@ -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<undefined>(
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)
);
}
@@ -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<undefined>(
bot.rest,
bot.rest,
"delete",
messageId
? bot.constants.endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(bot.applicationId, token, messageId)
@@ -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,
}
);
}
@@ -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
@@ -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) {
@@ -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<GuildApplicationCommandPermissions>(
bot.rest,
bot.rest,
"get",
bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId)
);
@@ -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<GuildApplicationCommandPermissions[]>(
bot.rest,
bot.rest,
"get",
bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId)
);
@@ -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<ApplicationCommand[]>(
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),
},
])
);
}
@@ -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<ApplicationCommand>(
bot.rest,
bot.rest,
"patch",
guildId
? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId)
@@ -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<EditGlobalApplicationCommand, "name">[],
guildId?: bigint
) {
options = bot.utils.validateSlashCommands(options) as MakeRequired<EditGlobalApplicationCommand, "name">[];
return await bot.rest.runMethod<ApplicationCommand[]>(
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
);
}