mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Merge pull request #175 from Skillz4Killz/resolve-promise
Resolve promise for all botHasChannelPermissions()
This commit is contained in:
+76
-30
@@ -43,16 +43,22 @@ export async function getMessage(
|
|||||||
channelID: string,
|
channelID: string,
|
||||||
id: string,
|
id: string,
|
||||||
) {
|
) {
|
||||||
|
const hasViewChannelPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.VIEW_CHANNEL],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.VIEW_CHANNEL])
|
!hasViewChannelPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_VIEW_CHANNEL);
|
throw new Error(Errors.MISSING_VIEW_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasReadMessageHistoryPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.READ_MESSAGE_HISTORY],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(
|
!hasReadMessageHistoryPerm
|
||||||
channelID,
|
|
||||||
[Permissions.READ_MESSAGE_HISTORY],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
||||||
}
|
}
|
||||||
@@ -72,16 +78,22 @@ export async function getMessages(
|
|||||||
| GetMessagesAround
|
| GetMessagesAround
|
||||||
| GetMessages,
|
| GetMessages,
|
||||||
) {
|
) {
|
||||||
|
const hasViewChannelPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.VIEW_CHANNEL],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.VIEW_CHANNEL])
|
!hasViewChannelPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_VIEW_CHANNEL);
|
throw new Error(Errors.MISSING_VIEW_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasReadMessageHistoryPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.READ_MESSAGE_HISTORY],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(
|
!hasReadMessageHistoryPerm
|
||||||
channelID,
|
|
||||||
[Permissions.READ_MESSAGE_HISTORY],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
||||||
}
|
}
|
||||||
@@ -109,24 +121,34 @@ export async function sendMessage(
|
|||||||
content: string | MessageContent,
|
content: string | MessageContent,
|
||||||
) {
|
) {
|
||||||
if (typeof content === "string") content = { content };
|
if (typeof content === "string") content = { content };
|
||||||
|
const hasSendMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.SEND_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.SEND_MESSAGES])
|
!hasSendMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasSendTtsMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.SEND_TTS_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
content.tts &&
|
content.tts &&
|
||||||
!botHasChannelPermissions(
|
!hasSendTtsMessagesPerm
|
||||||
channelID,
|
|
||||||
[Permissions.SEND_TTS_MESSAGES],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_SEND_TTS_MESSAGE);
|
throw new Error(Errors.MISSING_SEND_TTS_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasEmbedLinksPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.EMBED_LINKS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
content.embed &&
|
content.embed &&
|
||||||
!botHasChannelPermissions(channelID, [Permissions.EMBED_LINKS])
|
!hasEmbedLinksPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_EMBED_LINKS);
|
throw new Error(Errors.MISSING_EMBED_LINKS);
|
||||||
}
|
}
|
||||||
@@ -183,13 +205,17 @@ export async function sendMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
||||||
export function deleteMessages(
|
export async function deleteMessages(
|
||||||
channelID: string,
|
channelID: string,
|
||||||
ids: string[],
|
ids: string[],
|
||||||
reason?: string,
|
reason?: string,
|
||||||
) {
|
) {
|
||||||
|
const hasManageMessages = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])
|
!hasManageMessages
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -210,9 +236,13 @@ export function deleteMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
||||||
export function getChannelInvites(channelID: string) {
|
export async function getChannelInvites(channelID: string) {
|
||||||
|
const hasManagaChannels = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_CHANNELS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_CHANNELS])
|
!hasManagaChannels
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
||||||
}
|
}
|
||||||
@@ -220,12 +250,16 @@ export function getChannelInvites(channelID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||||
export function createInvite(channelID: string, options: CreateInviteOptions) {
|
export async function createInvite(
|
||||||
|
channelID: string,
|
||||||
|
options: CreateInviteOptions,
|
||||||
|
) {
|
||||||
|
const hasCreateInstantInvitePerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.CREATE_INSTANT_INVITE],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(
|
!hasCreateInstantInvitePerm
|
||||||
channelID,
|
|
||||||
[Permissions.CREATE_INSTANT_INVITE],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_CREATE_INSTANT_INVITE);
|
throw new Error(Errors.MISSING_CREATE_INSTANT_INVITE);
|
||||||
}
|
}
|
||||||
@@ -233,9 +267,13 @@ export function createInvite(channelID: string, options: CreateInviteOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
||||||
export function getChannelWebhooks(channelID: string) {
|
export async function getChannelWebhooks(channelID: string) {
|
||||||
|
const hasManageWebhooksPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_WEBHOOKS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_WEBHOOKS])
|
!hasManageWebhooksPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_WEBHOOKS);
|
throw new Error(Errors.MISSING_MANAGE_WEBHOOKS);
|
||||||
}
|
}
|
||||||
@@ -288,12 +326,16 @@ function processEditChannelQueue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function editChannel(
|
export async function editChannel(
|
||||||
channelID: string,
|
channelID: string,
|
||||||
options: ChannelEditOptions,
|
options: ChannelEditOptions,
|
||||||
) {
|
) {
|
||||||
|
const hasManageChannelsPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_CHANNELS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_CHANNELS])
|
!hasManageChannelsPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
||||||
}
|
}
|
||||||
@@ -356,8 +398,12 @@ export async function followChannel(
|
|||||||
sourceChannelID: string,
|
sourceChannelID: string,
|
||||||
targetChannelID: string,
|
targetChannelID: string,
|
||||||
) {
|
) {
|
||||||
|
const hasManageWebhooksPerm = await botHasChannelPermissions(
|
||||||
|
targetChannelID,
|
||||||
|
[Permissions.MANAGE_WEBHOOKS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(targetChannelID, [Permissions.MANAGE_WEBHOOKS])
|
!hasManageWebhooksPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-22
@@ -38,11 +38,12 @@ export async function deleteMessage(
|
|||||||
) {
|
) {
|
||||||
if (message.author.id !== botID) {
|
if (message.author.id !== botID) {
|
||||||
// This needs to check the channels permission not the guild permission
|
// This needs to check the channels permission not the guild permission
|
||||||
|
const hasManageMessages = await botHasChannelPermissions(
|
||||||
|
message.channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(
|
!hasManageMessages
|
||||||
message.channelID,
|
|
||||||
[Permissions.MANAGE_MESSAGES],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -57,9 +58,13 @@ export async function deleteMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
|
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
|
||||||
export function pin(channelID: string, messageID: string) {
|
export async function pin(channelID: string, messageID: string) {
|
||||||
|
const hasManageMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])
|
!hasManageMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -67,9 +72,13 @@ export function pin(channelID: string, messageID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
||||||
export function unpin(channelID: string, messageID: string) {
|
export async function unpin(channelID: string, messageID: string) {
|
||||||
|
const hasManageMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])
|
!hasManageMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -79,17 +88,25 @@ export function unpin(channelID: string, messageID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
/** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
||||||
export function addReaction(
|
export async function addReaction(
|
||||||
channelID: string,
|
channelID: string,
|
||||||
messageID: string,
|
messageID: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
) {
|
) {
|
||||||
if (!botHasChannelPermissions(channelID, [Permissions.ADD_REACTIONS])) {
|
const hasAddReactionsPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.ADD_REACTIONS],
|
||||||
|
);
|
||||||
|
if (!hasAddReactionsPerm) {
|
||||||
throw new Error(Errors.MISSING_ADD_REACTIONS);
|
throw new Error(Errors.MISSING_ADD_REACTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasReadMessageHistoryPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.READ_MESSAGE_HISTORY],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.READ_MESSAGE_HISTORY])
|
!hasReadMessageHistoryPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
throw new Error(Errors.MISSING_READ_MESSAGE_HISTORY);
|
||||||
}
|
}
|
||||||
@@ -143,13 +160,17 @@ export function removeReaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||||
export function removeUserReaction(
|
export async function removeUserReaction(
|
||||||
channelID: string,
|
channelID: string,
|
||||||
messageID: string,
|
messageID: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
userID: string,
|
userID: string,
|
||||||
) {
|
) {
|
||||||
if (!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])) {
|
const hasManageMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
|
if (!hasManageMessagesPerm) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,9 +185,13 @@ export function removeUserReaction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all reactions for all emojis on this message. */
|
/** Removes all reactions for all emojis on this message. */
|
||||||
export function removeAllReactions(channelID: string, messageID: string) {
|
export async function removeAllReactions(channelID: string, messageID: string) {
|
||||||
|
const hasManageMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])
|
!hasManageMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -176,13 +201,17 @@ export function removeAllReactions(channelID: string, messageID: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
/** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||||
export function removeReactionEmoji(
|
export async function removeReactionEmoji(
|
||||||
channelID: string,
|
channelID: string,
|
||||||
messageID: string,
|
messageID: string,
|
||||||
reaction: string,
|
reaction: string,
|
||||||
) {
|
) {
|
||||||
|
const hasManageMessagesPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(channelID, [Permissions.MANAGE_MESSAGES])
|
!hasManageMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||||
}
|
}
|
||||||
@@ -216,18 +245,23 @@ export async function editMessage(
|
|||||||
|
|
||||||
if (typeof content === "string") content = { content };
|
if (typeof content === "string") content = { content };
|
||||||
|
|
||||||
|
const hasSendMessagesPerm = await botHasChannelPermissions(
|
||||||
|
message.channelID,
|
||||||
|
[Permissions.SEND_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(message.channelID, [Permissions.SEND_MESSAGES])
|
!hasSendMessagesPerm
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
throw new Error(Errors.MISSING_SEND_MESSAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasSendTtsMessagesPerm = await botHasChannelPermissions(
|
||||||
|
message.channelID,
|
||||||
|
[Permissions.SEND_TTS_MESSAGES],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
content.tts &&
|
content.tts &&
|
||||||
!botHasChannelPermissions(
|
!hasSendTtsMessagesPerm
|
||||||
message.channelID,
|
|
||||||
[Permissions.SEND_TTS_MESSAGES],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_SEND_TTS_MESSAGE);
|
throw new Error(Errors.MISSING_SEND_TTS_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,12 @@ export async function createWebhook(
|
|||||||
channelID: string,
|
channelID: string,
|
||||||
options: WebhookCreateOptions,
|
options: WebhookCreateOptions,
|
||||||
) {
|
) {
|
||||||
|
const hasManageWebhooksPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
[Permissions.MANAGE_WEBHOOKS],
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!botHasChannelPermissions(
|
!hasManageWebhooksPerm
|
||||||
channelID,
|
|
||||||
[Permissions.MANAGE_WEBHOOKS],
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.MISSING_MANAGE_WEBHOOKS);
|
throw new Error(Errors.MISSING_MANAGE_WEBHOOKS);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user