✨ Add some few things that are useful to voiceState
This commit is contained in:
parent
d3ed30ce17
commit
b4a1ae389d
2 changed files with 108 additions and 5 deletions
|
@ -5,6 +5,7 @@ import { MemberPayload } from '../types/guild.ts'
|
||||||
import { Permissions } from '../utils/permissions.ts'
|
import { Permissions } from '../utils/permissions.ts'
|
||||||
import { SnowflakeBase } from './base.ts'
|
import { SnowflakeBase } from './base.ts'
|
||||||
import { Guild } from './guild.ts'
|
import { Guild } from './guild.ts'
|
||||||
|
import { VoiceChannel } from './guildVoiceChannel.ts'
|
||||||
import { Role } from './role.ts'
|
import { Role } from './role.ts'
|
||||||
import { User } from './user.ts'
|
import { User } from './user.ts'
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ export interface MemberData {
|
||||||
roles?: Array<Role | string>
|
roles?: Array<Role | string>
|
||||||
deaf?: boolean
|
deaf?: boolean
|
||||||
mute?: boolean
|
mute?: boolean
|
||||||
|
channel?: string | VoiceChannel | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Member extends SnowflakeBase {
|
export class Member extends SnowflakeBase {
|
||||||
|
@ -84,8 +86,11 @@ export class Member extends SnowflakeBase {
|
||||||
nick: data.nick,
|
nick: data.nick,
|
||||||
roles: data.roles?.map((e) => (typeof e === 'string' ? e : e.id)),
|
roles: data.roles?.map((e) => (typeof e === 'string' ? e : e.id)),
|
||||||
deaf: data.deaf,
|
deaf: data.deaf,
|
||||||
mute: data.mute
|
mute: data.mute,
|
||||||
|
channel_id:
|
||||||
|
typeof data.channel === 'string' ? data.channel : data.channel?.id
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await this.client.rest.patch(
|
const res = await this.client.rest.patch(
|
||||||
GUILD_MEMBER(this.guild.id, this.id),
|
GUILD_MEMBER(this.guild.id, this.id),
|
||||||
payload,
|
payload,
|
||||||
|
@ -125,7 +130,7 @@ export class Member extends SnowflakeBase {
|
||||||
*/
|
*/
|
||||||
async setMute(mute?: boolean): Promise<Member> {
|
async setMute(mute?: boolean): Promise<Member> {
|
||||||
return await this.edit({
|
return await this.edit({
|
||||||
mute: mute === undefined ? false : mute
|
mute: mute ?? false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +140,28 @@ export class Member extends SnowflakeBase {
|
||||||
*/
|
*/
|
||||||
async setDeaf(deaf?: boolean): Promise<Member> {
|
async setDeaf(deaf?: boolean): Promise<Member> {
|
||||||
return await this.edit({
|
return await this.edit({
|
||||||
deaf: deaf === undefined ? false : deaf
|
deaf: deaf ?? false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves a Member to another VC
|
||||||
|
* @param channel Channel to move(null or undefined to disconnect)
|
||||||
|
*/
|
||||||
|
async moveVoiceChannel(
|
||||||
|
channel?: string | VoiceChannel | null
|
||||||
|
): Promise<Member> {
|
||||||
|
return await this.edit({
|
||||||
|
channel: channel ?? null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects a Member from connected VC
|
||||||
|
*/
|
||||||
|
async disconnectVoice(): Promise<Member> {
|
||||||
|
return await this.edit({
|
||||||
|
channel: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +172,13 @@ export class Member extends SnowflakeBase {
|
||||||
return await this.setMute(false)
|
return await this.setMute(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undeafs the Member from VC.
|
||||||
|
*/
|
||||||
|
async undeaf(): Promise<Member> {
|
||||||
|
return await this.setDeaf(false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kicks the member.
|
* Kicks the member.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Client } from '../models/client.ts'
|
import { Client } from '../models/client.ts'
|
||||||
|
import { ChannelTypes } from '../types/channel.ts'
|
||||||
import { VoiceStatePayload } from '../types/voice.ts'
|
import { VoiceStatePayload } from '../types/voice.ts'
|
||||||
import { Base } from './base.ts'
|
import { Base } from './base.ts'
|
||||||
import { Guild } from './guild.ts'
|
import { Guild } from './guild.ts'
|
||||||
|
@ -52,12 +53,81 @@ export class VoiceState extends Base {
|
||||||
this.deaf = data.deaf ?? this.deaf
|
this.deaf = data.deaf ?? this.deaf
|
||||||
this.channelID = data.channel_id ?? this.channelID
|
this.channelID = data.channel_id ?? this.channelID
|
||||||
this.mute = data.mute ?? this.mute
|
this.mute = data.mute ?? this.mute
|
||||||
this.deaf = data.self_deaf ?? this.deaf
|
|
||||||
this.mute = data.self_mute ?? this.mute
|
|
||||||
this.selfDeaf = data.self_deaf ?? this.selfDeaf
|
this.selfDeaf = data.self_deaf ?? this.selfDeaf
|
||||||
this.selfMute = data.self_mute ?? this.selfMute
|
this.selfMute = data.self_mute ?? this.selfMute
|
||||||
this.stream = data.self_stream ?? this.stream
|
this.stream = data.self_stream ?? this.stream
|
||||||
this.video = data.self_video ?? this.video
|
this.video = data.self_video ?? this.video
|
||||||
this.suppress = data.suppress ?? this.suppress
|
this.suppress = data.suppress ?? this.suppress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects a Member from connected VC
|
||||||
|
*/
|
||||||
|
async disconnect(): Promise<Member | undefined> {
|
||||||
|
const result = this.member?.disconnectVoice()
|
||||||
|
if (result !== undefined) {
|
||||||
|
this.channelID = null
|
||||||
|
this.channel = null
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves a Member to another VC
|
||||||
|
* @param channel Channel to move(null or undefined to disconnect)
|
||||||
|
*/
|
||||||
|
async moveChannel(
|
||||||
|
channel?: string | VoiceChannel | null
|
||||||
|
): Promise<Member | undefined> {
|
||||||
|
const result = this.member?.moveVoiceChannel(channel)
|
||||||
|
if (result !== undefined) {
|
||||||
|
let channelFetched: VoiceChannel | null
|
||||||
|
let channelID: string | null
|
||||||
|
if (typeof channel === 'string') {
|
||||||
|
channelID = channel
|
||||||
|
const channelCached = await this.guild?.channels.fetch(channel)
|
||||||
|
if (channelCached?.type === ChannelTypes.GUILD_VOICE) {
|
||||||
|
channelFetched = channelCached as VoiceChannel
|
||||||
|
} else {
|
||||||
|
throw new Error(`Channel ${channel} is not a VoiceChannel.`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
channelID = channel?.id ?? null
|
||||||
|
channelFetched = channel ?? null
|
||||||
|
}
|
||||||
|
this.channelID = channelID
|
||||||
|
this.channel = channelFetched
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a Member mute in VC
|
||||||
|
* @param mute Value to set
|
||||||
|
*/
|
||||||
|
async setMute(mute?: boolean): Promise<Member | undefined> {
|
||||||
|
return this.member?.setMute(mute)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a Member deaf in VC
|
||||||
|
* @param deaf Value to set
|
||||||
|
*/
|
||||||
|
async setDeaf(deaf?: boolean): Promise<Member | undefined> {
|
||||||
|
return this.member?.setDeaf(deaf)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unmutes the Member from VC.
|
||||||
|
*/
|
||||||
|
async unmute(): Promise<Member | undefined> {
|
||||||
|
return await this.setMute(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undeafs the Member from VC.
|
||||||
|
*/
|
||||||
|
async undeaf(): Promise<Member | undefined> {
|
||||||
|
return await this.setDeaf(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue