add PermissionOverwrites class in preparation for permission evaluation

This commit is contained in:
hydrabolt
2016-04-18 17:23:37 +01:00
parent c36cc3b551
commit 7f4751e7c4
4 changed files with 35 additions and 6 deletions

View File

@@ -1,10 +1,14 @@
'use strict';
class Channel {
constructor(client, data) {
constructor(client, data, guild) {
this.client = client;
this.typingMap = {};
this.typingTimeouts = [];
if (guild) {
this.guild = guild;
}
if (data) {
this.setup(data);
}

View File

@@ -0,0 +1,19 @@
'use strict';
class PermissionOverwrites {
constructor(serverChannel, data) {
this.channel = serverChannel;
if (data) {
this.setup(data);
}
}
setup(data) {
this.type = data.type;
this.id = data.id;
this.denyData = data.deny;
this.allowData = data.allow;
}
}
module.exports = PermissionOverwrites;

View File

@@ -1,11 +1,11 @@
'use strict';
const Channel = require('./Channel');
const PermissionOverwrites = require('./PermissionOverwrites');
class ServerChannel extends Channel{
constructor(guild, data) {
super(guild.client, data);
this.guild = guild;
super(guild.client, data, guild);
}
setup(data) {
@@ -13,9 +13,15 @@ class ServerChannel extends Channel{
this.type = data.type;
this.topic = data.topic;
this.position = data.position;
this.permissionOverwrites = data.permission_overwrites;
this.name = data.name;
this.lastMessageID = data.last_message_id;
if (data.permission_overwrites) {
this.permissionOverwrites = [];
for (let overwrite of data.permission_overwrites) {
this.permissionOverwrites.push(new PermissionOverwrites(this, overwrite));
}
}
}
toString() {

View File

@@ -57,12 +57,12 @@ client.on('voiceStateUpdate', (oldMember, newMember) => {
console.log('voiceState', oldMember.user.username, oldMember.voiceChannel + '', newMember.voiceChannel + '');
});
client.on('typingStart', (channel, user) => {
client.on('typingStart.', (channel, user) => {
if (user.username === 'hydrabolt')
console.log(user.username, 'started typing in', channel.name);
});
client.on('typingStop', (channel, user, data) => {
client.on('typingStop.', (channel, user, data) => {
if (user.username === 'hydrabolt')
console.log(user.username, 'stopped typing in', channel.name, 'after', data.elapsedTime + 'ms');
});