properly delegate to sub classes for channels and clients

This commit is contained in:
Josh Burman
2019-03-11 16:55:44 -04:00
parent cdd6179992
commit 74aad4a957
11 changed files with 66 additions and 44 deletions

View File

@ -9,17 +9,15 @@ class ChannelManager {
this.channels.push(channel);
}
createChannel(data) {
var channel = this.channelExists(data.channel_id);
var channel = this.channelExists(data.channel);
if (channel) {
console.log('channel already exists');
}
else {
var Channel = require(`./channels/${data.client_type}s/${data.client}channel`);
var channel = new channelBase_1.default(data.channel_id);
this.channels.push(channel);
channel = this.getChannelType(data);
channel ? this.channels.push(channel) : null;
console.log('added channel to channel manager');
}
console.log(data.channel_id);
}
channelExists(channel_id) {
for (let channel of this.channels) {
@ -39,6 +37,18 @@ class ChannelManager {
console.log(`channel with id ${channel_id} does not exist.`);
}
}
getChannelType(data) {
try {
var Channel = require(`./channels/${data.client_type}s/${data.client}channel`);
console.log(`attempting to create channel of type ${data.client}, channel id: ${data.channel}...`);
return new Channel(data.channel);
}
catch (e) {
console.log(e);
console.log(`creating base channel`);
return new channelBase_1.default(data.channel);
}
}
}
;
exports.default = ChannelManager;