mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-17 19:58:18 +00:00
types: fix new types issues (#829)
* feat: add tests for deleting channel overwrites * fix: typings
This commit is contained in:
@@ -9,7 +9,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
/** Edit the message. */
|
||||
export async function editMessage(
|
||||
message: Message,
|
||||
content: string | MessageContent,
|
||||
content: string | MessageContent
|
||||
) {
|
||||
if (message.author.id !== botId) {
|
||||
throw "You can only edit a message that was sent by the bot.";
|
||||
@@ -30,8 +30,8 @@ export async function editMessage(
|
||||
const result = await rest.runMethod(
|
||||
"patch",
|
||||
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
|
||||
content,
|
||||
content
|
||||
);
|
||||
|
||||
return structures.createDiscordenoMessage(result as MessageCreateOptions);
|
||||
return structures.createDiscordenoMessage(result as DiscordMessage);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -15,8 +16,8 @@ export async function getMessage(channelId: string, id: string) {
|
||||
|
||||
const result = (await rest.runMethod(
|
||||
"get",
|
||||
endpoints.CHANNEL_MESSAGE(channelId, id),
|
||||
)) as MessageCreateOptions;
|
||||
endpoints.CHANNEL_MESSAGE(channelId, id)
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(result);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -10,7 +11,7 @@ export async function getMessages(
|
||||
| GetMessagesAfter
|
||||
| GetMessagesBefore
|
||||
| GetMessagesAround
|
||||
| GetMessages,
|
||||
| GetMessages
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, [
|
||||
"VIEW_CHANNEL",
|
||||
@@ -22,10 +23,10 @@ export async function getMessages(
|
||||
const result = (await rest.runMethod(
|
||||
"get",
|
||||
endpoints.CHANNEL_MESSAGES(channelId),
|
||||
options,
|
||||
)) as MessageCreateOptions[];
|
||||
options
|
||||
)) as DiscordMessage[];
|
||||
|
||||
return Promise.all(
|
||||
result.map((res) => structures.createDiscordenoMessage(res)),
|
||||
result.map((res) => structures.createDiscordenoMessage(res))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Crosspost a message in a News Channel to following channels. */
|
||||
export async function publishMessage(channelId: string, messageId: string) {
|
||||
const data = (await rest.runMethod(
|
||||
"post",
|
||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
||||
)) as MessageCreateOptions;
|
||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId)
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(data);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
|
||||
import { CreateMessage } from "../../types/messages/create_message.ts";
|
||||
import { DiscordMessage } from "../../types/messages/message.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
|
||||
@@ -13,7 +14,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||
export async function sendMessage(
|
||||
channelId: string,
|
||||
content: string | DiscordenoCreateMessage,
|
||||
content: string | CreateMessage
|
||||
) {
|
||||
if (typeof content === "string") content = { content };
|
||||
|
||||
@@ -55,18 +56,18 @@ export async function sendMessage(
|
||||
if (content.allowedMentions.users?.length) {
|
||||
if (
|
||||
content.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.UserMentions,
|
||||
DiscordAllowedMentionsTypes.UserMentions
|
||||
)
|
||||
) {
|
||||
content.allowedMentions.parse = content.allowedMentions.parse.filter(
|
||||
(p) => p !== "users",
|
||||
(p) => p !== "users"
|
||||
);
|
||||
}
|
||||
|
||||
if (content.allowedMentions.users.length > 100) {
|
||||
content.allowedMentions.users = content.allowedMentions.users.slice(
|
||||
0,
|
||||
100,
|
||||
100
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -74,18 +75,18 @@ export async function sendMessage(
|
||||
if (content.allowedMentions.roles?.length) {
|
||||
if (
|
||||
content.allowedMentions.parse?.includes(
|
||||
DiscordAllowedMentionsTypes.RoleMentions,
|
||||
DiscordAllowedMentionsTypes.RoleMentions
|
||||
)
|
||||
) {
|
||||
content.allowedMentions.parse = content.allowedMentions.parse.filter(
|
||||
(p) => p !== "roles",
|
||||
(p) => p !== "roles"
|
||||
);
|
||||
}
|
||||
|
||||
if (content.allowedMentions.roles.length > 100) {
|
||||
content.allowedMentions.roles = content.allowedMentions.roles.slice(
|
||||
0,
|
||||
100,
|
||||
100
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -98,13 +99,14 @@ export async function sendMessage(
|
||||
...content,
|
||||
...(content.messageReference?.messageId
|
||||
? {
|
||||
messageReference: {
|
||||
...content.messageReference,
|
||||
failIfNotExists: content.messageReference.failIfNotExists === true,
|
||||
},
|
||||
}
|
||||
messageReference: {
|
||||
...content.messageReference,
|
||||
failIfNotExists:
|
||||
content.messageReference.failIfNotExists === true,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
})
|
||||
)) as DiscordMessage;
|
||||
|
||||
return structures.createDiscordenoMessage(result);
|
||||
|
||||
Reference in New Issue
Block a user