<commit_before>/*
 * slack-bot
 * https://github.com/usubram/slack-bot
 *
 * Copyright (c) 2017 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

const SlackBot = require('./lib/index');
const fs = require('fs');
const sampleTemplate = fs.readFileSync('./sample.hbs', 'utf8');
const moment = require('moment');

const args = process.argv.slice(2);

const config = {
  bots: [{
    botCommand: {
      log: {
        commandType: 'DATA',
        allowedParam: ['hello'], // allow any argument to a command
        helpText: '    → this is log command \\n',
        template: sampleTemplate,
        data: function (input, options, callback) {
          // input.command - for command name.
          // input.params - for params in array.
          // options.user.profile.email - email in slack.
          // options.hookUrl - custom webhook url.
          // options.channel - channel from which the command was fired.
          callback({
            param: input.params,
          });
        },
      },
      trend: {
        commandType: 'DATA',
        responseType: {
          type: 'png',
          ylabel: 'errors',
          timeUnit: 'm',
          title: 'Log data',
          logscale: false,
          style: 'lines',
          exec: {
            encoding: 'utf16',
          },
        },
        allowedParam: [1, 2],
        defaultParamValue: 1,
        helpText: '    → this is trend command \\n',
        data: function (input, options, callback) {
          const dataArr = [ // Sample data
            [100, 120, 130, 110, 123, 90],
            [1, 120, 130, 110, 90, 85],
            [1, 120, 130, 1010, 140, 145],
            [100, 120, 130, 250, 140, 145],
            [100, 120, 130, 300, 140, 145],
            [100, 400, 130, 300, 140, 145],
            [100, 90, 130, 300, 140, 145],
            [100, 120, 130, 1010, 150, 90],
          ];
          const rand = dataArr[Math.floor(Math.random() * dataArr.length)];
          callback(rand);
        },
      },
      error: {
        commandType: 'RECURSIVE',
        lowerLimit: 0,
        upperLimit: 100,
        defaultParamValue: 1,
        helpText: '    → this is error command \\n',
        template: sampleTemplate,
        data: function (input, options, callback) {
          callback({
            param: input.params,
          });
        },
      },
      alert: {
        commandType: 'ALERT',
        timeInterval: 1,
        helpText: '    → this a alert command \\n',
        algo: 'CUMULATIVE_DIFFERENCE',
        data: function (input, options, callback) {
          const dataArr = [ // Sample data
            {
              time: moment().unix() - 1000,
              value: 400,
            },
            {
              time: moment().unix(),
              value: 120,
            },
          ];
          callback(dataArr);
        },
      },
      file: {
        commandType: 'DATA',
        allowedParam: ['*'],
        helpText: '    → this a alert command \\n',
        data: function (input, options, callback) {
          callback({
            responseType: {
              type: 'xml',
              name: 'hello',
            },
            response: '<xml></xml>',
          });
        },
      },
    },
    schedule: true,
    blockDirectMessage: false,
    webHook: true,
    slackApi: {
      user: {
        exclude: true,
        presence: false,
      },
      channel: {
        exclude: false,
      },
    },
    mock: {
      self: {
        name: 'testbot1',
        id: 'U1234567',
      },
    },
    botToken: args[0],
  }],
  // proxy: {
  //   url: 'http://proxy.socketproxy.com:8080/'
  // },
  logger: console, // you could pass a winston logger.
  server: {
    port: 9090,
    webHook: true,
  },
};

// const slackBot = new SlackBot(config, { isMock: true });
const slackBot = new SlackBot(config);
slackBot.start().then((botEvt) => {
  botEvt[0].on('message', (message) => {
    // do something with the message.
  });

  botEvt[0].on('connect', () => {
    // do something on bot connection.
  });

  botEvt[0].on('restart', () => {
    // do something on bot restart.
  });

  botEvt[0].on('close', () => {
    // do something on bot connection close.
  });
});
<commit_msg>config for slack api<commit_after>/*
 * slack-bot
 * https://github.com/usubram/slack-bot
 *
 * Copyright (c) 2017 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

const SlackBot = require('./lib/index');
const fs = require('fs');
const sampleTemplate = fs.readFileSync('./sample.hbs', 'utf8');
const moment = require('moment');

const args = process.argv.slice(2);

const config = {
  bots: [{
    botCommand: {
      log: {
        commandType: 'DATA',
        allowedParam: ['hello'], // allow any argument to a command
        helpText: '    → this is log command \\n',
        template: sampleTemplate,
        data: function (input, options, callback) {
          // input.command - for command name.
          // input.params - for params in array.
          // options.user.profile.email - email in slack.
          // options.hookUrl - custom webhook url.
          // options.channel - channel from which the command was fired.
          callback({
            param: input.params,
          });
        },
      },
      trend: {
        commandType: 'DATA',
        responseType: {
          type: 'png',
          ylabel: 'errors',
          timeUnit: 'm',
          title: 'Log data',
          logscale: false,
          style: 'lines',
          exec: {
            encoding: 'utf16',
          },
        },
        allowedParam: [1, 2],
        defaultParamValue: 1,
        helpText: '    → this is trend command \\n',
        data: function (input, options, callback) {
          const dataArr = [ // Sample data
            [100, 120, 130, 110, 123, 90],
            [1, 120, 130, 110, 90, 85],
            [1, 120, 130, 1010, 140, 145],
            [100, 120, 130, 250, 140, 145],
            [100, 120, 130, 300, 140, 145],
            [100, 400, 130, 300, 140, 145],
            [100, 90, 130, 300, 140, 145],
            [100, 120, 130, 1010, 150, 90],
          ];
          const rand = dataArr[Math.floor(Math.random() * dataArr.length)];
          callback(rand);
        },
      },
      error: {
        commandType: 'RECURSIVE',
        lowerLimit: 0,
        upperLimit: 100,
        defaultParamValue: 1,
        helpText: '    → this is error command \\n',
        template: sampleTemplate,
        data: function (input, options, callback) {
          callback({
            param: input.params,
          });
        },
      },
      alert: {
        commandType: 'ALERT',
        timeInterval: 1,
        helpText: '    → this a alert command \\n',
        algo: 'CUMULATIVE_DIFFERENCE',
        data: function (input, options, callback) {
          const dataArr = [ // Sample data
            {
              time: moment().unix() - 1000,
              value: 400,
            },
            {
              time: moment().unix(),
              value: 120,
            },
          ];
          callback(dataArr);
        },
      },
      file: {
        commandType: 'DATA',
        allowedParam: ['*'],
        helpText: '    → this a alert command \\n',
        data: function (input, options, callback) {
          callback({
            responseType: {
              type: 'xml',
              name: 'hello',
            },
            response: '<xml></xml>',
          });
        },
      },
    },
    schedule: true,
    blockDirectMessage: false,
    webHook: true,
    slackApi: {
      user: {
        exclude: false,
        presence: false,
      },
      channel: {
        exclude: false,
      },
    },
    mock: {
      self: {
        name: 'testbot1',
        id: 'U1234567',
      },
    },
    botToken: args[0],
  }],
  // proxy: {
  //   url: 'http://proxy.socketproxy.com:8080/'
  // },
  logger: console, // you could pass a winston logger.
  server: {
    port: 9090,
    webHook: true,
  },
};

// const slackBot = new SlackBot(config, { isMock: true });
const slackBot = new SlackBot(config);
slackBot.start().then((botEvt) => {
  botEvt[0].on('message', (message) => {
    // do something with the message.
  });

  botEvt[0].on('connect', () => {
    // do something on bot connection.
  });

  botEvt[0].on('restart', () => {
    // do something on bot restart.
  });

  botEvt[0].on('close', () => {
    // do something on bot connection close.
  });
});

{'fraction_non_alphanumeric': 0.1492220650636492, 'fraction_numerical': 0.043611504007543614, 'mean_word_length': 1.5588057901085646, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '1711306', 'n_tokens_mistral': 2849, 'n_tokens_neox': 2517, 'n_words': 683}