mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Prettified Code!
This commit is contained in:
@@ -7,11 +7,11 @@ 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(
|
||||
guildId: bigint,
|
||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[],
|
||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { snakelize, validateSlashCommands } from "../../../util/utils.ts";
|
||||
*/
|
||||
export async function createSlashCommand(
|
||||
options: CreateGlobalApplicationCommand,
|
||||
guildId?: bigint,
|
||||
guildId?: bigint
|
||||
) {
|
||||
validateSlashCommands([options], true);
|
||||
|
||||
@@ -27,6 +27,6 @@ export async function createSlashCommand(
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId),
|
||||
snakelize(options),
|
||||
snakelize(options)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,11 @@ import { rest } from "../../../rest/rest.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
|
||||
/** Deletes a slash command. */
|
||||
export async function deleteSlashCommand(
|
||||
id: bigint,
|
||||
guildId?: bigint,
|
||||
) {
|
||||
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),
|
||||
: endpoints.COMMANDS_ID(applicationId, id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,15 @@ 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(
|
||||
token: string,
|
||||
messageId?: bigint,
|
||||
) {
|
||||
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_ORIGINAL_ID_TOKEN(applicationId, token),
|
||||
applicationId,
|
||||
token,
|
||||
messageId
|
||||
)
|
||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import { snakelize } from "../../../util/utils.ts";
|
||||
export async function editSlashCommandPermissions(
|
||||
guildId: bigint,
|
||||
commandId: bigint,
|
||||
options: ApplicationCommandPermissions[],
|
||||
options: ApplicationCommandPermissions[]
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
"put",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
{ permissions: snakelize(options) },
|
||||
{ permissions: snakelize(options) }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ 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,
|
||||
options: DiscordenoEditWebhookMessage
|
||||
) {
|
||||
if (options.content && options.content.length > 2000) {
|
||||
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
||||
@@ -23,18 +23,18 @@ export async function editSlashResponse(
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions,
|
||||
DiscordAllowedMentionsTypes.UserMentions
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||
(p) => p !== "users",
|
||||
(p) => p !== "users"
|
||||
);
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100,
|
||||
100
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -42,18 +42,18 @@ export async function editSlashResponse(
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.RoleMentions,
|
||||
DiscordAllowedMentionsTypes.RoleMentions
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter(
|
||||
(p) => p !== "roles",
|
||||
(p) => p !== "roles"
|
||||
);
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100,
|
||||
100
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,14 +64,12 @@ export async function editSlashResponse(
|
||||
options.messageId
|
||||
? endpoints.WEBHOOK_MESSAGE(applicationId, token, options.messageId)
|
||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
|
||||
options,
|
||||
options
|
||||
);
|
||||
|
||||
// If the original message was edited, this will not return a message
|
||||
if (!options.messageId) return result as undefined;
|
||||
|
||||
const message = await structures.createDiscordenoMessage(
|
||||
result,
|
||||
);
|
||||
const message = await structures.createDiscordenoMessage(result);
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ export async function getSlashCommand(commandId: bigint, guildId?: bigint) {
|
||||
"get",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
||||
: endpoints.COMMANDS_ID(applicationId, commandId),
|
||||
: endpoints.COMMANDS_ID(applicationId, commandId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ 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,
|
||||
commandId: bigint
|
||||
) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId),
|
||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ import { endpoints } from "../../../util/constants.ts";
|
||||
export async function getSlashCommandPermissions(guildId: bigint) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions[]>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function getSlashCommands(guildId?: bigint) {
|
||||
"get",
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId),
|
||||
: endpoints.COMMANDS(applicationId)
|
||||
);
|
||||
|
||||
return new Collection(result.map((command) => [command.name, command]));
|
||||
|
||||
@@ -11,7 +11,7 @@ import { validateSlashCommands } from "../../../util/utils.ts";
|
||||
export async function upsertSlashCommand(
|
||||
commandId: bigint,
|
||||
options: EditGlobalApplicationCommand,
|
||||
guildId?: bigint,
|
||||
guildId?: bigint
|
||||
) {
|
||||
validateSlashCommands([options]);
|
||||
|
||||
@@ -20,6 +20,6 @@ export async function upsertSlashCommand(
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
||||
: endpoints.COMMANDS_ID(applicationId, commandId),
|
||||
options,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import { validateSlashCommands } from "../../../util/utils.ts";
|
||||
*/
|
||||
export async function upsertSlashCommands(
|
||||
options: EditGlobalApplicationCommand[],
|
||||
guildId?: bigint,
|
||||
guildId?: bigint
|
||||
) {
|
||||
validateSlashCommands(options);
|
||||
|
||||
@@ -21,6 +21,6 @@ export async function upsertSlashCommands(
|
||||
guildId
|
||||
? endpoints.COMMANDS_GUILD(applicationId, guildId)
|
||||
: endpoints.COMMANDS(applicationId),
|
||||
options,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function getOriginalInteractionResponse(token: string) {
|
||||
const result = await rest.runMethod<Message>(
|
||||
"get",
|
||||
endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
|
||||
endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
||||
);
|
||||
|
||||
return await structures.createDiscordenoMessage(result);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { validateComponents } from "../../util/utils.ts";
|
||||
export async function sendInteractionResponse(
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: DiscordenoInteractionResponse,
|
||||
options: DiscordenoInteractionResponse
|
||||
) {
|
||||
// TODO: add more options validations
|
||||
if (options.data?.components) validateComponents(options.data?.components);
|
||||
@@ -25,7 +25,7 @@ export async function sendInteractionResponse(
|
||||
endpoints.WEBHOOK(applicationId, token),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function sendInteractionResponse(
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running setTimeout in send_interaction_response file.`,
|
||||
`Running setTimeout in send_interaction_response file.`
|
||||
);
|
||||
cache.executedSlashCommands.delete(token);
|
||||
}, 900000);
|
||||
@@ -52,6 +52,6 @@ export async function sendInteractionResponse(
|
||||
return await rest.runMethod(
|
||||
"post",
|
||||
endpoints.INTERACTION_ID_TOKEN(id, token),
|
||||
options,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user