mirror of
https://github.com/projectdysnomia/dysnomia.git
synced 2026-12-02 13:48:31 +02:00
This should allow for not using the `Client.channelGuildMap`, `Client.threadGuildMap`, and `Client.guildShardMap` when `caching.disableMaps` is on. Some caveats: - Obviously `getChannel` will do linear searching now, but this can be skipped with guild hinting. `getChannel` now has a `guildIDHint` parameter for getting that specific guild rather than searching all of them. Which has some caveats: - `editChannelPosition`'s option param has `guildIDHint`, it's channel's corresponding function will use it. - Same for `joinVoiceChannel` and `leaveVoiceChannel`, but `leaveVoiceChannel` has it's hinting in a new parameter. - `ThreadMember`'s construction to find the guild *will* do linear searching, sad. - Many of the shard events that use `getChannel` either now hint at the guild or just gets the guild directly. --------- Co-authored-by: TTtie <me@tttie.cz>
153 lines
5.6 KiB
JavaScript
153 lines
5.6 KiB
JavaScript
"use strict";
|
|
|
|
const Collection = require("../util/Collection");
|
|
const GuildChannel = require("./GuildChannel");
|
|
const Member = require("./Member");
|
|
const PermissionOverwrite = require("./PermissionOverwrite");
|
|
|
|
/**
|
|
* Represents a guild voice channel. See GuildChannel for more properties and methods.
|
|
* @extends GuildChannel
|
|
*/
|
|
class VoiceChannel extends GuildChannel {
|
|
#client;
|
|
constructor(data, client) {
|
|
super(data, client);
|
|
this.#client = client;
|
|
/**
|
|
* Collection of Members in this channel
|
|
* @type {Collection<Member>}
|
|
*/
|
|
this.voiceMembers = new Collection(Member);
|
|
}
|
|
|
|
update(data, client) {
|
|
super.update(data, client);
|
|
|
|
if(data.bitrate !== undefined) {
|
|
/**
|
|
* The bitrate of the channel
|
|
* @type {Number?}
|
|
*/
|
|
this.bitrate = data.bitrate;
|
|
}
|
|
if(data.rtc_region !== undefined) {
|
|
/**
|
|
* The RTC region ID of the channel (automatic when `null`)
|
|
* @type {String?}
|
|
*/
|
|
this.rtcRegion = data.rtc_region;
|
|
}
|
|
if(data.permission_overwrites) {
|
|
/**
|
|
* Collection of PermissionOverwrites in this channel
|
|
* @type {Collection<PermissionOverwrite>}
|
|
*/
|
|
this.permissionOverwrites = new Collection(PermissionOverwrite);
|
|
data.permission_overwrites.forEach((overwrite) => {
|
|
this.permissionOverwrites.add(overwrite);
|
|
});
|
|
}
|
|
if(data.position !== undefined) {
|
|
/**
|
|
* The position of the channel
|
|
* @type {Number}
|
|
*/
|
|
this.position = data.position;
|
|
}
|
|
if(data.nsfw !== undefined) {
|
|
/**
|
|
* Whether the channel is an NSFW channel or not
|
|
* @type {Boolean}
|
|
*/
|
|
this.nsfw = data.nsfw;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create an invite for the channel
|
|
* @param {Object} [options] Invite generation options
|
|
* @param {Number} [options.maxAge] How long the invite should last in seconds
|
|
* @param {Number} [options.maxUses] How many uses the invite should last for
|
|
* @param {Boolean} [options.temporary] Whether the invite grants temporary membership or not
|
|
* @param {Boolean} [options.unique] Whether the invite is unique or not
|
|
* @param {Array<String>} [options.roleIDs] An array of role IDs to give to the users when they accept the invite
|
|
* @param {Array<String>} [options.targetUserIDs] An array of user IDs that are able to accept this invite
|
|
* @param {String} [reason] The reason to be displayed in audit logs
|
|
* @returns {Promise<Invite>}
|
|
*/
|
|
createInvite(options, reason) {
|
|
return this.#client.createChannelInvite.call(this.#client, this.id, options, reason);
|
|
}
|
|
|
|
/**
|
|
* Get all invites in the channel
|
|
* @returns {Promise<Array<Invite>>}
|
|
*/
|
|
getInvites() {
|
|
return this.#client.getChannelInvites.call(this.#client, this.id);
|
|
}
|
|
|
|
/**
|
|
* Joins the channel.
|
|
* @param {Object} [options] VoiceConnection constructor options
|
|
* @param {Object} [options.daveEncryption=true] Whether to enable DAVE E2EE encryption for voice connections
|
|
* @param {Object} [options.opusOnly] Skip opus encoder initialization. You should not enable this unless you know what you are doing
|
|
* @param {Object} [options.udpTimeout] How long the IP discovery from the UDP should take until it times out
|
|
* @param {Number} [options.decryptionFailureTolerance] How many consecutive decryption failures needed to reinitialize the E2EE session to recover
|
|
* @param {Object} [options.shared] Whether the VoiceConnection will be part of a SharedStream or not
|
|
* @param {Boolean} [options.selfMute] Whether the bot joins the channel muted or not
|
|
* @param {Boolean} [options.selfDeaf] Whether the bot joins the channel deafened or not
|
|
* @param {Object} [options.ws] Additional options for the WebSocket connection, defaults to the options set in the client
|
|
* @returns {Promise<VoiceConnection>} Resolves with a VoiceConnection
|
|
*/
|
|
join(options) {
|
|
return this.#client.joinVoiceChannel.call(this.#client, this.id, {
|
|
...(options || {}),
|
|
guildIDHint: this.guild.id
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Leaves the channel.
|
|
*/
|
|
leave() {
|
|
return this.#client.leaveVoiceChannel.call(this.#client, this.id, this.guild.id);
|
|
}
|
|
|
|
/**
|
|
* Send a soundboard sound to the voice channel
|
|
* @param {Object} options The soundboard sound options
|
|
* @param {String} options.soundID The ID of the soundboard sound
|
|
* @param {String} [options.sourceGuildID] The ID of the guild where the soundboard sound was created, if not in the same guild
|
|
* @returns {Promise}
|
|
*/
|
|
sendSoundboardSound(options) {
|
|
return this.#client.sendSoundboardSound.call(this.#client, this.id, options);
|
|
}
|
|
|
|
/**
|
|
* Set the voice channel status
|
|
* @param {Object} options The voice channel status options
|
|
* @param {String?} options.status The status to set
|
|
* @param {String} [options.reason] The reason to be setting the voice status
|
|
* @returns {Promise}
|
|
*/
|
|
setVoiceStatus(options) {
|
|
return this.#client.setVoiceChannelStatus.call(this.#client, this.id, options);
|
|
}
|
|
|
|
toJSON(props = []) {
|
|
return super.toJSON([
|
|
"bitrate",
|
|
"permissionOverwrites",
|
|
"position",
|
|
"rtcRegion",
|
|
"voiceMembers",
|
|
...props
|
|
]);
|
|
}
|
|
}
|
|
|
|
module.exports = VoiceChannel;
|