mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactor(helpers): separate functions into files (#667)
* refactor(helpers): separate functions into files * idk * idk
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { CreateInviteOptions } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||
export async function createInvite(
|
||||
channelID: string,
|
||||
options: CreateInviteOptions,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelID, ["CREATE_INSTANT_INVITE"]);
|
||||
|
||||
if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) {
|
||||
console.log(
|
||||
`The max age for invite created in ${channelID} was not between 0-604800. Using default values instead.`,
|
||||
);
|
||||
options.max_age = undefined;
|
||||
}
|
||||
|
||||
if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) {
|
||||
console.log(
|
||||
`The max uses for invite created in ${channelID} was not between 0-100. Using default values instead.`,
|
||||
);
|
||||
options.max_uses = undefined;
|
||||
}
|
||||
|
||||
const result = await RequestManager.post(
|
||||
endpoints.CHANNEL_INVITES(channelID),
|
||||
options,
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { Errors, InvitePayload } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
botHasChannelPermissions,
|
||||
requireBotGuildPermissions,
|
||||
} from "../../util/permissions.ts";
|
||||
|
||||
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
|
||||
export async function deleteInvite(channelID: string, inviteCode: string) {
|
||||
const channel = await cacheHandlers.get("channels", channelID);
|
||||
|
||||
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||
|
||||
const hasPerm = await botHasChannelPermissions(channel, [
|
||||
"MANAGE_CHANNELS",
|
||||
]);
|
||||
|
||||
if (!hasPerm) {
|
||||
await requireBotGuildPermissions(channel!.guildID, ["MANAGE_GUILD"]);
|
||||
}
|
||||
|
||||
const result = await RequestManager.delete(endpoints.INVITE(inviteCode));
|
||||
|
||||
return result as InvitePayload;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
||||
export async function getChannelInvites(channelID: string) {
|
||||
await requireBotChannelPermissions(channelID, ["MANAGE_CHANNELS"]);
|
||||
|
||||
const result = await RequestManager.get(endpoints.CHANNEL_INVITES(channelID));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { InvitePayload } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns an invite for the given code. */
|
||||
export async function getInvite(inviteCode: string) {
|
||||
const result = await RequestManager.get(endpoints.INVITE(inviteCode));
|
||||
|
||||
return result as InvitePayload;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { RequestManager } from "../../rest/request_manager.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
||||
export async function getInvites(guildID: string) {
|
||||
await requireBotGuildPermissions(guildID, ["MANAGE_GUILD"]);
|
||||
|
||||
const result = await RequestManager.get(endpoints.GUILD_INVITES(guildID));
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user