mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Prettified Code!
This commit is contained in:
@@ -9,9 +9,5 @@ export async function batchEditSlashCommandPermissions(
|
||||
guildId: bigint,
|
||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
snakelize(options)
|
||||
);
|
||||
return await rest.runMethod("put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), snakelize(options));
|
||||
}
|
||||
|
||||
@@ -16,17 +16,12 @@ import { snakelize, validateSlashCommands } from "../../../util/utils.ts";
|
||||
* Global commands are cached for **1 hour**. That means that new global commands will fan out slowly across all guilds, and will be guaranteed to be updated in an hour.
|
||||
* Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.
|
||||
*/
|
||||
export async function createSlashCommand(
|
||||
options: CreateGlobalApplicationCommand,
|
||||
guildId?: bigint
|
||||
) {
|
||||
export async function createSlashCommand(options: CreateGlobalApplicationCommand, guildId?: bigint) {
|
||||
validateSlashCommands([options], true);
|
||||
|
||||
return await rest.runMethod<ApplicationCommand>(
|
||||
"post",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId),
|
||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import { endpoints } from "../../../util/constants.ts";
|
||||
export async function deleteSlashCommand(id: bigint, guildId?: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id)
|
||||
: endpoints.COMMANDS_ID(applicationId, id)
|
||||
guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id) : endpoints.COMMANDS_ID(applicationId, id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,7 @@ export async function deleteSlashResponse(token: string, messageId?: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
messageId
|
||||
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(
|
||||
applicationId,
|
||||
token,
|
||||
messageId
|
||||
)
|
||||
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(applicationId, token, messageId)
|
||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ export async function editSlashCommandPermissions(
|
||||
commandId: bigint,
|
||||
options: ApplicationCommandPermissions[]
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
{ permissions: snakelize(options) }
|
||||
);
|
||||
return await rest.runMethod("put", endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), {
|
||||
permissions: snakelize(options),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import { DiscordAllowedMentionsTypes } from "../../../types/messages/allowed_men
|
||||
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(
|
||||
token: string,
|
||||
options: DiscordenoEditWebhookMessage
|
||||
) {
|
||||
export async function editSlashResponse(token: string, options: DiscordenoEditWebhookMessage) {
|
||||
if (options.content && options.content.length > 2000) {
|
||||
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
||||
}
|
||||
@@ -21,40 +18,22 @@ export async function editSlashResponse(
|
||||
|
||||
if (options.allowedMentions) {
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||
(p) => p !== "users"
|
||||
);
|
||||
if (options.allowedMentions.parse?.includes(DiscordAllowedMentionsTypes.UserMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100
|
||||
);
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.RoleMentions
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||
(p) => p !== "roles"
|
||||
);
|
||||
if (options.allowedMentions.parse?.includes(DiscordAllowedMentionsTypes.RoleMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100
|
||||
);
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ import type { GuildApplicationCommandPermissions } from "../../../types/interact
|
||||
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(
|
||||
guildId: bigint,
|
||||
commandId: bigint
|
||||
) {
|
||||
export async function getSlashCommandPermission(guildId: bigint, commandId: bigint) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId)
|
||||
|
||||
@@ -8,9 +8,7 @@ import { endpoints } from "../../../util/constants.ts";
|
||||
export async function getSlashCommands(guildId?: bigint) {
|
||||
const result = await rest.runMethod<ApplicationCommand[]>(
|
||||
"get",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId)
|
||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId)
|
||||
);
|
||||
|
||||
return new Collection(result.map((command) => [command.name, command]));
|
||||
|
||||
@@ -8,11 +8,7 @@ import { validateSlashCommands } from "../../../util/utils.ts";
|
||||
/**
|
||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
||||
*/
|
||||
export async function upsertSlashCommand(
|
||||
commandId: bigint,
|
||||
options: EditGlobalApplicationCommand,
|
||||
guildId?: bigint
|
||||
) {
|
||||
export async function upsertSlashCommand(commandId: bigint, options: EditGlobalApplicationCommand, guildId?: bigint) {
|
||||
validateSlashCommands([options]);
|
||||
|
||||
return await rest.runMethod<ApplicationCommand>(
|
||||
|
||||
@@ -10,17 +10,12 @@ import { validateSlashCommands } from "../../../util/utils.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(
|
||||
options: EditGlobalApplicationCommand[],
|
||||
guildId?: bigint
|
||||
) {
|
||||
export async function upsertSlashCommands(options: EditGlobalApplicationCommand[], guildId?: bigint) {
|
||||
validateSlashCommands(options);
|
||||
|
||||
return await rest.runMethod<ApplicationCommand[]>(
|
||||
"put",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId),
|
||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the initial Interactio response. Functions the same as Get Webhook Message */
|
||||
export async function getOriginalInteractionResponse(token: string) {
|
||||
const result = await rest.runMethod<Message>(
|
||||
"get",
|
||||
endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
||||
);
|
||||
const result = await rest.runMethod<Message>("get", endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token));
|
||||
|
||||
return await structures.createDiscordenoMessage(result);
|
||||
}
|
||||
|
||||
@@ -11,31 +11,20 @@ import { validateComponents } from "../../util/utils.ts";
|
||||
*
|
||||
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
|
||||
*/
|
||||
export async function sendInteractionResponse(
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: DiscordenoInteractionResponse
|
||||
) {
|
||||
export async function sendInteractionResponse(id: bigint, token: string, options: DiscordenoInteractionResponse) {
|
||||
// TODO: add more options validations
|
||||
if (options.data?.components) validateComponents(options.data?.components);
|
||||
// If its already been executed, we need to send a followup response
|
||||
if (cache.executedSlashCommands.has(token)) {
|
||||
return await rest.runMethod(
|
||||
"post",
|
||||
endpoints.WEBHOOK(applicationId, token),
|
||||
{
|
||||
...options,
|
||||
}
|
||||
);
|
||||
return await rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), {
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
// Expire in 15 minutes
|
||||
cache.executedSlashCommands.add(token);
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running setTimeout in send_interaction_response file.`
|
||||
);
|
||||
eventHandlers.debug?.("loop", `Running setTimeout in send_interaction_response file.`);
|
||||
cache.executedSlashCommands.delete(token);
|
||||
}, 900000);
|
||||
|
||||
@@ -49,9 +38,5 @@ export async function sendInteractionResponse(
|
||||
options.data = { ...options.data, allowedMentions: { parse: [] } };
|
||||
}
|
||||
|
||||
return await rest.runMethod(
|
||||
"post",
|
||||
endpoints.INTERACTION_ID_TOKEN(id, token),
|
||||
options
|
||||
);
|
||||
return await rest.runMethod("post", endpoints.INTERACTION_ID_TOKEN(id, token), options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user