<commit_before>'use strict';

var slack = require('./slack.js');
var clc = require('cli-color');
var moment = require('moment-timezone');

// Entry point for DAG node
module.exports = function(got) {
  const inData = got['in'];
  const lookupData = got['lookup'];
  var results = [];
  var botToken;
  let settings = null;
  let reports = [];
  let outgoingMessage = null;
  var initialMsg = "Hello, I\'m <@scrumbot>, please send me stand-up reports on my private channel when I ask for them. \n You can also ask me for `status` and `help`.";
  // Extract the Slack API token
  console.log("InData ", inData);
  console.log("LOOKUP ", got['lookup'])



  inData.data.forEach(function(d) {
    console.log('IN ITEM', d);
    reports.push({
      name: "reports",
      key: d.key,
      value: d.value.toString()
    });
  });

  lookupData.forEach(function(d) {
    //Get settings and slack token.
    console.log('LK ITEM', d.data);
    if (d.data.key == 'settings') {
      settings = JSON.parse(d.data.value);
    }

    if (d.data.key == 'slack/bot_access_token') {
      botToken = d.data.value.toString();
      console.log("BT ", botToken)
    }
  });
  // Initialize settings if not found.
  if (settings) {
    console.log(clc.magenta("SETTINGS"), settings);
  } else {
    //Setting defaults
    console.log(clc.red("INIT SETTINGS"))
    settings = {
      tz: "US/Eastern",
      startOfDay: "9",
      meetingCall: "11"
    };
    results.push({
      name: "settings",
      key: "settings",
      value: settings
    });
    results.push({
      name: "settingsExport",
      key: "settings",
      value: settings
    });
  }

  var now = moment.tz(settings.tz);
  console.log("LOCAL TIME ", now.format('MMMM Do YYYY, h:mm:ss a zz'));
  //Is it the weekend?
  if (now.day() > 0 && now.day() < 6) {
    console.log("Its a workday")
    //Is it start of Day?
    if (now.hour() == parseInt(settings.startOfDay)) {
      // Do we have anyone on the team?
      if (reports.length > 0) {
        console.log("Resetting Reports");
        //Reset reports
        // Iterate over all report records and reset them.
        for (var d of reports) {
          console.log('RESETTING: ', d);
          results.push({
            name: "reports",<commit_msg>FIX: Handle null slack token<commit_after>'use strict';

var slack = require('./slack.js');
var clc = require('cli-color');
var moment = require('moment-timezone');

// Entry point for DAG node
module.exports = function(got) {
  const inData = got['in'];
  const lookupData = got['lookup'];
  var results = [];
  var botToken;
  let settings = null;
  let reports = [];
  let outgoingMessage = null;
  var initialMsg = "Hello, I\'m <@scrumbot>, please send me stand-up reports on my private channel when I ask for them. \n You can also ask me for `status` and `help`.";
  // Extract the Slack API token
  console.log("InData ", inData);
  console.log("LOOKUP ", got['lookup'])



  inData.data.forEach(function(d) {
    console.log('IN ITEM', d);
    reports.push({
      name: "reports",
      key: d.key,
      value: d.value.toString()
    });
  });

  lookupData.forEach(function(d) {
    //Get settings and slack token.
    console.log('LK ITEM', d.data);
    if (d.data.key == 'settings' && d.data.value) {
      settings = JSON.parse(d.data.value);
    }

    if (d.data.key == 'slack/bot_access_token' && d.data.value) {
      botToken = d.data.value.toString();
      console.log("BT ", botToken)
    }
  });
  // Initialize settings if not found.
  if (settings) {
    console.log(clc.magenta("SETTINGS"), settings);
  } else {
    //Setting defaults
    console.log(clc.red("INIT SETTINGS"))
    settings = {
      tz: "US/Eastern",
      startOfDay: "9",
      meetingCall: "11"
    };
    results.push({
      name: "settings",
      key: "settings",
      value: settings
    });
    results.push({
      name: "settingsExport",
      key: "settings",
      value: "settings"
    });
  }

  var now = moment.tz(settings.tz);
  console.log("LOCAL TIME ", now.format('MMMM Do YYYY, h:mm:ss a zz'));
  //Is it the weekend?
  if (now.day() > 0 && now.day() < 6) {
    console.log("Its a workday")
    //Is it start of Day?
    if (now.hour() == parseInt(settings.startOfDay)) {
      // Do we have anyone on the team?
      if (reports.length > 0) {
        console.log("Resetting Reports");
        //Reset reports
        // Iterate over all report records and reset them.
        for (var d of reports) {
          console.log('RESETTING: ', d);
          results.push({
            name: "reports",
{'fraction_non_alphanumeric': 0.16021857923497268, 'fraction_numerical': 0.002622950819672131, 'mean_word_length': 2.5335907335907337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5725188', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1489, 'n_words': 413}