mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Add voice state http endpoints (#3841)
This commit is contained in:
@@ -120,6 +120,7 @@ import type {
|
||||
Template,
|
||||
ThreadMember,
|
||||
User,
|
||||
VoiceState,
|
||||
Webhook,
|
||||
WelcomeScreen,
|
||||
} from './transformers/index.js'
|
||||
@@ -453,6 +454,12 @@ export function createBotHelpers(bot: Bot): BotHelpers {
|
||||
getStageInstance: async (channelId) => {
|
||||
return bot.transformers.stageInstance(bot, snakelize(await bot.rest.getStageInstance(channelId)))
|
||||
},
|
||||
getOwnVoiceState: async (guildId) => {
|
||||
return bot.transformers.voiceState(bot, { guildId, voiceState: snakelize(await bot.rest.getOwnVoiceState(guildId)) })
|
||||
},
|
||||
getUserVoiceState: async (guildId, userId) => {
|
||||
return bot.transformers.voiceState(bot, { guildId, voiceState: snakelize(await bot.rest.getUserVoiceState(guildId, userId)) })
|
||||
},
|
||||
getSticker: async (stickerId) => {
|
||||
return bot.transformers.sticker(bot, snakelize(await bot.rest.getSticker(stickerId)))
|
||||
},
|
||||
@@ -874,6 +881,8 @@ export interface BotHelpers {
|
||||
) => Promise<Array<{ user: User; member?: Member }>>
|
||||
getSessionInfo: () => Promise<CamelizedDiscordGetGatewayBot>
|
||||
getStageInstance: (channelId: BigString) => Promise<StageInstance>
|
||||
getOwnVoiceState: (guildId: BigString) => Promise<VoiceState>
|
||||
getUserVoiceState: (guildId: BigString, userId: BigString) => Promise<VoiceState>
|
||||
getSticker: (stickerId: BigString) => Promise<Sticker>
|
||||
getThreadMember: (channelId: BigString, userId: BigString) => Promise<ThreadMember>
|
||||
getThreadMembers: (channelId: BigString) => Promise<ThreadMember[]>
|
||||
|
||||
@@ -279,7 +279,7 @@ export interface Transformers {
|
||||
messageInteractionMetadata: (bot: Bot, payload: DiscordMessageInteractionMetadata) => MessageInteractionMetadata
|
||||
messageCall: (bot: Bot, payload: DiscordMessageCall) => MessageCall
|
||||
role: (bot: Bot, payload: { role: DiscordRole } & { guildId: BigString }) => Role
|
||||
voiceState: (bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) => VoiceState
|
||||
voiceState: (bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: BigString }) => VoiceState
|
||||
interaction: (bot: Bot, payload: { interaction: DiscordInteraction; shardId: number }) => Interaction
|
||||
interactionDataOptions: (bot: Bot, payload: DiscordInteractionDataOption) => InteractionDataOption
|
||||
integration: (bot: Bot, payload: DiscordIntegrationCreateUpdate) => Integration
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { DiscordVoiceState } from '@discordeno/types'
|
||||
import type { BigString, DiscordVoiceState } from '@discordeno/types'
|
||||
import type { Bot, VoiceState } from '../index.js'
|
||||
import { VoiceStateToggles } from './toggles/voice.js'
|
||||
|
||||
export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }): VoiceState {
|
||||
export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: BigString }): VoiceState {
|
||||
const props = bot.transformers.desiredProperties.voiceState
|
||||
const voiceState = {} as VoiceState
|
||||
|
||||
if (props.requestToSpeakTimestamp && payload.voiceState.request_to_speak_timestamp)
|
||||
voiceState.requestToSpeakTimestamp = Date.parse(payload.voiceState.request_to_speak_timestamp)
|
||||
if (props.channelId && payload.voiceState.channel_id) voiceState.channelId = bot.transformers.snowflake(payload.voiceState.channel_id)
|
||||
if (props.guildId) voiceState.guildId = payload.guildId
|
||||
if (props.guildId) voiceState.guildId = bot.transformers.snowflake(payload.guildId)
|
||||
if (props.toggles) voiceState.toggles = new VoiceStateToggles(payload.voiceState)
|
||||
if (props.sessionId) voiceState.sessionId = payload.voiceState.session_id
|
||||
if (props.userId && payload.voiceState.user_id) voiceState.userId = bot.transformers.snowflake(payload.voiceState.user_id) ?? 0n
|
||||
|
||||
@@ -44,6 +44,7 @@ import {
|
||||
type DiscordUser,
|
||||
type DiscordVanityUrl,
|
||||
type DiscordVoiceRegion,
|
||||
type DiscordVoiceState,
|
||||
type DiscordWebhook,
|
||||
type DiscordWelcomeScreen,
|
||||
InteractionResponseTypes,
|
||||
@@ -1308,6 +1309,14 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
return await rest.get<DiscordStageInstance>(rest.routes.channels.stage(channelId))
|
||||
},
|
||||
|
||||
async getOwnVoiceState(guildId) {
|
||||
return await rest.get<DiscordVoiceState>(rest.routes.guilds.voice(guildId))
|
||||
},
|
||||
|
||||
async getUserVoiceState(guildId, userId) {
|
||||
return await rest.get<DiscordVoiceState>(rest.routes.guilds.voice(guildId, userId))
|
||||
},
|
||||
|
||||
async getSticker(stickerId: BigString) {
|
||||
return await rest.get<DiscordSticker>(rest.routes.sticker(stickerId))
|
||||
},
|
||||
|
||||
@@ -50,6 +50,7 @@ import type {
|
||||
CamelizedDiscordUser,
|
||||
CamelizedDiscordVanityUrl,
|
||||
CamelizedDiscordVoiceRegion,
|
||||
CamelizedDiscordVoiceState,
|
||||
CamelizedDiscordWebhook,
|
||||
CamelizedDiscordWelcomeScreen,
|
||||
// Type required for typedoc
|
||||
@@ -1321,7 +1322,7 @@ export interface RestManager {
|
||||
* If attempting to request to speak:
|
||||
* - Requires the `REQUEST_TO_SPEAK` permission.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#modify-current-user-voice-state}
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#modify-current-user-voice-state}
|
||||
*/
|
||||
editOwnVoiceState: (guildId: BigString, options: EditOwnVoiceState) => Promise<void>
|
||||
/**
|
||||
@@ -1409,7 +1410,7 @@ export interface RestManager {
|
||||
*
|
||||
* Requires the `MUTE_MEMBERS` permission.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#modify-current-user-voice-state}
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#modify-user-voice-state}
|
||||
*/
|
||||
editUserVoiceState: (guildId: BigString, options: EditUserVoiceState) => Promise<void>
|
||||
/**
|
||||
@@ -2213,6 +2214,25 @@ export interface RestManager {
|
||||
* @see {@link https://discord.com/developers/docs/resources/stage-instance#get-stage-instance}
|
||||
*/
|
||||
getStageInstance: (channelId: BigString) => Promise<CamelizedDiscordStageInstance>
|
||||
/**
|
||||
* Returns the current user's voice state in the guild.
|
||||
*
|
||||
* @param guildId - The ID of the guild to get the voice state from.
|
||||
* @returns An instance of {@link CamelizedDiscordVoiceState}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#get-current-user-voice-state}
|
||||
*/
|
||||
getOwnVoiceState: (guildId: BigString) => Promise<CamelizedDiscordVoiceState>
|
||||
/**
|
||||
* Returns the specified user's voice state in the guild.
|
||||
*
|
||||
* @param guildId - The ID of the guild to get the voice state from.
|
||||
* @param userId - The ID of the user to get the voice state from
|
||||
* @returns An instance of {@link CamelizedDiscordVoiceState}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/voice#get-user-voice-state}
|
||||
*/
|
||||
getUserVoiceState: (guildId: BigString, userId: BigString) => Promise<CamelizedDiscordVoiceState>
|
||||
/**
|
||||
* Returns a sticker object for the given sticker ID.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user