mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Interactions helpers
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
|
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
|
||||||
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`. */
|
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
|
||||||
export async function batchEditSlashCommandPermissions(
|
export async function batchEditSlashCommandPermissions(
|
||||||
|
bot: Bot,
|
||||||
guildId: bigint,
|
guildId: bigint,
|
||||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
options: { id: string; permissions: ApplicationCommandPermissions[] }[]
|
||||||
) {
|
) {
|
||||||
return await rest.runMethod("put", endpoints.COMMANDS_PERMISSIONS(applicationId, guildId), snakelize(options));
|
return await bot.rest.runMethod(bot.rest,"put", bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId), options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
||||||
import type { CreateGlobalApplicationCommand } from "../../../types/interactions/commands/create_global_application_command.ts";
|
import type { CreateGlobalApplicationCommand } from "../../../types/interactions/commands/create_global_application_command.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { snakelize, validateSlashCommands } from "../../../util/utils.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:
|
* 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:
|
||||||
@@ -16,12 +13,13 @@ 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.
|
* 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.
|
* 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(bot: Bot, options: CreateGlobalApplicationCommand, guildId?: bigint) {
|
||||||
[options] = validateSlashCommands([options], true) as CreateGlobalApplicationCommand[];
|
[options] = bot.utils.validateSlashCommands([options], true) as CreateGlobalApplicationCommand[];
|
||||||
|
|
||||||
return await rest.runMethod<ApplicationCommand>(
|
return await bot.rest.runMethod<ApplicationCommand>(
|
||||||
|
bot.rest,
|
||||||
"post",
|
"post",
|
||||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
|
guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId),
|
||||||
snakelize(options)
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
import type { Bot} from "../../../bot.ts";
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
|
||||||
|
|
||||||
/** Deletes a slash command. */
|
/** Deletes a slash command. */
|
||||||
export async function deleteSlashCommand(id: bigint, guildId?: bigint) {
|
export async function deleteSlashCommand(bot: Bot, id: bigint, guildId?: bigint) {
|
||||||
return await rest.runMethod<undefined>(
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
"delete",
|
"delete",
|
||||||
guildId ? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id) : endpoints.COMMANDS_ID(applicationId, id)
|
guildId ? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, id) : bot.constants.endpoints.COMMANDS_ID(bot.applicationId, id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
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. */
|
/** 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(bot: Bot, token: string, messageId?: bigint) {
|
||||||
return await rest.runMethod<undefined>(
|
return await bot.rest.runMethod<undefined>(
|
||||||
|
bot.rest,
|
||||||
"delete",
|
"delete",
|
||||||
messageId
|
messageId
|
||||||
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(applicationId, token, messageId)
|
? bot.constants.endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(bot.applicationId, token, messageId)
|
||||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token)
|
: bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
|
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/application_command_permissions.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { snakelize } from "../../../util/utils.ts";
|
|
||||||
|
|
||||||
/** Edits command permissions for a specific command for your application in a guild. */
|
/** Edits command permissions for a specific command for your application in a guild. */
|
||||||
export async function editSlashCommandPermissions(
|
export async function editSlashCommandPermissions(
|
||||||
|
bot: Bot,
|
||||||
guildId: bigint,
|
guildId: bigint,
|
||||||
commandId: bigint,
|
commandId: bigint,
|
||||||
options: ApplicationCommandPermissions[]
|
options: ApplicationCommandPermissions[]
|
||||||
) {
|
) {
|
||||||
return await rest.runMethod("put", endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId), {
|
return await bot.rest.runMethod(bot.rest,"put", bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId), {
|
||||||
permissions: snakelize(options),
|
permissions: options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import { structures } from "../../../structures/mod.ts";
|
|
||||||
import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/edit_webhook_message.ts";
|
import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/edit_webhook_message.ts";
|
||||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { DiscordAllowedMentionsTypes } from "../../../types/messages/allowed_mentions_types.ts";
|
import {DiscordAllowedMentionsTypes} from "../../../types/messages/allowed_mentions_types.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
|
||||||
import { snakelize, validateComponents } from "../../../util/utils.ts";
|
|
||||||
|
|
||||||
/** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */
|
/** 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(bot: Bot, token: string, options: DiscordenoEditWebhookMessage) {
|
||||||
if (options.content && options.content.length > 2000) {
|
if (options.content && options.content.length > 2000) {
|
||||||
throw Error(Errors.MESSAGE_MAX_LENGTH);
|
throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.components?.length) {
|
if (options.components?.length) {
|
||||||
validateComponents(options.components);
|
bot.utils.validateComponents(bot, options.components);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.embeds && options.embeds.length > 10) {
|
if (options.embeds && options.embeds.length > 10) {
|
||||||
@@ -43,17 +38,31 @@ export async function editSlashResponse(token: string, options: DiscordenoEditWe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
const result = await bot.rest.runMethod(
|
||||||
|
bot.rest,
|
||||||
"patch",
|
"patch",
|
||||||
options.messageId
|
options.messageId
|
||||||
? endpoints.WEBHOOK_MESSAGE(applicationId, token, options.messageId)
|
? bot.constants.endpoints.WEBHOOK_MESSAGE(bot.applicationId, token, options.messageId)
|
||||||
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
|
: bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token),
|
||||||
snakelize(options)
|
{
|
||||||
|
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
|
// If the original message was edited, this will not return a message
|
||||||
if (!options.messageId) return result as undefined;
|
if (!options.messageId) return result as undefined;
|
||||||
|
|
||||||
const message = await structures.createDiscordenoMessage(result);
|
return bot.transformers.message(result);
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
||||||
import { snowflakeToBigint } from "../../../util/bigint.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
|
||||||
|
|
||||||
/** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
|
/** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
|
||||||
export async function getSlashCommand(commandId: bigint, guildId?: bigint) {
|
export async function getSlashCommand(bot: Bot, commandId: bigint, guildId?: bigint) {
|
||||||
const result = await rest.runMethod<ApplicationCommand>(
|
const result = await bot.rest.runMethod<ApplicationCommand>(
|
||||||
"get",
|
"get",
|
||||||
guildId
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId)
|
||||||
: endpoints.COMMANDS_ID(applicationId, commandId)
|
: bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId)
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
id: snowflakeToBigint(result.id),
|
id: bot.transformers.snowflake(result.id),
|
||||||
applicationId: snowflakeToBigint(result.applicationId),
|
applicationId: bot.transformers.snowflake(result.applicationId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
|
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
|
|
||||||
/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */
|
/** 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(bot: Bot, guildId: bigint, commandId: bigint) {
|
||||||
return await rest.runMethod<GuildApplicationCommandPermissions>(
|
return await bot.rest.runMethod<GuildApplicationCommandPermissions>(
|
||||||
|
bot.rest,
|
||||||
"get",
|
"get",
|
||||||
endpoints.COMMANDS_PERMISSION(applicationId, guildId, commandId)
|
bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
|
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guild_application_command_permissions.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
|
||||||
|
|
||||||
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
|
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
|
||||||
export async function getSlashCommandPermissions(guildId: bigint) {
|
export async function getSlashCommandPermissions(bot: Bot, guildId: bigint) {
|
||||||
return await rest.runMethod<GuildApplicationCommandPermissions[]>(
|
return await bot.rest.runMethod<GuildApplicationCommandPermissions[]>(
|
||||||
|
bot.rest,
|
||||||
"get",
|
"get",
|
||||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId)
|
bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
||||||
import { snowflakeToBigint } from "../../../util/bigint.ts";
|
|
||||||
import { Collection } from "../../../util/collection.ts";
|
import { Collection } from "../../../util/collection.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
|
|
||||||
/** Fetch all of the global commands for your application. */
|
/** Fetch all the global commands for your application. */
|
||||||
export async function getSlashCommands(guildId?: bigint) {
|
export async function getSlashCommands(bot: Bot, guildId?: bigint) {
|
||||||
const result = await rest.runMethod<ApplicationCommand[]>(
|
const result = await bot.rest.runMethod<ApplicationCommand[]>(
|
||||||
|
bot.rest,
|
||||||
"get",
|
"get",
|
||||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId)
|
guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
result.map((command) => [
|
result.map((command) => [
|
||||||
command.name,
|
command.name,
|
||||||
{ ...command, id: snowflakeToBigint(command.id), applicationId: snowflakeToBigint(command.applicationId) },
|
{ ...command, id: bot.transformers.snowflake(command.id), applicationId: bot.transformers.snowflake(command.applicationId) },
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
||||||
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts";
|
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { validateSlashCommands } from "../../../util/utils.ts";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
* 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(bot: Bot, commandId: bigint, options: EditGlobalApplicationCommand, guildId?: bigint) {
|
||||||
[options] = validateSlashCommands([options]);
|
[options] = bot.utils.validateSlashCommands([options]);
|
||||||
|
|
||||||
return await rest.runMethod<ApplicationCommand>(
|
return await bot.rest.runMethod<ApplicationCommand>(
|
||||||
|
bot.rest,
|
||||||
"patch",
|
"patch",
|
||||||
guildId
|
guildId
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
|
? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId)
|
||||||
: endpoints.COMMANDS_ID(applicationId, commandId),
|
: bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId),
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { applicationId } from "../../../bot.ts";
|
|
||||||
import { rest } from "../../../rest/rest.ts";
|
|
||||||
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
import type { ApplicationCommand } from "../../../types/interactions/commands/application_command.ts";
|
||||||
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts";
|
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/edit_global_application_command.ts";
|
||||||
import { MakeRequired } from "../../../types/util.ts";
|
import type { MakeRequired } from "../../../types/util.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import type {Bot} from "../../../bot.ts";
|
||||||
import { validateSlashCommands } from "../../../util/utils.ts";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk edit existing slash commands. If a command does not exist, it will create it.
|
* Bulk edit existing slash commands. If a command does not exist, it will create it.
|
||||||
@@ -12,14 +9,16 @@ 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.
|
* **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(
|
export async function upsertSlashCommands(
|
||||||
|
bot: Bot,
|
||||||
options: MakeRequired<EditGlobalApplicationCommand, "name">[],
|
options: MakeRequired<EditGlobalApplicationCommand, "name">[],
|
||||||
guildId?: bigint
|
guildId?: bigint
|
||||||
) {
|
) {
|
||||||
options = validateSlashCommands(options) as MakeRequired<EditGlobalApplicationCommand, "name">[];
|
options = bot.utils.validateSlashCommands(options) as MakeRequired<EditGlobalApplicationCommand, "name">[];
|
||||||
|
|
||||||
return await rest.runMethod<ApplicationCommand[]>(
|
return await bot.rest.runMethod<ApplicationCommand[]>(
|
||||||
|
bot.rest,
|
||||||
"put",
|
"put",
|
||||||
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
|
guildId ? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId) : bot.constants.endpoints.COMMANDS(bot.applicationId),
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { applicationId } from "../../bot.ts";
|
import type {Bot} from "../../bot.ts";
|
||||||
import { rest } from "../../rest/rest.ts";
|
|
||||||
import { structures } from "../../structures/mod.ts";
|
|
||||||
import type { Message } from "../../types/messages/message.ts";
|
import type { Message } from "../../types/messages/message.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import type {SnakeCasedPropertiesDeep} from "../../types/util.ts";
|
||||||
|
|
||||||
/** Returns the initial Interactio response. Functions the same as Get Webhook Message */
|
/** Returns the initial Interaction response. Functions the same as Get Webhook Message */
|
||||||
export async function getOriginalInteractionResponse(token: string) {
|
export async function getOriginalInteractionResponse(bot: Bot, token: string) {
|
||||||
const result = await rest.runMethod<Message>("get", endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token));
|
const result = await bot.rest.runMethod<SnakeCasedPropertiesDeep<Message>>(bot.rest,"get", bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token));
|
||||||
|
|
||||||
return await structures.createDiscordenoMessage(result);
|
return bot.transformers.message(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { applicationId, eventHandlers } from "../../bot.ts";
|
|
||||||
import { cache } from "../../cache.ts";
|
|
||||||
import { rest } from "../../rest/rest.ts";
|
|
||||||
import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts";
|
import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import type {Bot} from "../../bot.ts";
|
||||||
import { snakelize, validateComponents } from "../../util/utils.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
|
// TODO: v12 remove | string
|
||||||
/**
|
/**
|
||||||
@@ -13,12 +14,13 @@ import { snakelize, validateComponents } from "../../util/utils.ts";
|
|||||||
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
|
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
|
||||||
*/
|
*/
|
||||||
export async function sendInteractionResponse(
|
export async function sendInteractionResponse(
|
||||||
|
bot: Bot,
|
||||||
id: bigint | string,
|
id: bigint | string,
|
||||||
token: string,
|
token: string,
|
||||||
options: DiscordenoInteractionResponse
|
options: DiscordenoInteractionResponse
|
||||||
) {
|
) {
|
||||||
// TODO: add more options validations
|
// TODO: add more options validations
|
||||||
if (options.data?.components) validateComponents(options.data?.components);
|
if (options.data?.components) bot.utils.validateComponents(bot, options.data?.components);
|
||||||
|
|
||||||
// If the user wants this as a private message mark it ephemeral
|
// If the user wants this as a private message mark it ephemeral
|
||||||
if (options.private) {
|
if (options.private) {
|
||||||
@@ -31,8 +33,32 @@ export async function sendInteractionResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If its already been executed, we need to send a followup response
|
// If its already been executed, we need to send a followup response
|
||||||
if (cache.executedSlashCommands.has(token)) {
|
if (bot.cache.executedSlashCommands.has(token)) {
|
||||||
return await rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), snakelize(options.data));
|
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,
|
||||||
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expire in 15 minutes
|
// Expire in 15 minutes
|
||||||
@@ -42,9 +68,34 @@ export async function sendInteractionResponse(
|
|||||||
cache.executedSlashCommands.delete(token);
|
cache.executedSlashCommands.delete(token);
|
||||||
}, 900000);
|
}, 900000);
|
||||||
|
|
||||||
return await rest.runMethod(
|
return await bot.rest.runMethod(
|
||||||
|
bot.rest,
|
||||||
"post",
|
"post",
|
||||||
endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : BigInt(id), token),
|
bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token),
|
||||||
snakelize(options)
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export { verify } from "https://unpkg.com/@evan/wasm@0.0.65/target/ed25519/deno.js";
|
import { verify } from "https://unpkg.com/@evan/wasm@0.0.87/target/ed25519/deno.js";
|
||||||
import { verify } from "./deps.ts";
|
|
||||||
|
|
||||||
export function verifySignature({ publicKey, signature, timestamp, body }: VerifySignatureOptions): {
|
export function verifySignature({ publicKey, signature, timestamp, body }: VerifySignatureOptions): {
|
||||||
isValid: boolean;
|
isValid: boolean;
|
||||||
|
|||||||
@@ -78,12 +78,25 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string |
|
|||||||
"post",
|
"post",
|
||||||
bot.constants.endpoints.CHANNEL_MESSAGES(channelId),
|
bot.constants.endpoints.CHANNEL_MESSAGES(channelId),
|
||||||
bot.utils.snakelize({
|
bot.utils.snakelize({
|
||||||
...content,
|
content: content.content,
|
||||||
|
tts: content.tts,
|
||||||
|
embeds: content.embeds,
|
||||||
|
allowed_mentions: {
|
||||||
|
parse: content.allowedMentions.parse,
|
||||||
|
roles: content.allowedMentions.roles,
|
||||||
|
users: content.allowedMentions.users,
|
||||||
|
replied_user: content.allowedMentions.repliedUser
|
||||||
|
},
|
||||||
|
file: content.file,
|
||||||
|
// TODO: Snakelize components??
|
||||||
|
components: content.components,
|
||||||
...(content.messageReference?.messageId
|
...(content.messageReference?.messageId
|
||||||
? {
|
? {
|
||||||
messageReference: {
|
message_reference: {
|
||||||
...content.messageReference,
|
message_id: content.messageReference.messageId,
|
||||||
failIfNotExists: content.messageReference.failIfNotExists === true,
|
channel_id: content.messageReference.channelId,
|
||||||
|
guild_id: content.messageReference.guildId,
|
||||||
|
fail_if_not_exists: content.messageReference.failIfNotExists === true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
|
|||||||
@@ -54,8 +54,14 @@ export async function editWebhookMessage(
|
|||||||
content: options.content,
|
content: options.content,
|
||||||
embeds: options.embeds,
|
embeds: options.embeds,
|
||||||
file: options.file,
|
file: options.file,
|
||||||
allowedMentions: options.allowed_mentions,
|
allowed_mentions: {
|
||||||
|
parse: content.allowedMentions.parse,
|
||||||
|
roles: content.allowedMentions.roles,
|
||||||
|
users: content.allowedMentions.users,
|
||||||
|
replied_user: content.allowedMentions.repliedUser
|
||||||
|
},
|
||||||
attachments: options.attachments,
|
attachments: options.attachments,
|
||||||
|
// TODO: Snakelize components??
|
||||||
components: options.components,
|
components: options.components,
|
||||||
message_id: options.messageId,
|
message_id: options.messageId,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user