mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
Added VoiceStateUpdate handler and DataStore for VoiceChannels. Also added toString methods to Guilds, DMChannels, ServerChannels and Users.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -17,6 +17,10 @@ class User {
|
||||
this.status = data.status || 'offline';
|
||||
this.game = data.game;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `<@${this.id}>`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = User;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
12
src/structures/datastore/VoiceChannelDataStore.js
Normal file
12
src/structures/datastore/VoiceChannelDataStore.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const AbstractDataStore = require('./AbstractDataStore');
|
||||
|
||||
class VoiceChannelDataStore extends AbstractDataStore{
|
||||
constructor() {
|
||||
super();
|
||||
this.register('members');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceChannelDataStore;
|
||||
Reference in New Issue
Block a user