"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
exports.runCallback = function (fn, thisArg) {
    return new Promise(function (resolve, reject) {
        fn.call(thisArg, function (error) {
            if (error) {
                reject(error);
            }
            else {
                if (arguments.length === 0) {
                    resolve();
                }
                else if (arguments.length === 1) {
                    resolve(arguments[1]);
                }
                else {
                    resolve(Array.prototype.slice.call(arguments, 1));
                }
            }
        });
    });
};
exports.promiseFromCallback = function (fn, thisArg, ...args) {
    return Promise.resolve().then(function () {
        args.unshift(undefined);
        fn = fn.bind.apply(fn, args);
        return exports.runCallback(fn, thisArg);
    });
};
function default_1(cmd, opts = { env: {} }) {
    return new Promise((resolve, reject) => {
        opts.env = Object.assign({}, { PATH: `${process.env.PATH}:/var/task/bin` }, opts.env);
        child_process_1.exec(cmd, opts, (error, stdout, stderr) => {
            if (error) {
                reject(error);
            }
            else {
                resolve({ stdout, stderr });
            }
        });
    });
}
exports.default = default_1;
exports.makeBotId = ({ channel_id, team_id, message_ts }) => {
    let chunks = [team_id, channel_id];
    if (message_ts) {
        chunks.push(message_ts);
    }
    return chunks.filter((chunk) => chunk).join('/');
};
//# sourceMappingURL=utils.js.map