<commit_before>/**
 * Description
 * Let hubot execute shell command.
 *
 * Dependencies:
 * send_message: include this module
 *
 * Configuration:
 * CMD_CONFIG: path to configuration file
 * CMD_MSG_COLOR: color
 *
 * hipchat "color" is allowed in "yellow", "red", "green", "purple", "gray", or "random".
 *
 * You need write CMD_CONFIG file in yaml format like this.
 *
 * "TARGET1":
 *   "ACTION1":
 *     "command": "/path/to/cmd1 ACTION1"
 *     "user": ["foo", "bar"]
 *     "message": "/path/to/cmd1 ACTION1 is executed."
 *   "ACTION2":
 *     "command": "/path/to/cmd1 ACTION2"
 *     "user": ["foo"]
 *     "message": "/path/to/cmd1 ACTION2 is executed."
 * "TARGET2":
 *   "ACTION1":
 *     "command": "/path/to/cmd2 ACTION1"
 *     "user": ["foo", "bar"]
 *     "message": "/path/to/cmd2 ACTION1 is executed."
 *
 * You need to execute hubot as adapter for each group chat system.
 * If you use slack, you need to hubot-slack adapter.
 *
 * You need to let hubot user allow to execute command on your system (ex. sudo).
 * Each ACTION has these properties:
 * command: the expression to execute command.
 * user:    the list of user allowed to execute the command.
 * message: the message to let hubot tell when the command executed.
 *
 * Commands:
 * Tell bot to order.
 * @bot cmd TARGET ACTION
 *
 * Author:
 * <NAME>
 */

/* @flow */
import fs            from 'fs';
import yaml          from 'js-yaml';
import child_process from 'child_process';

import SendMessage   from './SendMessage';
import Auth          from './Auth';

const prefix      = '[cmd]';
const debug       = process.env.CMD_DEBUG;
const configFile  = process.env.CMD_CONFIG;
const type        = process.env.HUBOT_IRC_TYPE;
const name        = 'cmd';
const USER        = 'user';
const MESSAGE     = 'message';
const COMMAND     = 'command';

module.exports = (robot) => {
  const sm      = new SendMessage(robot, type);
  const log     = sm.robot;
  const options = {
    color: color
  };

  if (!configFile) {
    log.error(`${name}> no config file.`);
    return;
  }

  const conf = yaml.safeLoad(fs.readFileSync(configFile));

  const execCommand = (msg, cmd) => {
    const room    = `#${msg.message.user.room}`;
    const target  = [ room ];
    const exec    = child_process.exec;
    const message = {};<commit_msg>fix unreadable variable.<commit_after>/**
 * Description
 * Let hubot execute shell command.
 *
 * Dependencies:
 * send_message: include this module
 *
 * Configuration:
 * CMD_CONFIG: path to configuration file
 * CMD_MSG_COLOR: color
 *
 * hipchat "color" is allowed in "yellow", "red", "green", "purple", "gray", or "random".
 *
 * You need write CMD_CONFIG file in yaml format like this.
 *
 * "TARGET1":
 *   "ACTION1":
 *     "command": "/path/to/cmd1 ACTION1"
 *     "user": ["foo", "bar"]
 *     "message": "/path/to/cmd1 ACTION1 is executed."
 *   "ACTION2":
 *     "command": "/path/to/cmd1 ACTION2"
 *     "user": ["foo"]
 *     "message": "/path/to/cmd1 ACTION2 is executed."
 * "TARGET2":
 *   "ACTION1":
 *     "command": "/path/to/cmd2 ACTION1"
 *     "user": ["foo", "bar"]
 *     "message": "/path/to/cmd2 ACTION1 is executed."
 *
 * You need to execute hubot as adapter for each group chat system.
 * If you use slack, you need to hubot-slack adapter.
 *
 * You need to let hubot user allow to execute command on your system (ex. sudo).
 * Each ACTION has these properties:
 * command: the expression to execute command.
 * user:    the list of user allowed to execute the command.
 * message: the message to let hubot tell when the command executed.
 *
 * Commands:
 * Tell bot to order.
 * @bot cmd TARGET ACTION
 *
 * Author:
 * <NAME>
 */

/* @flow */
import fs            from 'fs';
import yaml          from 'js-yaml';
import child_process from 'child_process';

import SendMessage   from './SendMessage';
import Auth          from './Auth';

const prefix      = '[cmd]';
const debug       = process.env.CMD_DEBUG;
const configFile  = process.env.CMD_CONFIG;
const type        = process.env.HUBOT_IRC_TYPE;
const name        = 'cmd';
const USER        = 'user';
const MESSAGE     = 'message';
const COMMAND     = 'command';

module.exports = (robot) => {
  const sm  = new SendMessage(robot, type);
  const log = sm.robot;

  if (!configFile) {
    log.error(`${name}> no config file.`);
    return;
  }

  const conf = yaml.safeLoad(fs.readFileSync(configFile));

  const execCommand = (msg, cmd) => {
    const room    = `#${msg.message.user.room}`;
    const target  = [ room ];
    const exec    = child_process.exec;
    const message = {};
{'fraction_non_alphanumeric': 0.1415156147630487, 'fraction_numerical': 0.007425202009172308, 'mean_word_length': 2.8519764507989906, 'pattern_counts': {'":': 28, '<': 5, '<?xml version=': 0, '>': 11, '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': '2787123', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1442, 'n_words': 482}