mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
The beginnings of the voiceUserStateChange event
This commit is contained in:
@@ -1703,16 +1703,31 @@ var InternalClient = (function () {
|
|||||||
if (user && server) {
|
if (user && server) {
|
||||||
|
|
||||||
if (data.channel_id) {
|
if (data.channel_id) {
|
||||||
// speaking
|
// in voice channel
|
||||||
var channel = self.channels.get("id", data.channel_id);
|
var channel = self.channels.get("id", data.channel_id);
|
||||||
if (channel) {
|
if (channel && channel.type === "voice") {
|
||||||
if (server.eventStartSpeaking(user, channel)) client.emit("voiceJoin", user, channel);else client.emit("warn", "voice state error occurred in adding");
|
var oldState = {
|
||||||
|
mute: user.voiceState.mute,
|
||||||
|
self_mute: user.voiceState.self_mute,
|
||||||
|
deaf: user.voiceState.deaf,
|
||||||
|
self_deaf: user.voiceState.self_deaf
|
||||||
|
};
|
||||||
|
user.voiceState.mute = data.mute;
|
||||||
|
user.voiceState.self_mute = data.self_mute;
|
||||||
|
user.voiceState.deaf = data.deaf;
|
||||||
|
user.voiceState.self_deaf = data.self_deaf;
|
||||||
|
if ((oldState.mute != user.voiceState.mute || oldState.self_mute != user.voiceState.self_mute || oldState.deaf != user.voiceState.deaf || oldState.self_deaf != user.voiceState.self_deaf) && oldState.mute !== undefined) {
|
||||||
|
client.emit("voiceUserStateChange", user, oldState);
|
||||||
|
} else {
|
||||||
|
server.eventVoiceJoin(user, channel);
|
||||||
|
client.emit("voiceJoin", user, channel);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
client.emit("warn", "voice state channel not in cache");
|
client.emit("warn", "voice state channel not in cache");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not speaking
|
// not in voice channel
|
||||||
client.emit("voiceLeave", user, server.eventStopSpeaking(user));
|
client.emit("voiceLeave", user, server.eventVoiceLeave(user));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client.emit("warn", "voice state update but user or server not in cache");
|
client.emit("warn", "voice state update but user or server not in cache");
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ var Server = (function (_Equality) {
|
|||||||
var _user = this.members.get("id", voiceState.user_id);
|
var _user = this.members.get("id", voiceState.user_id);
|
||||||
var channel = this.channels.get("id", voiceState.channel_id);
|
var channel = this.channels.get("id", voiceState.channel_id);
|
||||||
if (_user && channel) {
|
if (_user && channel) {
|
||||||
this.eventStartSpeaking(_user, channel);
|
this.eventVoiceJoin(_user, channel);
|
||||||
} else {
|
} else {
|
||||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||||
}
|
}
|
||||||
@@ -199,24 +199,15 @@ var Server = (function (_Equality) {
|
|||||||
return this.name;
|
return this.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.eventStartSpeaking = function eventStartSpeaking(user, channel) {
|
Server.prototype.eventVoiceJoin = function eventVoiceJoin(user, channel) {
|
||||||
channel = this.channels.get("id", channel.id);
|
// removes from other speaking channels first
|
||||||
if (channel && channel.type === "voice") {
|
this.eventVoiceLeave(user);
|
||||||
// good
|
|
||||||
|
|
||||||
// removes from other speaking channels first
|
channel.members.add(user);
|
||||||
this.eventStopSpeaking(user);
|
user.voiceChannel = channel;
|
||||||
|
|
||||||
channel.members.add(user);
|
|
||||||
user.voiceChannel = channel;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// bad
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.eventStopSpeaking = function eventStopSpeaking(user) {
|
Server.prototype.eventVoiceLeave = function eventVoiceLeave(user) {
|
||||||
for (var _iterator3 = this.channels.getAll("type", "voice"), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
for (var _iterator3 = this.channels.getAll("type", "voice"), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||||
var _ref3;
|
var _ref3;
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ var User = (function (_Equality) {
|
|||||||
channel: null
|
channel: null
|
||||||
};
|
};
|
||||||
this.voiceChannel = null;
|
this.voiceChannel = null;
|
||||||
|
this.voiceState = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.mention = function mention() {
|
User.prototype.mention = function mention() {
|
||||||
|
|||||||
@@ -1491,25 +1491,39 @@ export default class InternalClient {
|
|||||||
var user = self.users.get("id", data.user_id);
|
var user = self.users.get("id", data.user_id);
|
||||||
var server = self.servers.get("id", data.guild_id);
|
var server = self.servers.get("id", data.guild_id);
|
||||||
|
|
||||||
if(user && server){
|
if (user && server) {
|
||||||
|
|
||||||
if(data.channel_id){
|
if (data.channel_id) {
|
||||||
// speaking
|
// in voice channel
|
||||||
var channel = self.channels.get("id", data.channel_id);
|
var channel = self.channels.get("id", data.channel_id);
|
||||||
if(channel){
|
if (channel && channel.type === "voice") {
|
||||||
if(server.eventStartSpeaking(user, channel))
|
var oldState = {
|
||||||
|
mute: user.voiceState.mute,
|
||||||
|
self_mute: user.voiceState.self_mute,
|
||||||
|
deaf: user.voiceState.deaf,
|
||||||
|
self_deaf: user.voiceState.self_deaf
|
||||||
|
};
|
||||||
|
user.voiceState.mute = data.mute;
|
||||||
|
user.voiceState.self_mute = data.self_mute;
|
||||||
|
user.voiceState.deaf = data.deaf;
|
||||||
|
user.voiceState.self_deaf = data.self_deaf;
|
||||||
|
if ((oldState.mute != user.voiceState.mute || oldState.self_mute != user.voiceState.self_mute
|
||||||
|
|| oldState.deaf != user.voiceState.deaf || oldState.self_deaf != user.voiceState.self_deaf)
|
||||||
|
&& oldState.mute !== undefined) {
|
||||||
|
client.emit("voiceUserStateChange", user, oldState);
|
||||||
|
} else {
|
||||||
|
server.eventVoiceJoin(user, channel);
|
||||||
client.emit("voiceJoin", user, channel);
|
client.emit("voiceJoin", user, channel);
|
||||||
else
|
}
|
||||||
client.emit("warn", "voice state error occurred in adding");
|
} else {
|
||||||
}else{
|
|
||||||
client.emit("warn", "voice state channel not in cache");
|
client.emit("warn", "voice state channel not in cache");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
// not speaking
|
// not in voice channel
|
||||||
client.emit("voiceLeave", user, server.eventStopSpeaking(user));
|
client.emit("voiceLeave", user, server.eventVoiceLeave(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
client.emit("warn", "voice state update but user or server not in cache");
|
client.emit("warn", "voice state update but user or server not in cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export default class Server extends Equality {
|
|||||||
let user = this.members.get("id", voiceState.user_id);
|
let user = this.members.get("id", voiceState.user_id);
|
||||||
let channel = this.channels.get("id", voiceState.channel_id);
|
let channel = this.channels.get("id", voiceState.channel_id);
|
||||||
if (user && channel) {
|
if (user && channel) {
|
||||||
this.eventStartSpeaking(user, channel);
|
this.eventVoiceJoin(user, channel);
|
||||||
} else {
|
} else {
|
||||||
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
this.client.emit("warn", "user doesn't exist even though READY expects them to");
|
||||||
}
|
}
|
||||||
@@ -161,26 +161,17 @@ export default class Server extends Equality {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
eventStartSpeaking(user, channel){
|
eventVoiceJoin(user, channel) {
|
||||||
channel = this.channels.get("id", channel.id);
|
// removes from other speaking channels first
|
||||||
if(channel && channel.type === "voice"){
|
this.eventVoiceLeave(user);
|
||||||
// good
|
|
||||||
|
|
||||||
// removes from other speaking channels first
|
channel.members.add(user);
|
||||||
this.eventStopSpeaking(user);
|
user.voiceChannel = channel;
|
||||||
|
|
||||||
channel.members.add(user);
|
|
||||||
user.voiceChannel = channel;
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
// bad
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eventStopSpeaking(user){
|
eventVoiceLeave(user) {
|
||||||
for(let chan of this.channels.getAll("type", "voice")){
|
for (let chan of this.channels.getAll("type", "voice")) {
|
||||||
if(chan.members.has(user)){
|
if (chan.members.has(user)) {
|
||||||
chan.members.remove(user);
|
chan.members.remove(user);
|
||||||
user.voiceChannel = null;
|
user.voiceChannel = null;
|
||||||
return chan;
|
return chan;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export default class User extends Equality{
|
|||||||
channel : null
|
channel : null
|
||||||
};
|
};
|
||||||
this.voiceChannel = null;
|
this.voiceChannel = null;
|
||||||
|
this.voiceState = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarURL(){
|
get avatarURL(){
|
||||||
|
|||||||
Reference in New Issue
Block a user