#1815 editStageInstance and createStageInstance should use a transformer

#1815 editStageInstance and createStageInstance should use a transformer
This commit is contained in:
lts20050703
2021-12-22 11:20:40 +07:00
parent e9dfcbd6bf
commit 2ea419287f
5 changed files with 39 additions and 18 deletions

View File

@@ -91,6 +91,7 @@ import { transformApplicationCommand } from "./transformers/applicationCommand.t
import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts";
import { transformVoiceRegion } from "./transformers/voiceRegion.ts";
import { transformWidget } from "./transformers/widget.ts";
import { transformStageInstance } from "./transformers/stageInstance.ts";
export function createBot(options: CreateBotOptions): Bot {
const bot = {
@@ -484,6 +485,7 @@ export interface Transformers {
welcomeScreen: typeof transformWelcomeScreen;
voiceRegion: typeof transformVoiceRegion;
widget: typeof transformWidget;
stageInstance: typeof transformStageInstance;
}
export function createTransformers(options: Partial<Transformers>) {
@@ -517,6 +519,7 @@ export function createTransformers(options: Partial<Transformers>) {
welcomeScreen: options.welcomeScreen || transformWelcomeScreen,
voiceRegion: options.voiceRegion || transformVoiceRegion,
widget: options.widget || transformWidget,
stageInstance: options.stageInstance || transformStageInstance,
};
}

View File

@@ -10,10 +10,5 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st
privacy_level: privacyLevel || PrivacyLevel.GuildOnly,
});
return {
id: bot.transformers.snowflake(result.id),
guildId: bot.transformers.snowflake(result.guild_id),
channelId: bot.transformers.snowflake(result.channel_id),
topic: result.topic,
};
return bot.transformers.stageInstance(bot, result);
}

View File

@@ -9,10 +9,5 @@ export async function getStageInstance(bot: Bot, channelId: bigint) {
bot.constants.endpoints.STAGE_INSTANCE(channelId)
);
return {
id: bot.transformers.snowflake(result.id),
guildId: bot.transformers.snowflake(result.guild_id),
channelId: bot.transformers.snowflake(result.channel_id),
topic: result.topic,
};
return bot.transformers.stageInstance(bot, result);
}

View File

@@ -13,10 +13,5 @@ export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtL
}
);
return {
id: bot.transformers.snowflake(result.id),
guildId: bot.transformers.snowflake(result.guild_id),
channelId: bot.transformers.snowflake(result.channel_id),
topic: result.topic,
};
return bot.transformers.stageInstance(bot, result);
}

View File

@@ -0,0 +1,33 @@
import { Bot } from "../bot.ts";
import { StageInstance } from "../types/channels/stageInstance.ts";
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
import { PrivacyLevel } from "../types/channels/privacyLevel.ts";
export function transformStageInstance(
bot: Bot,
payload: SnakeCasedPropertiesDeep<StageInstance>
): DiscordenoStageInstance {
return {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
channelId: bot.transformers.snowflake(payload.channel_id),
topic: payload.topic,
privacyLevel: payload.privacy_level,
discoverableDisabled: payload.discoverable_disabled,
};
}
export interface DiscordenoStageInstance {
/** The id of this Stage instance */
id: bigint;
/** The guild id of the associated Stage channel */
guildId: bigint;
/** The id of the associated Stage channel */
channelId: bigint;
/** The topic of the Stage instance (1-120 characters) */
topic: string;
/** The privacy level of the Stage instance */
privacyLevel: PrivacyLevel;
/** Whether or not Stage discovery is disabled */
discoverableDisabled: boolean;
}