<commit_before>'use strict';

const WebClient = require('@slack/client').WebClient;
const db = require('serverless-slack/src/dynamo');

const teamId = process.env.TEAM_ID;

const getChannelName = (bot) => {
  return getChannelsWithToken(bot.auth.bot.bot_access_token)
    .then((channels) => {
      const matches = channels.filter(c => c.id === bot.payload.event.channel);
      if (!matches || matches.length === 0) {
        throw new Error('no channel found');
      }
      return matches[0].name;
    });
};

const getChannelsWithToken = (token) => {
  const web = new WebClient(token);
  return new Promise((resolve, reject) => {
    web.channels.list((err, info) => {
      if (err) {
        console.log('Error getting channel list:', err);
        return reject(err);
      }
      return resolve(info.channels);
    });
  });
};

const getChannels = () => {
  return db.get(teamId).then(record => {
    return getChannelsWithToken(record.bot.bot_access_token);
  });
};

module.exports = {
  getChannelName: getChannelName,
  getChannelsWithToken: getChannelsWithToken,
  getChannels: getChannels
};
<commit_msg>Prevent trying to fetch archived channels<commit_after>'use strict';

const WebClient = require('@slack/client').WebClient;
const db = require('serverless-slack/src/dynamo');

const teamId = process.env.TEAM_ID;

const getChannelName = (bot) => {
  return getChannelsWithToken(bot.auth.bot.bot_access_token)
    .then((channels) => {
      const matches = channels.filter(c => c.id === bot.payload.event.channel);
      if (!matches || matches.length === 0) {
        throw new Error('no channel found');
      }
      return matches[0].name;
    });
};

const getChannelsWithToken = (token) => {
  const web = new WebClient(token);
  return new Promise((resolve, reject) => {
    web.channels.list(true, (err, info) => {
      if (err) {
        console.log('Error getting channel list:', err);
        return reject(err);
      }
      return resolve(info.channels);
    });
  });
};

const getChannels = () => {
  return db.get(teamId).then(record => {
    return getChannelsWithToken(record.bot.bot_access_token);
  });
};

module.exports = {
  getChannelName: getChannelName,
  getChannelsWithToken: getChannelsWithToken,
  getChannels: getChannels
};

{'fraction_non_alphanumeric': 0.1513157894736842, 'fraction_numerical': 0.0017543859649122807, 'mean_word_length': 3.5347912524850895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '71189', 'n_tokens_mistral': 727, 'n_tokens_neox': 724, 'n_words': 146}