'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);
});

slack.login();

@@ -349,24 +349,133 @@
 autoMark);%0A%0A
+function sendResponse(channel, message) %7B%0A  console.log('Response: ' + message);%0A  channel.send(message);%0A%7D%0A%0A
 slack.on('op
@@ -997,96 +997,45 @@
     
-let res = '%E0%BC%BC %E3%81%A4 %E2%97%95_%E2%97%95 %E0%BC%BD%E3%81%A4 %E2%98%95%EF%B8%8F';%0A      console.log('Response: ' + res);%0A      channel.send(res
+sendResponse(channel, '%E0%BC%BC %E3%81%A4 %E2%97%95_%E2%97%95 %E0%BC%BD%E3%81%A4 %E2%98%95%EF%B8%8F'
 );%0A 
@@ -1087,17 +1087,29 @@
     
-let res =
+sendResponse(channel,
  _.s
@@ -1145,71 +1145,8 @@
 ame)
-;%0A      console.log('Response: ' + res);%0A      channel.send(res
 );%0A 

Refactor sending slack response to its own function