You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var fs = require('fs');
var path = require('path');
var Yaml = require('yaml');
var Channel = require('./Channel');
var BroadcastChannel = require('./BroadcastChannel');
class ChannelManager {
constructor(app, configPath){
this.app = app;
this.configPath = configPath;
this.channels = {};
this.initChannels();
}
initChannels(){
let files = fs.readdirSync(this.configPath);
files.forEach((file) => {
if(!file.match(/\.yml$/)){
return;
}
let name = file.replace(/\.yml$/, '');
let content = fs.readFileSync(this.configPath + '/' + file, {encoding: 'utf-8'});
let config = Yaml.parse(content);
let channel = new Channel(this.app, config);
this.channels[name] = channel;
console.log('已加载Channel配置: ' + name + '对应channel: ' + config.channel);
});
this.channels['broadcast'] = new BroadcastChannel(this.app);
}
}
module.exports = ChannelManager;