<commit_before>import calf from '../support/calf';
import getForage from './getForage';
import {now} from '../support/dataObj';
import retryAjax from './retryAjax';
import setForage from './setForage';

function currentGuildId() {
  var _guildId;
  var nodeList = document.body.getElementsByTagName('script');
  Array.prototype.forEach.call(nodeList, function getGuildId(el) {
    var match = el.textContent.match(/\s+guildId: ([0-9]+),/);
    if (match) {_guildId = parseInt(match[1], 10);}
  });
  return _guildId;
}

function getGuild(guildId) {
  return retryAjax({
    dataType: 'json',
    url: 'index.php',
    data: {
      cmd: 'export',
      subcmd: 'guild_members',
      guild_id: guildId
    }
  });
}

function addMembrListToForage(membrList) {
  getForage('fsh_membrList')
    .done(function saveMembrListInForage(data) {
      var oldMemList = data || {};
      setForage('fsh_membrList', $.extend(oldMemList, membrList));
    });
}

function getGuildMembers(guildId) {
  return getGuild(guildId).pipe(function membrListToHash(data) {
    var membrList = {};
    membrList[guildId] = {};
    membrList[guildId].lastUpdate = now;
    data.forEach(function memberToObject(ele) {
      membrList[guildId][ele.username] = ele;
    });
    return membrList;
  });
}

function getMembrListFromForage(guildId, membrList) {
  if (membrList && membrList[guildId] &&
      membrList[guildId].lastUpdate &&
      membrList[guildId].lastUpdate > now - 300000) {
    return membrList;
  }
  return getGuildMembers(guildId).done(addMembrListToForage);<commit_msg>reduce complexity (updated eslint rule 4.14.0)<commit_after>import calf from '../support/calf';
import getForage from './getForage';
import {now} from '../support/dataObj';
import retryAjax from './retryAjax';
import setForage from './setForage';

function currentGuildId() {
  var _guildId;
  var nodeList = document.body.getElementsByTagName('script');
  Array.prototype.forEach.call(nodeList, function getGuildId(el) {
    var match = el.textContent.match(/\s+guildId: ([0-9]+),/);
    if (match) {_guildId = parseInt(match[1], 10);}
  });
  return _guildId;
}

function getGuild(guildId) {
  return retryAjax({
    dataType: 'json',
    url: 'index.php',
    data: {
      cmd: 'export',
      subcmd: 'guild_members',
      guild_id: guildId
    }
  });
}

function addMembrListToForage(membrList) {
  getForage('fsh_membrList')
    .done(function saveMembrListInForage(data) {
      var oldMemList = data || {};
      setForage('fsh_membrList', $.extend(oldMemList, membrList));
    });
}

function getGuildMembers(guildId) {
  return getGuild(guildId).pipe(function membrListToHash(data) {
    var membrList = {};
    membrList[guildId] = {};
    membrList[guildId].lastUpdate = now;
    data.forEach(function memberToObject(ele) {
      membrList[guildId][ele.username] = ele;
    });
    return membrList;
  });
}

var testList = [
  function(guildId, membrList) {return typeof membrList === 'object';},
  function(guildId, membrList) {return typeof membrList[guildId] === 'object';},
  function(guildId, membrList) {
    return typeof membrList[guildId].lastUpdate === 'number';
  },
  function(guildId, membrList) {
    return membrList[guildId].lastUpdate > now - 300000;
  }
];

function getMembrListFromForage(guildId, membrList) {
  if (testList.every(function(e) {return e(guildId, membrList);})) {
    return membrList;
  }
  return getGuildMembers(guildId).done(addMembrListToForage);
{'fraction_non_alphanumeric': 0.14677047289504036, 'fraction_numerical': 0.007497116493656286, 'mean_word_length': 4.185351270553064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3082182', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1218, 'n_words': 222}