voice state fixes

This commit is contained in:
Amish Shah
2018-08-10 15:15:52 +01:00
parent df54d11dce
commit fe8ece0192
5 changed files with 12 additions and 10 deletions

View File

@@ -10,16 +10,15 @@ class VoiceStateUpdateHandler extends AbstractHandler {
const guild = client.guilds.get(data.guild_id);
if (guild) {
// Update the state
const oldState = guild.voiceStates.get(data.user_id);
if (oldState) oldState._patch(data);
else guild.voiceStates.add(data);
let oldState = guild.voiceStates.get(data.user_id);
if (oldState) oldState = oldState._clone();
const newState = guild.voiceStates.add(data);
const member = guild.members.get(data.user_id);
if (member) {
if (member.user.id === client.user.id && data.channel_id) {
client.emit('self.voiceStateUpdate', data);
}
client.emit(Events.VOICE_STATE_UPDATE, oldState, member.voiceState);
client.emit(Events.VOICE_STATE_UPDATE, oldState, newState);
}
}
}
@@ -28,7 +27,7 @@ class VoiceStateUpdateHandler extends AbstractHandler {
/**
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
* @event Client#voiceStateUpdate
* @param {VoiceState} oldState The voice state before the update
* @param {?VoiceState} oldState The voice state before the update
* @param {VoiceState} newState The voice state after the update
*/

View File

@@ -9,7 +9,7 @@ class VoiceStateStore extends DataStore {
add(data, cache = true) {
const existing = this.get(data.user_id);
if (existing) return existing;
if (existing) return existing._patch(data);
const entry = new VoiceState(this.guild, data);
if (cache) this.set(data.user_id, entry);

View File

@@ -233,9 +233,7 @@ class Guild extends Base {
if (!this.voiceStates) this.voiceStates = new VoiceStateStore(this);
if (data.voice_states) {
for (const voiceState of data.voice_states) {
const existing = this.voiceStates.get(voiceState.user_id);
if (existing) existing._patch(voiceState);
else this.voiceStates.add(voiceState);
this.voiceStates.add(voiceState);
}
}

View File

@@ -50,6 +50,7 @@ class VoiceState extends Base {
* @type {Snowflake}
*/
this.channelID = data.channel_id;
return this;
}
/**

View File

@@ -29,6 +29,10 @@ var count = 0;
process.on('unhandledRejection', console.log);
client.on('voiceStateUpdate', (a, b) => {
console.log(a ? a.channelID : null, b ? b.channelID : null, b.member.user.username);
});
client.on('message', m => {
if (!m.guild) return;
if (m.author.id !== '66564597481480192') return;