mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
Added a voiceSpeaking event, fired when a user in a voiceChannel starts or stops speaking. (#452)
* Added an event for the voice speaking packet. * Updated the docs to reflect the voiceSpeaking event addition. * Fixed some spacing issues in the VoiceConnection.js file. * Moved the speaking boolean to the User object.
This commit is contained in:
13
docs/docs_client.rst
Normal file → Executable file
13
docs/docs_client.rst
Normal file → Executable file
@@ -1015,19 +1015,24 @@ Emitted when a note is updated. Supplies a User_ object (containing the updated
|
|||||||
voiceJoin
|
voiceJoin
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
Emitted when a user joins a voice channel, supplies a VoiceChannel_ and a User_
|
Emitted when a user joins a voice channel, supplies a VoiceChannel_ and a User_.
|
||||||
|
|
||||||
voiceSwitch
|
voiceSwitch
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
Emitted when a user switches voice channels, supplies the old VoiceChannel_, the new VoiceChannel_, and a User_
|
Emitted when a user switches voice channels, supplies the old VoiceChannel_, the new VoiceChannel_, and a User_.
|
||||||
|
|
||||||
voiceLeave
|
voiceLeave
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
Emitted when a user leaves a voice channel, supplies a VoiceChannel_ and a User_
|
Emitted when a user leaves a voice channel, supplies a VoiceChannel_ and a User_.
|
||||||
|
|
||||||
voiceStateUpdate
|
voiceStateUpdate
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
Emitted when a user mutes/deafens, supplies a VoiceChannel_, User_, an object containing the old mute/selfMute/deaf/selfDeaf properties, and an object containing the new mute/selfMute/deaf/selfDeaf properties
|
Emitted when a user mutes/deafens, supplies a VoiceChannel_, User_, an object containing the old mute/selfMute/deaf/selfDeaf properties, and an object containing the new mute/selfMute/deaf/selfDeaf properties.
|
||||||
|
|
||||||
|
voiceSpeaking
|
||||||
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
Emitted when a user starts or stops speaking, supplies a VoiceChannel_, and User_. The `speaking` property under the supplied User_ object can be used to determine whether the user started or stopped speaking.
|
||||||
6
docs/docs_user.rst
Normal file → Executable file
6
docs/docs_user.rst
Normal file → Executable file
@@ -87,12 +87,16 @@ createdAt
|
|||||||
|
|
||||||
A `Date` referring to when the user was created.
|
A `Date` referring to when the user was created.
|
||||||
|
|
||||||
|
|
||||||
note
|
note
|
||||||
~~~~
|
~~~~
|
||||||
|
|
||||||
The note of the user, `String`.
|
The note of the user, `String`.
|
||||||
|
|
||||||
|
speaking
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
A boolean that represents whether or not the user is speaking in a voice channel, default is `false`.
|
||||||
|
|
||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ var User = (function (_Equality) {
|
|||||||
this.note = data.note || null;
|
this.note = data.note || null;
|
||||||
this.voiceChannel = null;
|
this.voiceChannel = null;
|
||||||
this.voiceState = {};
|
this.voiceState = {};
|
||||||
|
this.speaking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.mention = function mention() {
|
User.prototype.mention = function mention() {
|
||||||
|
|||||||
@@ -447,6 +447,24 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
self.mode = data.d.mode;
|
self.mode = data.d.mode;
|
||||||
self.emit("ready", self);
|
self.emit("ready", self);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
var user = self.server.members.get("id", data.d.user_id);
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
var speaking = data.d.speaking;
|
||||||
|
var channel = user.voiceChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
user.speaking = speaking;
|
||||||
|
self.client.emit("voiceSpeaking", channel, user);
|
||||||
|
} else {
|
||||||
|
self.client.emit("warn", "channel doesn't exist even though SPEAKING expects them to");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.client.emit("warn", "user doesn't exist even though SPEAKING expects them to");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
3
src/Structures/User.js
Normal file → Executable file
3
src/Structures/User.js
Normal file → Executable file
@@ -4,7 +4,7 @@ import Equality from "../Util/Equality";
|
|||||||
import {Endpoints} from "../Constants";
|
import {Endpoints} from "../Constants";
|
||||||
import {reg} from "../Util/ArgumentRegulariser";
|
import {reg} from "../Util/ArgumentRegulariser";
|
||||||
|
|
||||||
export default class User extends Equality{
|
export default class User extends Equality {
|
||||||
constructor(data, client){
|
constructor(data, client){
|
||||||
super();
|
super();
|
||||||
this.client = client;
|
this.client = client;
|
||||||
@@ -22,6 +22,7 @@ export default class User extends Equality{
|
|||||||
this.note = data.note || null;
|
this.note = data.note || null;
|
||||||
this.voiceChannel = null;
|
this.voiceChannel = null;
|
||||||
this.voiceState = {};
|
this.voiceState = {};
|
||||||
|
this.speaking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get createdAt() {
|
get createdAt() {
|
||||||
|
|||||||
36
src/Voice/VoiceConnection.js
Normal file → Executable file
36
src/Voice/VoiceConnection.js
Normal file → Executable file
@@ -231,9 +231,9 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
// options is the callback
|
// options is the callback
|
||||||
callback = options;
|
callback = options;
|
||||||
}
|
}
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.encoder
|
this.encoder
|
||||||
@@ -260,9 +260,9 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
// options is the callback
|
// options is the callback
|
||||||
callback = options;
|
callback = options;
|
||||||
}
|
}
|
||||||
if (typeof options !== "object") {
|
if (typeof options !== "object") {
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
options.volume = options.volume !== undefined ? options.volume : this.getVolume();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.encoder
|
this.encoder
|
||||||
@@ -290,9 +290,9 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
// volume is the callback
|
// volume is the callback
|
||||||
callback = volume;
|
callback = volume;
|
||||||
}
|
}
|
||||||
if (!ffmpegOptions instanceof Array) {
|
if (!ffmpegOptions instanceof Array) {
|
||||||
ffmpegOptions = [];
|
ffmpegOptions = [];
|
||||||
}
|
}
|
||||||
var volume = volume !== undefined ? volume : this.getVolume();
|
var volume = volume !== undefined ? volume : this.getVolume();
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.encoder
|
this.encoder
|
||||||
@@ -402,6 +402,24 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
self.mode = data.d.mode;
|
self.mode = data.d.mode;
|
||||||
self.emit("ready", self);
|
self.emit("ready", self);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
var user = self.server.members.get("id", data.d.user_id);
|
||||||
|
|
||||||
|
if (user){
|
||||||
|
var speaking = data.d.speaking;
|
||||||
|
var channel = user.voiceChannel;
|
||||||
|
|
||||||
|
if (channel){
|
||||||
|
user.speaking = speaking;
|
||||||
|
self.client.emit("voiceSpeaking", channel, user);
|
||||||
|
} else {
|
||||||
|
self.client.emit("warn", "channel doesn't exist even though SPEAKING expects them to");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.client.emit("warn", "user doesn't exist even though SPEAKING expects them to");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user