Files
discordeno/packages/bot/src/transformers/voiceState.ts
T
FlenyandLink 4581222cf4 feat(transformers)!: Partial transformers (#4436)
* refactor(bot)!: setup desired properties for all transformers

SetupDesiredProps when is given an object that does not corrispond to a transformer object that supports desired properties will behave like TransformProperty on the entire object as when it tries to get the properties for said object it will find `never` as the props and for `IsKeyDesired` a props of `never` means that all props are desired.

* feat(transformers)!: Handle partials in transformers

* Add expiresAt to invite create event

* Use Equals helper, clean up a bit the code

* Explicit the IsKeyDesired TProps never behavior

* Fix type errors

* format

* Add all trasformer objects to bot.transformers.$inferredTypes

* Use transfromerInformations for bot.transformers.$inferredTypes

* code review

* code review

* fix component transformer

* fix

* Update packages/bot/src/transformers/types.ts

* Fixes from Tri (+ GPT sol) code review

---------

Co-authored-by: Link <link20050703@gmail.com>
2026-07-31 15:12:15 +05:30

25 lines
1.5 KiB
TypeScript

import type { BigString, DiscordVoiceState } from '@discordeno/types';
import type { Bot } from '../bot.js';
import type { DesiredPropertiesBehavior, SetupDesiredProps, TransformersDesiredProperties } from '../desiredProperties.js';
import { callCustomizer } from '../transformers.js';
import { VoiceStateToggles } from './toggles/voice.js';
import type { VoiceState } from './types.js';
export function transformVoiceState(bot: Bot, payload: Partial<DiscordVoiceState>, extra?: { guildId?: BigString; partial?: boolean }) {
const props = bot.transformers.desiredProperties.voiceState;
const voiceState = {} as SetupDesiredProps<VoiceState, TransformersDesiredProperties, DesiredPropertiesBehavior>;
if (props.requestToSpeakTimestamp && payload.request_to_speak_timestamp)
voiceState.requestToSpeakTimestamp = Date.parse(payload.request_to_speak_timestamp);
if (props.channelId && payload.channel_id) voiceState.channelId = bot.transformers.snowflake(payload.channel_id);
if (props.guildId && extra?.guildId) voiceState.guildId = bot.transformers.snowflake(extra.guildId);
if (props.toggles) voiceState.toggles = new VoiceStateToggles(payload);
if (props.sessionId && payload.session_id !== undefined) voiceState.sessionId = payload.session_id;
if (props.userId && payload.user_id) voiceState.userId = bot.transformers.snowflake(payload.user_id);
return callCustomizer('voiceState', bot, payload, voiceState, {
guildId: extra?.guildId ? bot.transformers.snowflake(extra.guildId) : undefined,
partial: extra?.partial ?? false,
});
}