<commit_before>const monzo = require('../monzo');
const _ = require('underscore');
const utils = require('../utils');

module.exports = function () {
  const monzoUser = monzo.monzoUser(utils.getAndValidiateMonzoAuthToken(this));
  if (!monzoUser) return;

  monzoUser.getAccounts().then((accounts) => {
    monzoUser.getTargets(accounts[0].id).then((targets) => {
      if (!targets.targets.length)
        return this.emit(':tell', `You don't have any targets! Set some up in the Monzo App!`);

      // TODO maybe give special treatment to the "total" target
      const targetBuckets = _.groupBy(targets.targets, 'status');
      if (targetBuckets['OKAY'] && targetBuckets['OKAY'].length === targets.targets.length) {
        this.emit(':tell', `You're currently within all your targets for this ${targets.interval_type}`);
      } else {
        const responseParts = [];
        if (targetBuckets['EXCEEDED'] && targetBuckets['EXCEEDED'].length)
          responseParts.push(`You've exceeded your target for the following categories: ${_.pluck(targetBuckets['EXCEEDED'], 'name').join(' ').replace('_', ' ')}.`);

        // TODO what's the name of the off-target state?

        if (targetBuckets['OKAY'] && targetBuckets['OKAY'].length)
          responseParts.push(`You're still on target for the following categories: ${_.pluck(targetBuckets['OKAY'], 'name').join(' ').replace('_', ' ')}`);

        this.emit(':tell', responseParts.join(' '));
      }
    });
  }).catch(utils.andleMonzoError.bind(this));
};<commit_msg>Added warning category to targets feature<commit_after>const monzo = require('../monzo');
const _ = require('underscore');
const utils = require('../utils');

module.exports = function () {
  const monzoUser = monzo.monzoUser(utils.getAndValidiateMonzoAuthToken(this));
  if (!monzoUser) return;

  monzoUser.getAccounts().then((accounts) => {
    monzoUser.getTargets(accounts[0].id).then((targets) => {
      if (!targets.targets.length)
        return this.emit(':tell', `You don't have any targets, Set some up in the Monzo App!`);

      // TODO maybe give special treatment to the "total" target
      const targetBuckets = _.groupBy(targets.targets, 'status');
      if (targetBuckets['OKAY'] && targetBuckets['OKAY'].length === targets.targets.length) {
        this.emit(':tell', `You're currently within all your targets for this ${targets.interval_type}`);
      } else {
        const responseParts = [];
        if (targetBuckets['EXCEEDED'] && targetBuckets['EXCEEDED'].length)
          responseParts.push(`You've exceeded your target for the following categories: ${_.pluck(targetBuckets['EXCEEDED'], 'name').join(' ').replace('_', ' ')}.`);

        if (targetBuckets['WARNING'] && targetBuckets['WARNING'].length)
          responseParts.push(`You're close to exceeding your target for these categories: ${_.pluck(targetBuckets['WARNING'], 'name').join(' ').replace('_', ' ')}.`);

        if (targetBuckets['OKAY'] && targetBuckets['OKAY'].length)
          responseParts.push(`You're still on target for the following categories: ${_.pluck(targetBuckets['OKAY'], 'name').join(' ').replace('_', ' ')}`);

        this.emit(':tell', responseParts.join(' '));
      }
    });
  }).catch(utils.andleMonzoError.bind(this));
};
{'fraction_non_alphanumeric': 0.17639865484561296, 'fraction_numerical': 0.0006114338122898196, 'mean_word_length': 4.003058103975535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6922306', 'n_tokens_mistral': 1022, 'n_tokens_neox': 969, 'n_words': 218}