add(types): stage discovery privacy fields (#957)

* feat: add stage discovery fields

* feat: add stage discovery fields

* Update src/types/channels/privacy_level.ts

Co-authored-by: ITOH <to@itoh.at>

* change: prettier code

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
Co-authored-by: ITOH <to@itoh.at>
Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com>
This commit is contained in:
rigormorrtiss
2021-05-22 11:41:06 +04:00
committed by GitHub
parent 61e5d3fcb9
commit 8a4968f1af
4 changed files with 32 additions and 11 deletions
+12 -5
View File
@@ -6,9 +6,11 @@ import type { StageInstance } from "../../types/channels/stage_instance.ts";
import { cacheHandlers } from "../../cache.ts";
import { ChannelTypes } from "../../types/channels/channel_types.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { PrivacyLevel } from "../../types/channels/privacy_level.ts";
import { snakelize } from "../../util/utils.ts";
/** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */
export async function createStageInstance(channelId: bigint, topic: string) {
export async function createStageInstance(channelId: bigint, topic: string, privacyLevel?: PrivacyLevel) {
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
@@ -23,8 +25,13 @@ export async function createStageInstance(channelId: bigint, topic: string) {
throw new Error(Errors.INVALID_TOPIC_LENGTH);
}
return await rest.runMethod<StageInstance>("post", endpoints.STAGE_INSTANCES, {
channel_id: channelId,
topic,
});
return await rest.runMethod<StageInstance>(
"post",
endpoints.STAGE_INSTANCES,
snakelize({
channelId,
topic,
privacyLevel,
})
);
}
@@ -6,9 +6,13 @@ import { validateLength } from "../../util/validate_length.ts";
import { cacheHandlers } from "../../cache.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { ChannelTypes } from "../../types/channels/channel_types.ts";
import { snakelize } from "../../util/utils.ts";
/** Updates fields of an existing Stage instance. Requires the user to be a moderator of the Stage channel. */
export async function updateStageInstance(channelId: bigint, topic: string) {
export async function updateStageInstance(
channelId: bigint,
data: Partial<Pick<StageInstance, "topic" | "privacyLevel">> = {}
) {
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
@@ -20,7 +24,8 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
}
if (
!validateLength(topic, {
data?.topic &&
!validateLength(data.topic, {
min: 1,
max: 120,
})
@@ -28,7 +33,5 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
throw new Error(Errors.INVALID_TOPIC_LENGTH);
}
return await rest.runMethod<StageInstance>("patch", endpoints.STAGE_INSTANCE(channelId), {
topic,
});
return await rest.runMethod<StageInstance>("patch", endpoints.STAGE_INSTANCE(channelId), snakelize(data));
}
+7
View File
@@ -0,0 +1,7 @@
// TODO: add resource link
export enum PrivacyLevel {
/** The Stage instance is visible publicly, such as on Stage discovery */
Public = 1,
/** The Stage instance is visible to only guild members */
GuildOnly,
}
+5 -1
View File
@@ -1,4 +1,4 @@
// TODO: add resource link
/** https://discord.com/developers/docs/resources/stage-instance#auto-closing-stage-instance-structure */
export interface StageInstance {
/** The id of this Stage instance */
id: string;
@@ -8,4 +8,8 @@ export interface StageInstance {
channelId: string;
/** The topic of the Stage instance (1-120 characters) */
topic: string;
/** The privacy level of the Stage instance */
privacyLevel: number;
/** Whether or not Stage discovery is disabled */
discoverableDisabled: boolean;
}