Compare commits

...

7 Commits

Author SHA1 Message Date
iCrawl
6e11596cb1 chore(Release): version upgrade 2021-03-31 22:53:48 +02:00
Souji
7efc295415 fix(InviteDelete): guild can be missing (#5457) 2021-03-31 22:42:10 +02:00
anandre
8e8d9b490a docs(ReactionUserManager): fetch description (#5382)
The description currently says that fetching returns all users on the reaction.  This is incorrect, as there is an API limit of 100 users per fetch.  This PR changes the description to better match the actual behavior.
2021-03-29 05:48:58 +02:00
iCrawl
8a7abc9f06 chore(Release): version upgrade 2020-11-26 00:03:06 +01:00
monbrey
a6b922f8ae fix(MessageReaction): set MessageReaction#me in patch method (#5047) 2020-11-25 23:57:03 +01:00
Amish Shah
5328648f45 fix(Voice*): filter out silent audio from video users (#5035) 2020-11-25 23:56:55 +01:00
izexi
f8b0c01c26 fix(GuildTemplate): 'guild' getter (#5040) 2020-11-25 23:56:41 +01:00
10 changed files with 1872 additions and 930 deletions

2701
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "discord.js",
"version": "12.5.0",
"version": "12.5.2",
"description": "A powerful library for interacting with the Discord API",
"main": "./src/index",
"types": "./typings/index.d.ts",
@@ -51,31 +51,31 @@
"@discordjs/form-data": "^3.0.1",
"abort-controller": "^3.0.0",
"node-fetch": "^2.6.1",
"prism-media": "^1.2.2",
"prism-media": "^1.2.9",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.3.1"
"ws": "^7.4.4"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-angular": "^11.0.0",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-angular": "^12.0.1",
"@types/node": "^12.12.6",
"@types/ws": "^7.2.7",
"cross-env": "^7.0.2",
"@types/ws": "^7.4.0",
"cross-env": "^7.0.3",
"discord.js-docgen": "git+https://github.com/discordjs/docgen.git",
"dtslint": "^4.0.4",
"eslint": "^7.11.0",
"dtslint": "^4.0.8",
"eslint": "^7.23.0",
"eslint-config-prettier": "^6.13.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^4.3.0",
"jest": "^26.6.0",
"jest": "^26.6.3",
"json-filter-loader": "^1.0.0",
"lint-staged": "^10.4.2",
"prettier": "^2.1.2",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"terser-webpack-plugin": "^4.2.3",
"tslint": "^6.1.3",
"typescript": "^4.0.3",
"typescript": "^4.2.3",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
},

View File

@@ -9,7 +9,7 @@ class InviteDeleteAction extends Action {
const client = this.client;
const channel = client.channels.cache.get(data.channel_id);
const guild = client.guilds.cache.get(data.guild_id);
if (!channel && !guild) return false;
if (!channel) return false;
const inviteData = Object.assign(data, { channel, guild });
const invite = new Invite(client, inviteData);

View File

@@ -473,7 +473,11 @@ class VoiceConnection extends EventEmitter {
}
onStartSpeaking({ user_id, ssrc, speaking }) {
this.ssrcMap.set(+ssrc, { userID: user_id, speaking: speaking });
this.ssrcMap.set(+ssrc, {
...(this.ssrcMap.get(+ssrc) || {}),
userID: user_id,
speaking: speaking,
});
}
/**

View File

@@ -189,7 +189,11 @@ class VoiceWebSocket extends EventEmitter {
this.emit('sessionDescription', packet.d);
break;
case VoiceOPCodes.CLIENT_CONNECT:
this.connection.ssrcMap.set(+packet.d.audio_ssrc, { userID: packet.d.user_id, speaking: 0 });
this.connection.ssrcMap.set(+packet.d.audio_ssrc, {
userID: packet.d.user_id,
speaking: 0,
hasVideo: Boolean(packet.d.video_ssrc),
});
break;
case VoiceOPCodes.CLIENT_DISCONNECT:
const streamInfo = this.connection.receiver && this.connection.receiver.packets.streams.get(packet.d.user_id);

View File

@@ -1,7 +1,9 @@
'use strict';
const EventEmitter = require('events');
const Speaking = require('../../../util/Speaking');
const secretbox = require('../util/Secretbox');
const { SILENCE_FRAME } = require('../util/Silence');
// The delay between packets when a user is considered to have stopped speaking
// https://github.com/discordjs/discord.js/issues/3524#issuecomment-540373200
@@ -84,12 +86,30 @@ class PacketHandler extends EventEmitter {
const userStat = this.connection.ssrcMap.get(ssrc);
if (!userStat) return;
let opusPacket;
const streamInfo = this.streams.get(userStat.userID);
// If the user is in video, we need to check if the packet is just silence
if (userStat.hasVideo) {
opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
// Only emit an error if we were actively receiving packets from this user
if (streamInfo) {
this.emit('error', opusPacket);
return;
}
}
if (SILENCE_FRAME.equals(opusPacket)) {
// If this is a silence frame, pretend we never received it
return;
}
}
let speakingTimeout = this.speakingTimeouts.get(ssrc);
if (typeof speakingTimeout === 'undefined') {
// Ensure at least the speaking bit is set.
// As the object is by reference, it's only needed once per client re-connect.
if (userStat.speaking === 0) {
userStat.speaking = 1;
userStat.speaking = Speaking.FLAGS.SPEAKING;
}
this.connection.onSpeaking({ user_id: userStat.userID, ssrc: ssrc, speaking: userStat.speaking });
speakingTimeout = this.receiver.connection.client.setTimeout(() => {
@@ -106,15 +126,17 @@ class PacketHandler extends EventEmitter {
speakingTimeout.refresh();
}
let stream = this.streams.get(userStat.userID);
if (!stream) return;
stream = stream.stream;
const opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
this.emit('error', opusPacket);
return;
if (streamInfo) {
const { stream } = streamInfo;
if (!opusPacket) {
opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
this.emit('error', opusPacket);
return;
}
}
stream.push(opusPacket);
}
stream.push(opusPacket);
}
}

View File

@@ -10,4 +10,6 @@ class Silence extends Readable {
}
}
Silence.SILENCE_FRAME = SILENCE_FRAME;
module.exports = Silence;

View File

@@ -25,7 +25,7 @@ class ReactionUserManager extends BaseManager {
*/
/**
* Fetches all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
* Fetches the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
* @param {Object} [options] Options for fetching the users
* @param {number} [options.limit=100] The maximum amount of users to fetch, defaults to 100
* @param {Snowflake} [options.before] Limit fetching users to those with an id lower than the supplied id

View File

@@ -198,8 +198,9 @@ class GuildTemplate extends Base {
* @readonly
*/
get guild() {
return this.client.guilds.get(this.guildID) || null;
return this.client.guilds.cache.get(this.guildID) || null;
}
/**
* The URL of this template
* @type {string}

View File

@@ -28,12 +28,6 @@ class MessageReaction {
*/
this.message = message;
/**
* Whether the client has given this reaction
* @type {boolean}
*/
this.me = data.me;
/**
* A manager of the users that have given this reaction
* @type {ReactionUserManager}
@@ -54,6 +48,12 @@ class MessageReaction {
*/
this.count = data.count;
}
/**
* Whether the client has given this reaction
* @type {boolean}
*/
this.me = data.me;
}
/**