Merge remote-tracking branch 'upstream/main' into fix-upsert-slash-typings

This commit is contained in:
ITOH
2021-03-07 15:52:37 +01:00
4 changed files with 21 additions and 18 deletions

View File

@@ -17,7 +17,7 @@ import {
WebhookPayload,
} from "../../types/mod.ts";
import { cache } from "../../util/cache.ts";
import { endpoints } from "../../util/constants.ts";
import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../../util/constants.ts";
import { botHasChannelPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts";
import { structures } from "../structures/mod.ts";
@@ -252,9 +252,10 @@ export async function editWebhookMessage(
const result = await RequestManager.patch(
endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken, messageID),
{ ...options, allowed_mentions: options.allowed_mentions },
);
) as MessageCreateOptions;
return result;
const message = await structures.createMessage(result);
return message;
}
export async function deleteWebhookMessage(
@@ -281,8 +282,7 @@ export async function deleteWebhookMessage(
* 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: CreateSlashCommandOptions) {
// Use ... for content length due to unicode characters and js .length handling
if ([...options.name].length < 2 || [...options.name].length > 32) {
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
throw new Error(Errors.INVALID_SLASH_NAME);
}
@@ -335,11 +335,7 @@ export async function upsertSlashCommand(
options: UpsertSlashCommandOptions,
guildID?: string,
) {
// Use ... for content length due to unicode characters and js .length handling
if (
options.name &&
([...options.name].length < 2 || [...options.name].length > 32)
) {
if (options.name && !SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
throw new Error(Errors.INVALID_SLASH_NAME);
}
@@ -375,11 +371,7 @@ export async function upsertSlashCommands(
guildID?: string,
) {
const data = options.map((option) => {
// Use ... for content length due to unicode characters and js .length handling
if (
option.name &&
([...option.name].length < 2 || [...option.name].length > 32)
) {
if (option.name && !SLASH_COMMANDS_NAME_REGEX.test(option.name)) {
throw new Error(Errors.INVALID_SLASH_NAME);
}
@@ -414,8 +406,7 @@ export async function editSlashCommand(
options: EditSlashCommandOptions,
guildID?: string,
) {
// Use ... for content length due to unicode characters and js .length handling
if ([...options.name].length < 2 || [...options.name].length > 32) {
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
throw new Error(Errors.INVALID_SLASH_NAME);
}
@@ -562,5 +553,11 @@ export async function editSlashResponse(
options,
);
return result;
// If the original message was edited, this will not return a message
if (!options.messageID) return result;
const message = await structures.createMessage(
result as MessageCreateOptions,
);
return message;
}

View File

@@ -56,6 +56,8 @@ export interface DiscordEmbedThumbnail {
export interface DiscordEmbedVideo {
/** source url of video */
url?: string;
/** a proxied url of the video */
proxy_url?: string;
/** height of video */
height?: number;
/** width of video */

View File

@@ -99,6 +99,8 @@ export interface EmbedThumbnail {
export interface EmbedVideo {
/** The source url of video */
url?: string;
/** a proxied url of the video */
proxy_url?: string;
/** The height of the video */
height?: number;
/** The width of the video */

View File

@@ -175,3 +175,5 @@ export const endpoints = {
// oAuth2
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
};
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;