mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
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:
@@ -6,9 +6,11 @@ import type { StageInstance } from "../../types/channels/stage_instance.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { ChannelTypes } from "../../types/channels/channel_types.ts";
|
import { ChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.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. */
|
/** 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);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
@@ -23,8 +25,13 @@ export async function createStageInstance(channelId: bigint, topic: string) {
|
|||||||
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<StageInstance>("post", endpoints.STAGE_INSTANCES, {
|
return await rest.runMethod<StageInstance>(
|
||||||
channel_id: channelId,
|
"post",
|
||||||
|
endpoints.STAGE_INSTANCES,
|
||||||
|
snakelize({
|
||||||
|
channelId,
|
||||||
topic,
|
topic,
|
||||||
});
|
privacyLevel,
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,13 @@ import { validateLength } from "../../util/validate_length.ts";
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
import { ChannelTypes } from "../../types/channels/channel_types.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. */
|
/** 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);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
@@ -20,7 +24,8 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!validateLength(topic, {
|
data?.topic &&
|
||||||
|
!validateLength(data.topic, {
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 120,
|
max: 120,
|
||||||
})
|
})
|
||||||
@@ -28,7 +33,5 @@ export async function updateStageInstance(channelId: bigint, topic: string) {
|
|||||||
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
throw new Error(Errors.INVALID_TOPIC_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod<StageInstance>("patch", endpoints.STAGE_INSTANCE(channelId), {
|
return await rest.runMethod<StageInstance>("patch", endpoints.STAGE_INSTANCE(channelId), snakelize(data));
|
||||||
topic,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// TODO: add resource link
|
/** https://discord.com/developers/docs/resources/stage-instance#auto-closing-stage-instance-structure */
|
||||||
export interface StageInstance {
|
export interface StageInstance {
|
||||||
/** The id of this Stage instance */
|
/** The id of this Stage instance */
|
||||||
id: string;
|
id: string;
|
||||||
@@ -8,4 +8,8 @@ export interface StageInstance {
|
|||||||
channelId: string;
|
channelId: string;
|
||||||
/** The topic of the Stage instance (1-120 characters) */
|
/** The topic of the Stage instance (1-120 characters) */
|
||||||
topic: string;
|
topic: string;
|
||||||
|
/** The privacy level of the Stage instance */
|
||||||
|
privacyLevel: number;
|
||||||
|
/** Whether or not Stage discovery is disabled */
|
||||||
|
discoverableDisabled: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user