mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
invites
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts";
|
import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts";
|
||||||
|
import { Invite } from "../../types/mod.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";
|
||||||
|
|
||||||
@@ -12,11 +13,9 @@ export async function createInvite(
|
|||||||
|
|
||||||
// TODO: add proper options validation
|
// TODO: add proper options validation
|
||||||
|
|
||||||
const result = await rest.runMethod(
|
return await rest.runMethod<Invite>(
|
||||||
"post",
|
"post",
|
||||||
endpoints.CHANNEL_INVITES(channelId),
|
endpoints.CHANNEL_INVITES(channelId),
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
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 { 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) {
|
||||||
@@ -23,10 +22,8 @@ export async function deleteInvite(channelId: string, inviteCode: string) {
|
|||||||
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: DiscordInvite = await rest.runMethod(
|
return await rest.runMethod<Invite>(
|
||||||
"delete",
|
"delete",
|
||||||
endpoints.INVITE(inviteCode),
|
endpoints.INVITE(inviteCode),
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase<Invite>(result);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
import { Invite } from "../../types/invites/invite.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.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";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|
||||||
|
|
||||||
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
||||||
export async function getChannelInvites(channelId: string) {
|
export async function getChannelInvites(channelId: string) {
|
||||||
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Invite[]>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.CHANNEL_INVITES(channelId),
|
endpoints.CHANNEL_INVITES(channelId),
|
||||||
)) as DiscordInvite[];
|
);
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
result.map((invite) => [invite.code, snakeKeysToCamelCase<Invite>(invite)]),
|
result.map((invite) => [invite.code, invite]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
import { 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 or throws an error if the invite doesn't exists. */
|
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */
|
||||||
export async function getInvite(inviteCode: string) {
|
export async function getInvite(inviteCode: string) {
|
||||||
const result: DiscordInvite = await rest.runMethod(
|
return await rest.runMethod<Invite>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.INVITE(inviteCode),
|
endpoints.INVITE(inviteCode),
|
||||||
);
|
);
|
||||||
|
|
||||||
return snakeKeysToCamelCase<Invite>(result);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
|
import { Invite } from "../../types/invites/invite.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
|
||||||
|
|
||||||
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
||||||
export async function getInvites(guildId: string) {
|
export async function getInvites(guildId: string) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||||
|
|
||||||
const result = (await rest.runMethod(
|
const result = await rest.runMethod<Invite[]>(
|
||||||
"get",
|
"get",
|
||||||
endpoints.GUILD_INVITES(guildId),
|
endpoints.GUILD_INVITES(guildId),
|
||||||
)) as DiscordInvite[];
|
);
|
||||||
|
|
||||||
return new Collection(
|
return new Collection(
|
||||||
result.map((invite) => [invite.code, snakeKeysToCamelCase<Invite>(invite)]),
|
result.map((invite) => [invite.code, invite]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user