mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(handlers): add getInvite() & deleteInvite() (#421)
* feat(handlers): add getInvite * feat(handlers): add deleteInvite * remove deving things * add jsdoc * move functions up * import got deleted * feat(handlers): invite better types * throw enum error * remove unnecessary checks * Update mod.ts * channel exists since botHasChannelPermissions did not throw any error
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
GetMessagesAfter,
|
||||
GetMessagesAround,
|
||||
GetMessagesBefore,
|
||||
InvitePayload,
|
||||
MessageContent,
|
||||
MessageCreateOptions,
|
||||
Permission,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
botHasChannelPermissions,
|
||||
botHasPermission,
|
||||
calculateBits,
|
||||
} from "../../util/permissions.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
@@ -301,6 +303,39 @@ export async function createInvite(
|
||||
return RequestManager.post(endpoints.CHANNEL_INVITES(channelID), options);
|
||||
}
|
||||
|
||||
/** Returns an invite for the given code. */
|
||||
export function getInvite(inviteCode: string) {
|
||||
return RequestManager.get(endpoints.INVITE(inviteCode)) as Promise<
|
||||
InvitePayload
|
||||
>;
|
||||
}
|
||||
|
||||
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
|
||||
export async function deleteInvite(
|
||||
channelID: string,
|
||||
inviteCode: string,
|
||||
) {
|
||||
const hasPerm = await botHasChannelPermissions(channelID, [
|
||||
"MANAGE_CHANNELS",
|
||||
]);
|
||||
|
||||
if (!hasPerm) {
|
||||
const channel = await cacheHandlers.get("channels", channelID);
|
||||
|
||||
const hasManageGuildPerm = await botHasPermission(channel!.guildID, [
|
||||
"MANAGE_GUILD",
|
||||
]);
|
||||
|
||||
if (!hasManageGuildPerm) {
|
||||
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
||||
}
|
||||
}
|
||||
|
||||
return RequestManager.delete(endpoints.INVITE(inviteCode)) as Promise<
|
||||
InvitePayload
|
||||
>;
|
||||
}
|
||||
|
||||
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
||||
export async function getChannelWebhooks(channelID: string) {
|
||||
const hasManageWebhooksPerm = await botHasChannelPermissions(
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import {
|
||||
channelOverwriteHasPermission,
|
||||
createInvite,
|
||||
deleteInvite,
|
||||
deleteMessages,
|
||||
editChannel,
|
||||
followChannel,
|
||||
getChannelInvites,
|
||||
getChannelWebhooks,
|
||||
getInvite,
|
||||
getMessage,
|
||||
getMessages,
|
||||
getPins,
|
||||
@@ -133,6 +135,8 @@ export let handlers = {
|
||||
getPins,
|
||||
isChannelSynced,
|
||||
sendMessage,
|
||||
getInvite,
|
||||
deleteInvite,
|
||||
startTyping,
|
||||
|
||||
// Gateway handler
|
||||
|
||||
Reference in New Issue
Block a user