<commit_before>/* global uuid */

function reslackPlan(desc) {
  var definedGroupsByChannelName = new Map();
  var skippedChannels = new Set();
  var definedChannels = Object.keys(desc.channelgroups);

  var slackDump;
  function loadSlackArchive(dump) {
    slackDump = dump;
  }

  function arrayed(v) {
    return Array.isArray(v) ? v : [v];
  }

  for (var i = 0; i < definedChannels.length; i++) {
    var channelName = definedChannels[i];
    var groupList = desc.channelgroups[channelName];
    if (groupList == 'skip') {
      skippedChannels.add(channelName);
    } else if (Array.isArray(groupList)) {
      var groupTags = new Map();
      for (var j = 0; j < groupList.length; j++) {
        var groupDesc = groupList[j];
        if (typeof groupDesc == 'string') {
          groupTags.set(groupDesc, [channelName]);
        } else if (groupDesc.group && groupDesc.tags) {
          groupTags.set(groupDesc.group, arrayed(groupDesc.tags));
        }
      }
      definedGroupsByChannelName.set(channelName, groupTags);
    } else {
      console.warn(channelName + ' is defined as ' + groupList + '? IDK');
    }
  }

  var entities = {
    lt: '<',
    gt: '>',
    amp: '&'
  };

  // Exposed externally for when instantiating a new group version of a message
  function slackMessageToDingroll(body) {
    return body.replace(/<([^>]+)>/g, function(match, inside) {
      if (inside.slice(0, 1) == '#') {
        return '#' + slackDump.channelsById.get(inside.slice(1)).name;
      } else if (inside.slice(0,1) == '@') {
        if (inside.indexOf('|') > -1) {
          inside = inside.slice(1, inside.indexOf('|'));
        } else {
          inside = inside.slice(1);
        }
        return '@' + slackDump.usersById.get(inside).name;
      } else return inside; // slack angle-wraps links etc
    }).replace(/\&([^;]+);/g, function(match, entname) {
      return entities[entname] || match;
    });
  }

  function tagsForGroup(channelName, groupName) {
    var groups = definedGroupsByChannelName.get(channelName);
    return groups && groups.get(groupName) || [channelName];
  }

  function priorityGroups(channel) {<commit_msg>Better angle-bracket unescapement<commit_after>/* global uuid */

function reslackPlan(desc) {
  var definedGroupsByChannelName = new Map();
  var skippedChannels = new Set();
  var definedChannels = Object.keys(desc.channelgroups);

  var slackDump;
  function loadSlackArchive(dump) {
    slackDump = dump;
  }

  function arrayed(v) {
    return Array.isArray(v) ? v : [v];
  }

  for (var i = 0; i < definedChannels.length; i++) {
    var channelName = definedChannels[i];
    var groupList = desc.channelgroups[channelName];
    if (groupList == 'skip') {
      skippedChannels.add(channelName);
    } else if (Array.isArray(groupList)) {
      var groupTags = new Map();
      for (var j = 0; j < groupList.length; j++) {
        var groupDesc = groupList[j];
        if (typeof groupDesc == 'string') {
          groupTags.set(groupDesc, [channelName]);
        } else if (groupDesc.group && groupDesc.tags) {
          groupTags.set(groupDesc.group, arrayed(groupDesc.tags));
        }
      }
      definedGroupsByChannelName.set(channelName, groupTags);
    } else {
      console.warn(channelName + ' is defined as ' + groupList + '? IDK');
    }
  }

  var entities = {
    lt: '<',
    gt: '>',
    amp: '&'
  };

  // Exposed externally for when instantiating a new group version of a message
  function slackMessageToDingroll(body) {
    return body.replace(/<([^>]+)>/g, function(match, inside) {

      // if it's a channel reference
      if (/^#/.test(inside)) {
        // use the channel name as a hashtag
        return '#' + slackDump.channelsById.get(inside.slice(1)).name;

      // if it's a user reference
      } else if (/^@/.test(inside)) {
        // if it's a reference with the name saved
        if (inside.indexOf('|') > -1) {
          // discard that saved name and leading @
          inside = inside.slice(1, inside.indexOf('|'));
        // otherwise
        } else {
          // just discard the leading @
          inside = inside.slice(1);
        }
        return '@' + slackDump.usersById.get(inside).name;

      // if it's a hyperlink
      } else if (/^https?:\/\//.test(inside)) {
        // if it's an inferred hyperlink
        if (inside.indexOf('|') > -1) {
          // use the original, non-inferred-link text
          return inside.slice(inside.indexOf('|')+1);
        // if it's a plain link
        } else {
          // just use the whole link
          return inside;
        }
      } else return match; // let me see what this case is
    }).replace(/\&([^;]+);/g, function(match, entname) {
      return entities[entname] || match;
    });
  }

  function tagsForGroup(channelName, groupName) {
    var groups = definedGroupsByChannelName.get(channelName);
    return groups && groups.get(groupName) || [channelName];
  }

  function priorityGroups(channel) {
{'fraction_non_alphanumeric': 0.14730707395498394, 'fraction_numerical': 0.003617363344051447, 'mean_word_length': 2.557541100786276, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '1633029', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1538, 'n_words': 375}