The beginnings of the voiceUserStateChange event

This commit is contained in:
abalabahaha
2016-01-29 17:46:46 -08:00
parent 8726b23730
commit 6af71bf639
6 changed files with 64 additions and 51 deletions

View File

@@ -1703,16 +1703,31 @@ var InternalClient = (function () {
if (user && server) {
if (data.channel_id) {
// speaking
// in voice channel
var channel = self.channels.get("id", data.channel_id);
if (channel) {
if (server.eventStartSpeaking(user, channel)) client.emit("voiceJoin", user, channel);else client.emit("warn", "voice state error occurred in adding");
if (channel && channel.type === "voice") {
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 {
client.emit("warn", "voice state channel not in cache");
}
} else {
// not speaking
client.emit("voiceLeave", user, server.eventStopSpeaking(user));
// not in voice channel
client.emit("voiceLeave", user, server.eventVoiceLeave(user));
}
} else {
client.emit("warn", "voice state update but user or server not in cache");

View File

@@ -153,7 +153,7 @@ var Server = (function (_Equality) {
var _user = this.members.get("id", voiceState.user_id);
var channel = this.channels.get("id", voiceState.channel_id);
if (_user && channel) {
this.eventStartSpeaking(_user, channel);
this.eventVoiceJoin(_user, channel);
} else {
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;
};
Server.prototype.eventStartSpeaking = function eventStartSpeaking(user, channel) {
channel = this.channels.get("id", channel.id);
if (channel && channel.type === "voice") {
// good
Server.prototype.eventVoiceJoin = function eventVoiceJoin(user, channel) {
// removes from other speaking channels first
this.eventVoiceLeave(user);
// removes from other speaking channels first
this.eventStopSpeaking(user);
channel.members.add(user);
user.voiceChannel = channel;
return true;
} else {
// bad
return false;
}
channel.members.add(user);
user.voiceChannel = channel;
};
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]();;) {
var _ref3;

View File

@@ -37,6 +37,7 @@ var User = (function (_Equality) {
channel: null
};
this.voiceChannel = null;
this.voiceState = {};
}
User.prototype.mention = function mention() {