Added VoiceStateUpdate handler and DataStore for VoiceChannels. Also added toString methods to Guilds, DMChannels, ServerChannels and Users.

This commit is contained in:
hydrabolt
2016-04-17 19:12:29 +01:00
parent 685d7b622c
commit d1d13f5c85
11 changed files with 111 additions and 2 deletions

View File

@@ -12,6 +12,10 @@ class DMChannel extends Channel{
this.recipient = this.client.store.add('users', new User(this.client, data.recipient));
this.lastMessageID = data.last_message_id;
}
toString() {
return this.recipient.toString();
}
}
module.exports = DMChannel;

View File

@@ -56,6 +56,10 @@ class Guild {
}
}
toString() {
return this.name;
}
setup(data) {
this.id = data.id;
this.available = !data.unavailable;
@@ -106,6 +110,20 @@ class Guild {
}
}
}
if (data.voice_states) {
for (let voiceState of data.voice_states) {
let member = this.store.get('members', voiceState.user_id);
if (member) {
member.serverMute = voiceState.mute;
member.serverDeaf = voiceState.deaf;
member.selfMute = voiceState.self_mute;
member.selfDeaf = voiceState.self_deaf;
member.voiceSessionID = voiceState.session_id;
member.voiceChannelID = voiceState.channel_id;
}
}
}
}
}

View File

@@ -13,8 +13,12 @@ class GuildMember {
setup(data) {
this.user = data.user;
this.deaf = data.deaf;
this.mute = data.mute;
this.serverDeaf = data.deaf;
this.serverMute = data.mute;
this.selfMute = data.self_mute;
this.selfDeaf = data.self_deaf;
this.voiceSessionID = data.session_id;
this.voiceChannelID = data.channel_id;
this.joinDate = new Date(data.joined_at);
this._roles = data.roles;
}
@@ -31,6 +35,18 @@ class GuildMember {
return list;
}
get mute() {
return this.selfMute || this.serverMute;
}
get deaf() {
return this.selfDeaf || this.serverDeaf;
}
get voiceChannel() {
return this.guild.store.get('channels', this.voiceChannelID);
}
get id() {
return this.user.id;
}

View File

@@ -17,6 +17,10 @@ class ServerChannel extends Channel{
this.name = data.name;
this.lastMessageID = data.last_message_id;
}
toString() {
return this.name;
}
}
module.exports = ServerChannel;

View File

@@ -17,6 +17,10 @@ class User {
this.status = data.status || 'offline';
this.game = data.game;
}
toString() {
return `<@${this.id}>`;
}
}
module.exports = User;

View File

@@ -1,10 +1,12 @@
'use strict';
const ServerChannel = require('./ServerChannel');
const VoiceChannelDataStore = require('./datastore/VoiceChannelDataStore');
class VoiceChannel extends ServerChannel {
constructor(guild, data) {
super(guild, data);
this.store = new VoiceChannelDataStore();
}
setup(data) {

View File

@@ -0,0 +1,12 @@
'use strict';
const AbstractDataStore = require('./AbstractDataStore');
class VoiceChannelDataStore extends AbstractDataStore{
constructor() {
super();
this.register('members');
}
}
module.exports = VoiceChannelDataStore;