Merge branch 'main' into change-enums

This commit is contained in:
Skillz4Killz
2021-05-05 12:04:53 -04:00
committed by GitHub
10 changed files with 57 additions and 19 deletions

View File

@@ -0,0 +1,15 @@
import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import type { Message } from "../../types/messages/message.ts";
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),
);
return await structures.createDiscordenoMessage(result);
}

View File

@@ -1,11 +1,14 @@
import { rest } from "../../rest/rest.ts";
import { GetInvite } from "../../types/invites/get_invite.ts";
import type { Invite } from "../../types/invites/invite.ts";
import { endpoints } from "../../util/constants.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */
export async function getInvite(inviteCode: string) {
export async function getInvite(inviteCode: string, options?: GetInvite) {
return await rest.runMethod<Invite>(
"get",
endpoints.INVITE(inviteCode),
camelKeysToSnakeCase(options ?? {}),
);
}

View File

@@ -145,13 +145,6 @@ export async function sendMessage(
}
}
if (
content.nonce &&
!validateLength(content.nonce.toString(), { max: 25 })
) {
throw new Error(Errors.NONCE_TOO_LONG);
}
const result = await rest.runMethod<Message>(
"post",
endpoints.CHANNEL_MESSAGES(channelId),

View File

@@ -19,6 +19,7 @@ import { deleteSlashCommand } from "./commands/delete_slash_command.ts";
import { deleteSlashResponse } from "./commands/delete_slash_response.ts";
import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts";
import { editSlashResponse } from "./commands/edit_slash_response.ts";
import { getOriginalInteractionResponse } from "./commands/get_original_interaction_response.ts";
import { getSlashCommand } from "./commands/get_slash_command.ts";
import { getSlashCommands } from "./commands/get_slash_commands.ts";
import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts";
@@ -111,6 +112,9 @@ import { editGuildTemplate } from "./templates/edit_guild_template.ts";
import { getGuildTemplates } from "./templates/get_guild_templates.ts";
import { getTemplate } from "./templates/get_template.ts";
import { syncGuildTemplate } from "./templates/sync_guild_template.ts";
// Type Guards
import { isActionRow } from "./type_guards/is_action_row.ts";
import { isButton } from "./type_guards/is_button.ts";
import { createWebhook } from "./webhooks/create_webhook.ts";
import { deleteWebhook } from "./webhooks/delete_webhook.ts";
import { deleteWebhookMessage } from "./webhooks/delete_webhook_message.ts";
@@ -118,13 +122,11 @@ import { deleteWebhookWithToken } from "./webhooks/delete_webhook_with_token.ts"
import { editWebhook } from "./webhooks/edit_webhook.ts";
import { editWebhookMessage } from "./webhooks/edit_webhook_message.ts";
import { editWebhookWithToken } from "./webhooks/edit_webhook_with_token.ts";
import { sendWebhook } from "./webhooks/send_webhook.ts";
import { getWebhook } from "./webhooks/get_webhook.ts";
import { getWebhooks } from "./webhooks/get_webhooks.ts";
import { getWebhookMessage } from "./webhooks/get_webhook_message.ts";
import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts";
// Type Guards
import { isActionRow } from "./type_guards/is_action_row.ts";
import { isButton } from "./type_guards/is_button.ts";
import { sendWebhook } from "./webhooks/send_webhook.ts";
export {
addDiscoverySubcategory,
@@ -205,6 +207,7 @@ export {
getMembers,
getMessage,
getMessages,
getOriginalInteractionResponse,
getPins,
getPruneCount,
getReactions,
@@ -218,6 +221,7 @@ export {
getVanityURL,
getVoiceRegions,
getWebhook,
getWebhookMessage,
getWebhooks,
getWebhookWithToken,
getWelcomeScreen,
@@ -289,6 +293,7 @@ export let helpers = {
getSlashCommands,
upsertSlashCommand,
upsertSlashCommands,
getOriginalInteractionResponse,
// emojis
createEmoji,
deleteEmoji,
@@ -396,6 +401,7 @@ export let helpers = {
getWebhookWithToken,
getWebhook,
getWebhooks,
getWebhookMessage,
};
export type Helpers = typeof helpers;

View File

@@ -0,0 +1,18 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import type { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */
export async function getWebhookMessage(
webhookId: bigint,
webhookToken: string,
messageId: bigint,
) {
const result = await rest.runMethod<Message>(
"get",
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
);
return await structures.createDiscordenoMessage(result);
}

View File

@@ -66,8 +66,8 @@ export async function sendWebhook(
const result = await rest.runMethod<Message>(
"post",
`${endpoints.WEBHOOK(webhookId, webhookToken)}${
options.wait ? "?wait=true" : ""
`${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait}${
options.threadId ? `&thread_id=${options.threadId}` : ""
}`,
{
...options,

View File

@@ -8,13 +8,11 @@ import { MessageComponents } from "./components/message_components.ts";
export interface CreateMessage {
/** The message contents (up to 2000 characters) */
content?: string;
/** A nonce that can be used for optimistic message sending */
nonce?: number | string;
/** true if this is a TTS message */
tts?: boolean;
/** Embedded `rich` content */
embed?: Embed;
/** Allowed mentions for a message */
/** Allowed mentions for the message */
allowedMentions?: AllowedMentions;
/** Include to make your message a reply */
messageReference?: MessageReference;

View File

@@ -1,4 +1,5 @@
import { Embed } from "../embeds/embed.ts";
import { FileContent } from "../misc/file_content.ts";
import { AllowedMentions } from "./allowed_mentions.ts";
import { Attachment } from "./attachment.ts";
@@ -10,6 +11,8 @@ export interface EditMessage {
embed?: Embed | null;
/** Edit the flags of the message (only `SUPRESS_EMBEDS` can currently be set/unset) */
flags?: 4 | null;
/** The contents of the file being sent/edited */
file?: FileContent | FileContent[] | null;
/** Allowed mentions for the message */
allowedMentions?: AllowedMentions | null;
/** Attached files to keep */

View File

@@ -1,7 +1,7 @@
import { Embed } from "../embeds/embed.ts";
import { AllowedMentions } from "../messages/allowed_mentions.ts";
import { FileContent } from "../misc/file_content.ts";
import { Attachment } from "../messages/attachment.ts";
import { FileContent } from "../misc/file_content.ts";
/** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */
export interface EditWebhookMessage {
@@ -10,7 +10,7 @@ export interface EditWebhookMessage {
/** Embedded `rich` content */
embeds?: Embed[] | null;
/** The contents of the file being sent/edited */
file?: FileContent | FileContent[];
file?: FileContent | FileContent[] | null;
/** Allowed mentions for the message */
allowedMentions?: AllowedMentions | null;
/** Attached files to keep */

View File

@@ -7,6 +7,8 @@ import { SnakeCasedPropertiesDeep } from "../util.ts";
export interface ExecuteWebhook {
/** Waits for server confirmation of message send before response, and returns the created message body (defaults to `false`; when `false` a message that is not saved does not return an error) */
wait?: boolean;
/** Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. */
threadId?: bigint;
/** The message contents (up to 2000 characters) */
content?: string;
/** Override the default username of the webhook */