mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
change: prettier code
This commit is contained in:
committed by
GitHub Action
parent
a8ccf05e8b
commit
baf8583976
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<SnakeCasedPropertiesDeep<Message>>(bot.rest,"get", bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token));
|
||||
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token)
|
||||
);
|
||||
|
||||
return bot.transformers.message(result);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user