{"size": 1389, "ext": "js", "max_stars_repo_path": "src/troubleshooting/test.js", "max_stars_repo_name": "ninjacoder88/lost-in-translation-twitch", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/troubleshooting/test.js", "max_issues_repo_name": "ninjacoder88/lost-in-translation-twitch", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/troubleshooting/test.js", "max_forks_repo_name": "ninjacoder88/lost-in-translation-twitch", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.3023255814, "max_line_length": 78, "alphanum_fraction": 0.6285097192}
const { MongoClientProxy } = require("../app/mongoClientProxy");
const { Logger } = require("../app/logger");
const { CredentialLoader } = require("../app/credentialLoader");
const { DatabaseProxy } = require("../app/databaseProxy");
const { TwitchApiProxy } = require("../app/twitchApiProxy");
const databaseProxy = require("../app/databaseProxy");

const l = new Logger("log.log");
const cl = new CredentialLoader("./app/secrets/litbot-credentials.json", l);

var c = cl.loadCredentials();

const mcp = new MongoClientProxy(c.mongoConnectionString, l);
const dp = new DatabaseProxy(mcp);
const tap = new TwitchApiProxy(c.twitchApiToken, c.twitchClientId, l);


let allChannels = undefined;
dp.getChannelsAsync()
    .then(channels => {
        console.log(channels);
        allChannels = channels;
        const channelArray = channels.map(c => c.channelName.replace("#",""));

        return tap.getLiveStreamsAsync(channelArray);
        
    }).then(liveChannels => {
        console.log(liveChannels);

        allChannels.forEach(c => {
            console.log(c);
            if(liveChannels.indexOf(c.channelName) !== -1){
                dp.updateChannelStatusAsync(c.channelName, "live");
            } else {
                dp.updateChannelStatusAsync(c.channelName, "off air");
            }
        });

        
    }).catch(error => {
        console.log(error);
    });
