mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
nothin'
This commit is contained in:
@@ -1,27 +1,16 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { InviteCreate } from "../../types/invites/invite_create.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||||
export async function createInvite(
|
export async function createInvite(
|
||||||
channelId: string,
|
channelId: string,
|
||||||
options: CreateInviteOptions,
|
options: InviteCreate,
|
||||||
) {
|
) {
|
||||||
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);
|
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);
|
||||||
|
|
||||||
if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) {
|
// TODO: add proper options validation
|
||||||
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 rest.runMethod(
|
const result = await rest.runMethod(
|
||||||
"post",
|
"post",
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
botHasChannelPermissions,
|
botHasChannelPermissions,
|
||||||
requireBotGuildPermissions,
|
requireBotGuildPermissions,
|
||||||
} from "../../util/permissions.ts";
|
} from "../../util/permissions.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
|
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
|
||||||
export async function deleteInvite(channelId: string, inviteCode: string) {
|
export async function deleteInvite(channelId: string, inviteCode: string) {
|
||||||
@@ -21,7 +23,10 @@ export async function deleteInvite(channelId: string, inviteCode: string) {
|
|||||||
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await rest.runMethod("delete", endpoints.INVITE(inviteCode));
|
const result: DiscordInvite = await rest.runMethod(
|
||||||
|
"delete",
|
||||||
|
endpoints.INVITE(inviteCode),
|
||||||
|
);
|
||||||
|
|
||||||
return result as InvitePayload;
|
return snakeKeysToCamelCase<Invite>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
|
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||||
|
|
||||||
/** Returns an invite for the given code. */
|
/** Returns an invite for the given code. */
|
||||||
export async function getInvite(inviteCode: string) {
|
export async function getInvite(inviteCode: string) {
|
||||||
const result = await rest.runMethod("get", endpoints.INVITE(inviteCode));
|
const result: DiscordInvite = await rest.runMethod(
|
||||||
|
"get",
|
||||||
|
endpoints.INVITE(inviteCode),
|
||||||
|
);
|
||||||
|
|
||||||
return result as InvitePayload;
|
return snakeKeysToCamelCase<Invite>(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user