Added websocket voice state watching

Now emits voiceJoin(user, voice_channel) or voiceLeave(user, voice_channel) and adds/removes from voice_channel.speaking when a user joins or leaves a voice channel.
This commit is contained in:
Amish Shah
2015-12-26 15:38:53 +00:00
parent 7b2f4e3357
commit 9c0e20947c
9 changed files with 157 additions and 11 deletions

View File

@@ -1417,6 +1417,34 @@ export default class InternalClient {
} else {
client.emit("warn", "user unbanned but user/server not in cache.");
}
break;
case PacketType.VOICE_STATE_UPDATE:
var user = self.users.get("id", data.user_id);
var server = self.servers.get("id", data.guild_id);
if(user && server){
if(data.channel_id){
// speaking
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");
}else{
client.emit("warn", "voice state channel not in cache");
}
}else{
// not speaking
client.emit("voiceLeave", user, server.eventStopSpeaking(user));
}
}else{
client.emit("warn", "voice state update but user or server not in cache");
}
break;
default:
client.emit("unknown", packet);