<commit_before>'use strict'

const scripts = require('../scripts')
const google = require('googleapis')
const sheet = google.sheets('v4')
const date = new Date()
let msg
let thisMonthInHalo = []
let nonMatchingEvents = []
let todayInHalo = []

function filterMonthlyHaloEvents(data) {
  return data[1] == scripts.curMonth()
}

function filterDailyHaloEvents(data) {
  for (var i = 0; i < data.length; i++) {
    if (data[i][2] == scripts.curDay()) {
      return data[i]
    }
  }
}

function getMonthlyActivities(spreadsheet) {
  return spreadsheet.filter(filterMonthlyHaloEvents)
}

function getDailyActivities(rows) {
  // We now have an array with activities for the current month.
  let monthlyActivities = getMonthlyActivities(rows)
  return filterDailyHaloEvents(monthlyActivities)
}

function getNonMatchingEvents(list) {
  // Make sure array is empty before adding to it
  nonMatchingEvents = []
  for (var i = 0; i < list.length; i++) {
    let row = list[i]
    if (row[1] | row[2] == "N/A") {
      nonMatchingEvents.push(row)
    }
  }
  return nonMatchingEvents
}

function gatherMessage(rows) {

  let cannon = getDailyActivities(rows)
  let result = []

  // Check if we have matching events for today
  if (cannon !== undefined) {

    for (var i = 0; i < cannon.length; i++) {
      result.push(cannon[i])
    }

    return messageStructure(result)

  }else {

    let nonMatching = getNonMatchingEvents(rows)
    let result = scripts.randomQuote(nonMatching)

    return messageStructure(result)

  }
}

function messageStructure(gather) {
  let messageDetails = []
  let year, month, day, pageSource, infoOrigin, notes

  try {

    if (gather[0] == 'N/A') {
      year = '__Unknown__'
    }else{
      year = gather[0]
    }

    messageDetails.push(year)

    if (gather[1] == 'N/A') {
      month = '__Unknown__'
    }else{
      month = gather[1]
    }

    messageDetails.push(month)

    if (gather[2] == 'N/A') {
      // If date is not present, we know this is a random event
      messageDetails.push('**__RANDOM HALO CANNON__**')
      day = '__Unknown__'
    }else{
      messageDetails.push('**__TODAY IN HALO__**')
      day = gather[2]
    }

    messageDetails.push(day)

    // gather[3] is the text of the gather
    messageDetails.push(gather[3])

    if (gather[4]) {
      pageSource = gather[4]
    }else{
      pageSource = 'No HaloPedia Reference Found'
    }

    messageDetails.push(pageSource)

    if (gather[5]) {
      infoOrigin = gather[5]
    }else{
      infoOrigin = 'Information Origin Not Applicable'
    }

    messageDetails.push(infoOrigin)

    if (gather[6]) {
      notes = gather[6]<commit_msg>change cannon to canon<commit_after>'use strict'

const scripts = require('../scripts')
const google = require('googleapis')
const sheet = google.sheets('v4')
const date = new Date()
let msg
let thisMonthInHalo = []
let nonMatchingEvents = []
let todayInHalo = []

function filterMonthlyHaloEvents(data) {
  return data[1] == scripts.curMonth()
}

function filterDailyHaloEvents(data) {
  for (var i = 0; i < data.length; i++) {
    if (data[i][2] == scripts.curDay()) {
      return data[i]
    }
  }
}

function getMonthlyActivities(spreadsheet) {
  return spreadsheet.filter(filterMonthlyHaloEvents)
}

function getDailyActivities(rows) {
  // We now have an array with activities for the current month.
  let monthlyActivities = getMonthlyActivities(rows)
  return filterDailyHaloEvents(monthlyActivities)
}

function getNonMatchingEvents(list) {
  // Make sure array is empty before adding to it
  nonMatchingEvents = []
  for (var i = 0; i < list.length; i++) {
    let row = list[i]
    if (row[1] | row[2] == "N/A") {
      nonMatchingEvents.push(row)
    }
  }
  return nonMatchingEvents
}

function gatherMessage(rows) {

  let cannon = getDailyActivities(rows)
  let result = []

  // Check if we have matching events for today
  if (cannon !== undefined) {

    for (var i = 0; i < cannon.length; i++) {
      result.push(cannon[i])
    }

    return messageStructure(result)

  }else {

    let nonMatching = getNonMatchingEvents(rows)
    let result = scripts.randomQuote(nonMatching)

    return messageStructure(result)

  }
}

function messageStructure(gather) {
  let messageDetails = []
  let year, month, day, pageSource, infoOrigin, notes

  try {

    if (gather[0] == 'N/A') {
      year = '__Unknown__'
    }else{
      year = gather[0]
    }

    messageDetails.push(year)

    if (gather[1] == 'N/A') {
      month = '__Unknown__'
    }else{
      month = gather[1]
    }

    messageDetails.push(month)

    if (gather[2] == 'N/A') {
      // If date is not present, we know this is a random event
      messageDetails.push('**__RANDOM HALO CANON__**')
      day = '__Unknown__'
    }else{
      messageDetails.push('**__TODAY IN HALO__**')
      day = gather[2]
    }

    messageDetails.push(day)

    // gather[3] is the text of the gather
    messageDetails.push(gather[3])

    if (gather[4]) {
      pageSource = gather[4]
    }else{
      pageSource = 'No HaloPedia Reference Found'
    }

    messageDetails.push(pageSource)

    if (gather[5]) {
      infoOrigin = gather[5]
    }else{
      infoOrigin = 'Information Origin Not Applicable'
    }

    messageDetails.push(infoOrigin)

    if (gather[6]) {
      notes = gather[6]
{'fraction_non_alphanumeric': 0.12551672303645245, 'fraction_numerical': 0.008267568583239383, 'mean_word_length': 3.0571646341463414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3701630', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1748, 'n_words': 444}