<commit_before>'use strict';

require('dotenv').load();
const _ = require('lodash');
const Slack = require('slack-client');
const responses = require('./responses.js');

const slackToken = process.env.SLACK_TOKEN;
const slackChannel = process.env.SLACK_CHANNEL;
const autoReconnect = true;
const autoMark = true;

let slack = new Slack(slackToken, autoReconnect, autoMark);

slack.on('open', function() {
  console.log('Connected to ' + slack.team.name + ' as ' + slack.self.name);
});

slack.on('message', function(message) {
  console.log('Received: ' + message);

  let channel = slack.getChannelGroupOrDMByID(message.channel);
  if (!channel) return;
  let user = slack.getUserByID(message.user);
  if (!user) return;

  // Only respond in the specified channel or to individual users
  if (!channel.is_channel || channel.name === slackChannel) {
    if (message.text.match(/praise koffee/ig)) {
      let res = '༼ つ ◕_◕ ༽つ ☕️';
      console.log('Response: ' + res);
      channel.send(res);
    } else if (message.text.match(/c/ig)) {
      let res = _.sample(responses)('@' + user.name);
      console.log('Response: ' + res);
      channel.send(res);
    }
  }
});

slack.on('error', function(err) {
  console.error('Error', err);
});
<commit_msg>Refactor sending slack response to its own function<commit_after>'use strict';

require('dotenv').load();
const _ = require('lodash');
const Slack = require('slack-client');
const responses = require('./responses.js');

const slackToken = process.env.SLACK_TOKEN;
const slackChannel = process.env.SLACK_CHANNEL;
const autoReconnect = true;
const autoMark = true;

let slack = new Slack(slackToken, autoReconnect, autoMark);

function sendResponse(channel, message) {
  console.log('Response: ' + message);
  channel.send(message);
}

slack.on('open', function() {
  console.log('Connected to ' + slack.team.name + ' as ' + slack.self.name);
});

slack.on('message', function(message) {
  console.log('Received: ' + message);

  let channel = slack.getChannelGroupOrDMByID(message.channel);
  if (!channel) return;
  let user = slack.getUserByID(message.user);
  if (!user) return;

  // Only respond in the specified channel or to individual users
  if (!channel.is_channel || channel.name === slackChannel) {
    if (message.text.match(/praise koffee/ig)) {
      sendResponse(channel, '༼ つ ◕_◕ ༽つ ☕️');
    } else if (message.text.match(/c/ig)) {
      sendResponse(channel, _.sample(responses)('@' + user.name));
    }
  }
});

slack.on('error', function(err) {
  console.error('Error', err);
});

{'fraction_non_alphanumeric': 0.16868884540117418, 'fraction_numerical': 0.0, 'mean_word_length': 4.270103092783505, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3530237', 'n_tokens_mistral': 879, 'n_tokens_neox': 853, 'n_words': 191}