I am setting up a discord channel to function as an SSH terminal. A NodeJS server will provide the connection. A custom command will spawn a new terminal instance, which can then be used as a shell.
I don't know how to spawn a terminal within a child process. I have tried using the screen and bash commands to no avail.
I am using CentOS 7.
// Code For Discord
var $discord = {
    currentInterface: null,
    send: (data) => {
        /* some code that sends data to a discord channel */
    },
    receive: (data) => {
        // Send Data To Terminal
        if ($discord.currentInterface) {
            $discord.currentInterface.send(data);
        } else {
            $discord.send('**Error:** Terminal has not been spawned.');
        }
    },
    command: (name, args) => {
        // Recieve Discord Commands
        switch (name) {
            case 'spawn':
                $discord.currentInterface = $interface();
            break;
        }
    }
};
// Create Interface
var $interface = function () {
    // Define object
    let x = {
        terminal: child_process.spawn('screen'),
        send: (data) => {
            // Send Input to Terminal
            x.process.stdin.write(data + '\n');
        },
        receive: (data) => {
            // Send Output to Discord
            $discord.send(data);
        }
    };
    // Process Output
    x.terminal.on('stdout', (data) => {
        x.receive(data);
    });
    // Process Errors
    x.terminal.on('stderr', (error) => {
        x.receive(`**Error:**\n${error}`);
    });
    // Return
    return x;
};
The problem lies with creating the terminal itself. How do you create an SSH-style shell within a child process?
 
    